]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add sub-second packet timestamp checks for invalid micro/nano
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 22 Dec 2024 14:12:56 +0000 (15:12 +0100)
committerfxlb <[email protected]>
Mon, 23 Dec 2024 09:11:18 +0000 (09:11 +0000)
Now prints e.g.:
    2  17:16:10.1000000 (invalid ms) IP [...]
    3  17:16:10.2147483648 (invalid ms) IP [...]
or
    2  17:16:10.1000000000 (invalid ns) IP [...]
    3  17:16:10.2147483648 (invalid ns) IP [...]

Add two test files.

tests/TESTLIST
tests/timestamp_invalid_micro.out [new file with mode: 0644]
tests/timestamp_invalid_micro.pcap [new file with mode: 0644]
tests/timestamp_invalid_nano.out [new file with mode: 0644]
tests/timestamp_invalid_nano.pcap [new file with mode: 0644]
util-print.c

index a6ffc3b0f341b2a07abfc689a66fa8f749af4393..ae9929b30b1a6b0bd6833343edcb212745753eab 100644 (file)
@@ -38,6 +38,10 @@ tcp-handshake-nano-ttt tcp-handshake-nano.pcap tcp-handshake-nano-ttt.out -ttt -
 tcp-handshake-nano-tttt tcp-handshake-nano.pcap tcp-handshake-nano-tttt.out -tttt -q --nano SPECIAL_t
 tcp-handshake-nano-ttttt tcp-handshake-nano.pcap tcp-handshake-nano-ttttt.out -ttttt -q --nano SPECIAL_t
 
+# Invalid timestamps, micro and nano precision
+timestamp_invalid_micro timestamp_invalid_micro.pcap timestamp_invalid_micro.out -q SPECIAL_t
+timestamp_invalid_nano timestamp_invalid_nano.pcap timestamp_invalid_nano.out -q --nano SPECIAL_t
+
 # TCP with data in the RST segment
 tcp_rst_data tcp_rst_data.pcap tcp_rst_data-v.out -v
 tcp_rst_data tcp_rst_data.pcap tcp_rst_data.out
diff --git a/tests/timestamp_invalid_micro.out b/tests/timestamp_invalid_micro.out
new file mode 100644 (file)
index 0000000..d980854
--- /dev/null
@@ -0,0 +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
diff --git a/tests/timestamp_invalid_micro.pcap b/tests/timestamp_invalid_micro.pcap
new file mode 100644 (file)
index 0000000..4285935
Binary files /dev/null and b/tests/timestamp_invalid_micro.pcap differ
diff --git a/tests/timestamp_invalid_nano.out b/tests/timestamp_invalid_nano.out
new file mode 100644 (file)
index 0000000..be49a38
--- /dev/null
@@ -0,0 +1,3 @@
+    1  17:16:09.999999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
+    2  17:16:10.1000000000 (invalid ns) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
+    3  17:16:10.2147483648 (invalid ns) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
diff --git a/tests/timestamp_invalid_nano.pcap b/tests/timestamp_invalid_nano.pcap
new file mode 100644 (file)
index 0000000..da45ad4
Binary files /dev/null and b/tests/timestamp_invalid_nano.pcap differ
index 47823aec2a65461605a831ea21b457529e754fab..b67e8a1879ac9cffd730d915977a6daf3c159ef4 100644 (file)
@@ -216,10 +216,14 @@ 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)");
                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)");
                break;
 
        default:
@@ -228,6 +232,8 @@ 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)");
 #endif
 }