From: Denis Ovsienko Date: Mon, 20 Jan 2025 13:59:44 +0000 (+0000) Subject: Report invalid microseconds as "us", not "ms". X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/09512cfc01958a37f67951bf7b6e00d52ed1e12e Report invalid microseconds as "us", not "ms". In timeval-operations.h for microseconds and nanoseconds define both the maximum number of units per second and the string to use for reporting an invalid value. Use the new macros in ts_frac_print() and update a test. For consistency in print-arista.c instead of MAX_VALID_NS and BOGUS_NS_STR use the macros from timeval-operations.h. --- diff --git a/print-arista.c b/print-arista.c index 1f6b0263..0ec04889 100644 --- a/print-arista.c +++ b/print-arista.c @@ -8,6 +8,7 @@ #include "netdissect.h" #include "extract.h" +#include "timeval-operations.h" /* @@ -85,9 +86,6 @@ static const struct tok hw_info_str[] = { { 0, NULL } }; -#define MAX_VALID_NS 999999999U -#define BOGUS_NS_STR "(bogus ns!)" - static inline void arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds, const uint32_t nanoseconds) @@ -98,8 +96,8 @@ arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds, ND_PRINT("%s.%09u", nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", gmtime(&ts)), nanoseconds); - if (nanoseconds > MAX_VALID_NS) - ND_PRINT(" " BOGUS_NS_STR); + if (nanoseconds > ND_NANO_PER_SEC - 1) + ND_PRINT(" " ND_INVALID_NANO_SEC_STR); } int @@ -151,8 +149,8 @@ arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_) seconds = GET_BE_U_2(bp); nanoseconds = GET_BE_U_4(bp + 2); ND_PRINT("%u.%09u", seconds, nanoseconds); - if (nanoseconds > MAX_VALID_NS) - ND_PRINT(" " BOGUS_NS_STR); + if (nanoseconds > ND_NANO_PER_SEC - 1) + ND_PRINT(" " ND_INVALID_NANO_SEC_STR); bytesConsumed += 6; break; default: diff --git a/tests/timestamp_invalid_micro.out b/tests/timestamp_invalid_micro.out index d980854b..0ff89636 100644 --- a/tests/timestamp_invalid_micro.out +++ b/tests/timestamp_invalid_micro.out @@ -1,3 +1,3 @@ 1 17:16:09.999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0 - 2 17:16:10.1000000 (invalid ms) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0 - 3 17:16:10.2147483648 (invalid ms) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0 + 2 17:16:10.1000000 (invalid us) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0 + 3 17:16:10.2147483648 (invalid us) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0 diff --git a/timeval-operations.h b/timeval-operations.h index 177027db..65a9b144 100644 --- a/timeval-operations.h +++ b/timeval-operations.h @@ -32,6 +32,8 @@ #define ND_MICRO_PER_SEC 1000000 #define ND_NANO_PER_SEC 1000000000 +#define ND_INVALID_MICRO_SEC_STR "(invalid us)" +#define ND_INVALID_NANO_SEC_STR "(invalid ns)" #define netdissect_timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) diff --git a/util-print.c b/util-print.c index b67e8a18..4a064eb0 100644 --- a/util-print.c +++ b/util-print.c @@ -217,13 +217,13 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv) case PCAP_TSTAMP_PRECISION_MICRO: ND_PRINT(".%06u", (unsigned)tv->tv_usec); if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1) - ND_PRINT(" (invalid ms)"); + ND_PRINT(" " ND_INVALID_MICRO_SEC_STR); break; case PCAP_TSTAMP_PRECISION_NANO: ND_PRINT(".%09u", (unsigned)tv->tv_usec); if ((unsigned)tv->tv_usec > ND_NANO_PER_SEC - 1) - ND_PRINT(" (invalid ns)"); + ND_PRINT(" " ND_INVALID_NANO_SEC_STR); break; default: @@ -233,7 +233,7 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv) #else ND_PRINT(".%06u", (unsigned)tv->tv_usec); if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1) - ND_PRINT(" (invalid ms)"); + ND_PRINT(" " ND_INVALID_MICRO_SEC_STR); #endif }