Deleted Added
full compact
24c24
< "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.95.2.6 2006/02/08 01:40:09 hannes Exp $ (LBL)";
---
> "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.109 2007-01-29 09:59:42 hannes Exp $ (LBL)";
46a47,48
> char * ts_format(register int, register int);
>
141a144,156
> * Format the timestamp
> */
> char *
> ts_format(register int sec, register int usec)
> {
> static char buf[sizeof("00:00:00.000000")];
> (void)snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u",
> sec / 3600, (sec % 3600) / 60, sec % 60, usec);
>
> return buf;
> }
>
> /*
151a167,168
> int d_usec;
> int d_sec;
157,159c174
< (void)printf("%02d:%02d:%02d.%06u ",
< s / 3600, (s % 3600) / 60, s % 60,
< (unsigned)tvp->tv_usec);
---
> (void)printf("%s ", ts_format(s, tvp->tv_usec));
171a187
> case 5: /* Microseconds since first packet */
173,176c189,192
< printf("000000 ");
< } else {
< int d_usec = tvp->tv_usec - b_usec;
< int d_sec = tvp->tv_sec - b_sec;
---
> /* init timestamp for first packet */
> b_usec = tvp->tv_usec;
> b_sec = tvp->tv_sec;
> }
178,187c194,207
< while (d_usec < 0) {
< d_usec += 1000000;
< d_sec--;
< }
< if (d_sec)
< printf("%d. ", d_sec);
< printf("%06d ", d_usec);
< }
< b_sec = tvp->tv_sec;
< b_usec = tvp->tv_usec;
---
> d_usec = tvp->tv_usec - b_usec;
> d_sec = tvp->tv_sec - b_sec;
>
> while (d_usec < 0) {
> d_usec += 1000000;
> d_sec--;
> }
>
> (void)printf("%s ", ts_format(d_sec, d_usec));
>
> if (tflag == 3) { /* set timestamp for last packet */
> b_sec = tvp->tv_sec;
> b_usec = tvp->tv_usec;
> }
197,200c217,219
< printf("%04d-%02d-%02d ",
< tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
< printf("%02d:%02d:%02d.%06u ",
< s / 3600, (s % 3600) / 60, s % 60, (unsigned)tvp->tv_usec);
---
> printf("%04d-%02d-%02d %s ",
> tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
> ts_format(s, tvp->tv_usec));
300c319,320
< * this is useful for parsing bitfields, the output strings are comma seperated
---
> * this is useful for parsing bitfields, the output strings are seperated
> * if the s field is positive.
302,304c322,324
< char *
< bittok2str(register const struct tok *lp, register const char *fmt,
< register int v)
---
> static char *
> bittok2str_internal(register const struct tok *lp, register const char *fmt,
> register int v, register int sep)
321c341,342
< buflen+=snprintf(buf+buflen, sizeof(buf)-buflen, "%s, ",lp->s);
---
> buflen+=snprintf(buf+buflen, sizeof(buf)-buflen, "%s%s",
> lp->s, sep ? ", " : "");
328a350,354
> /* user didn't want string seperation - no need to cut off trailing seperators */
> if (!sep) {
> return (buf);
> }
>
343a370,391
> * Convert a bit token value to a string; use "fmt" if not found.
> * this is useful for parsing bitfields, the output strings are not seperated.
> */
> char *
> bittok2str_nosep(register const struct tok *lp, register const char *fmt,
> register int v)
> {
> return (bittok2str_internal(lp, fmt, v, 0));
> }
>
> /*
> * Convert a bit token value to a string; use "fmt" if not found.
> * this is useful for parsing bitfields, the output strings are comma seperated.
> */
> char *
> bittok2str(register const struct tok *lp, register const char *fmt,
> register int v)
> {
> return (bittok2str_internal(lp, fmt, v, 1));
> }
>
> /*
512c560,561
< int idx = 0;
---
> int idx = 0;
>
529c578
< printf("\\%03o", ch);
---
> printf("\\0x%02x", ch);