]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Report invalid microseconds as "us", not "ms".
authorDenis Ovsienko <[email protected]>
Mon, 20 Jan 2025 13:59:44 +0000 (13:59 +0000)
committerDenis Ovsienko <[email protected]>
Mon, 20 Jan 2025 14:15:04 +0000 (14:15 +0000)
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.

print-arista.c
tests/timestamp_invalid_micro.out
timeval-operations.h
util-print.c

index 1f6b0263deddb2467357d78054e02538bc87849a..0ec04889b6a212a5c34af18daace66c935a8d047 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "netdissect.h"
 #include "extract.h"
 
 #include "netdissect.h"
 #include "extract.h"
+#include "timeval-operations.h"
 
 /*
 
 
 /*
 
@@ -85,9 +86,6 @@ static const struct tok hw_info_str[] = {
        { 0, NULL }
 };
 
        { 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)
 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);
        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
 }
 
 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);
                        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:
                        bytesConsumed += 6;
                        break;
                default:
index d980854bf832dedd63d6529aea4fca77f2e3382d..0ff89636375c4dbc3b21603a36f3d134a45a2c61 100644 (file)
@@ -1,3 +1,3 @@
     1  17:16:09.999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
     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
index 177027db031d91267e0c7866c69c862f2956008e..65a9b144e07c573406398ab335f90901eb2c7104 100644 (file)
@@ -32,6 +32,8 @@
 
 #define ND_MICRO_PER_SEC 1000000
 #define ND_NANO_PER_SEC 1000000000
 
 #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)
 
 
 #define netdissect_timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
 
index b67e8a1879ac9cffd730d915977a6daf3c159ef4..4a064eb0b9be788b4fd5b5b11ed95a4199b07b0d 100644 (file)
@@ -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)
        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)
                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:
                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)
 #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
 }
 
 #endif
 }