mirror of
https://github.com/the-tcpdump-group/tcpdump.git
synced 2024-11-23 18:14:29 +08:00
Fix display of nanoseconds timestamps with -tt option (GH issue 466)
Add 'ts_unix_format' function.
This commit is contained in:
parent
6632565511
commit
22d4afb88a
44
util-print.c
44
util-print.c
@ -59,7 +59,7 @@ int32_t thiszone; /* seconds offset from gmt to local time */
|
|||||||
/*
|
/*
|
||||||
* timestamp display buffer size, the biggest size of both formats is needed
|
* timestamp display buffer size, the biggest size of both formats is needed
|
||||||
* sizeof("0000000000.000000000") > sizeof("00:00:00.000000000")
|
* sizeof("0000000000.000000000") > sizeof("00:00:00.000000000")
|
||||||
*/
|
*/
|
||||||
#define TS_BUF_SIZE sizeof("0000000000.000000000")
|
#define TS_BUF_SIZE sizeof("0000000000.000000000")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -192,6 +192,43 @@ _U_
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Format the timestamp - Unix timeval style
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
ts_unix_format(netdissect_options *ndo
|
||||||
|
#ifndef HAVE_PCAP_SET_TSTAMP_PRECISION
|
||||||
|
_U_
|
||||||
|
#endif
|
||||||
|
, int sec, int usec, char *buf)
|
||||||
|
{
|
||||||
|
const char *format;
|
||||||
|
|
||||||
|
#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
|
||||||
|
switch (ndo->ndo_tstamp_precision) {
|
||||||
|
|
||||||
|
case PCAP_TSTAMP_PRECISION_MICRO:
|
||||||
|
format = "%u.%06u";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PCAP_TSTAMP_PRECISION_NANO:
|
||||||
|
format = "%u.%09u";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
format = "%u.{unknown}";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
format = "%u.%06u";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
snprintf(buf, TS_BUF_SIZE, format,
|
||||||
|
(unsigned)sec, (unsigned)usec);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print the timestamp
|
* Print the timestamp
|
||||||
*/
|
*/
|
||||||
@ -219,9 +256,8 @@ ts_print(netdissect_options *ndo,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: /* Unix timeval style */
|
case 2: /* Unix timeval style */
|
||||||
ND_PRINT((ndo, "%u.%06u ",
|
ND_PRINT((ndo, "%s ", ts_unix_format(ndo,
|
||||||
(unsigned)tvp->tv_sec,
|
tvp->tv_sec, tvp->tv_usec, buf)));
|
||||||
(unsigned)tvp->tv_usec));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: /* Microseconds since previous packet */
|
case 3: /* Microseconds since previous packet */
|
||||||
|
Loading…
Reference in New Issue
Block a user