]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Print NTP timestamps as UTC, not local time
authorUlrich Windl <[email protected]>
Thu, 24 Aug 2017 07:22:57 +0000 (09:22 +0200)
committerDenis Ovsienko <[email protected]>
Tue, 29 Aug 2017 13:47:51 +0000 (14:47 +0100)
print-ntp.c: Change p_ntp_time() to print NTP timestamps in UTC instead
of local time.  This allows for consistent output for automatic testing
different time zones.  Also use an ISO 8601 (RFC3339) format for the
time stamps.

print-ntp.c

index 8edb58fc8e90056030ec73bd8ecace910bbe5f87..a0b046418ab1d4f2e39f24edec9663eeaf48d9de 100644 (file)
@@ -366,15 +366,16 @@ p_ntp_time(netdissect_options *ndo,
 
 #ifdef HAVE_STRFTIME
        /*
-        * print the time in human-readable format.
+        * print the UTC time in human-readable format.
         */
        if (i) {
            time_t seconds = i - JAN_1970;
            struct tm *tm;
            char time_buf[128];
 
-           tm = localtime(&seconds);
-           strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm);
+           tm = gmtime(&seconds);
+           /* use ISO 8601 (RFC3339) format */
+           strftime(time_buf, sizeof (time_buf), "%Y-%m-%dT%H:%M:%S", tm);
            ND_PRINT((ndo, " (%s)", time_buf));
        }
 #endif