aboutsummaryrefslogtreecommitdiff
path: root/ntp.c
diff options
context:
space:
mode:
authorSadaf Ebrahimi <sadafebrahimi@google.com>2023-07-12 22:07:12 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-07-12 22:07:12 +0000
commitd231da0df56a84f7dce9f76e18de90ebc6361984 (patch)
tree459101553d2b7814467ff205890774b31912033c /ntp.c
parentbc66278394fe60f4893d1b443a0a26ba08f0880a (diff)
parent0c7d779c63e6406f59508542fc92c6b48595a25c (diff)
downloadtcpdump-d231da0df56a84f7dce9f76e18de90ebc6361984.tar.gz
Merge "Upgrade tcpdump to tcpdump-4.99.4" into main
Diffstat (limited to 'ntp.c')
-rw-r--r--ntp.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/ntp.c b/ntp.c
index 4d17932f..ec8f659a 100644
--- a/ntp.c
+++ b/ntp.c
@@ -48,15 +48,14 @@ p_ntp_time(netdissect_options *ndo,
f = (uint32_t)(ff * 1000000000.0); /* treat fraction as parts per billion */
ND_PRINT("%u.%09u", i, f);
-#ifdef HAVE_STRFTIME
/*
* print the UTC time in human-readable format.
*/
if (i) {
int64_t seconds_64bit = (int64_t)i - JAN_1970;
time_t seconds;
- struct tm *tm;
char time_buf[128];
+ const char *time_string;
seconds = (time_t)seconds_64bit;
if (seconds != seconds_64bit) {
@@ -64,22 +63,12 @@ p_ntp_time(netdissect_options *ndo,
* It doesn't fit into a time_t, so we can't hand it
* to gmtime.
*/
- ND_PRINT(" (unrepresentable)");
+ time_string = "[Time is too large to fit into a time_t]";
} else {
- tm = gmtime(&seconds);
- if (tm == NULL) {
- /*
- * gmtime() can't handle it.
- * (Yes, that might happen with some version of
- * Microsoft's C library.)
- */
- ND_PRINT(" (unrepresentable)");
- } else {
- /* use ISO 8601 (RFC3339) format */
- strftime(time_buf, sizeof (time_buf), "%Y-%m-%dT%H:%M:%SZ", tm);
- ND_PRINT(" (%s)", time_buf);
- }
+ /* use ISO 8601 (RFC3339) format */
+ time_string = nd_format_time(time_buf, sizeof (time_buf),
+ "%Y-%m-%dT%H:%M:%SZ", gmtime(&seconds));
}
+ ND_PRINT(" (%s)", time_string);
}
-#endif
}