X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a6df5512cfdf7d7221d63d40d7329eaae6b93481..ddb7009f906c69c5f7bddbd21c735a117f9a1e49:/util.c diff --git a/util.c b/util.c index 13d29974..cb4f2aaa 100644 --- a/util.c +++ b/util.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.103 2005-12-13 08:37:23 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.106 2006-02-08 01:38:16 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -164,6 +164,8 @@ ts_print(register const struct timeval *tvp) time_t Time; static unsigned b_sec; static unsigned b_usec; + int d_usec; + int d_sec; switch (tflag) { @@ -183,14 +185,14 @@ ts_print(register const struct timeval *tvp) case 3: /* Microseconds since previous packet */ case 5: /* Microseconds since first packet */ - if (b_sec == 0 && tflag == 5) { + if (b_sec == 0) { /* init timestamp for first packet */ b_usec = tvp->tv_usec; b_sec = tvp->tv_sec; } - int d_usec = tvp->tv_usec - b_usec; - int d_sec = tvp->tv_sec - b_sec; + d_usec = tvp->tv_usec - b_usec; + d_sec = tvp->tv_sec - b_sec; while (d_usec < 0) { d_usec += 1000000; @@ -524,10 +526,12 @@ read_infile(char *fname) } void -safeputs(const char *s) +safeputs(const char *s, int maxlen) { - while (*s) { + int idx = 0; + while (*s && idx < maxlen) { safeputchar(*s); + idx++; s++; } } @@ -541,5 +545,5 @@ safeputchar(int c) if (ch < 0x80 && isprint(ch)) printf("%c", ch); else - printf("\\%03o", ch); + printf("\\0x%02x ", ch); }