]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix display of nanoseconds timestamps with -tt option (GH issue 466)
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jun 2015 18:53:27 +0000 (20:53 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 30 Jun 2015 18:53:27 +0000 (20:53 +0200)
Add 'ts_unix_format' function.

util.c

diff --git a/util.c b/util.c
index 8fcf3e0cfc97113a4498e9e67735a379c4bc8518..a5c969c0073eddabe33d1d69d0f084f2553ffe19 100644 (file)
--- a/util.c
+++ b/util.c
@@ -190,6 +190,43 @@ _U_
         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
  */
@@ -217,9 +254,8 @@ ts_print(netdissect_options *ndo,
                break;
 
        case 2: /* Unix timeval style */
-               ND_PRINT((ndo, "%u.%06u ",
-                            (unsigned)tvp->tv_sec,
-                            (unsigned)tvp->tv_usec));
+               ND_PRINT((ndo, "%s ", ts_unix_format(ndo,
+                         tvp->tv_sec, tvp->tv_usec, buf)));
                break;
 
        case 3: /* Microseconds since previous packet */