]> 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 19:39:44 +0000 (19:39 +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.

(cherry picked from commit f08d60d42d60adce6e5b374882fc2035972730f4)

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 74ac7f1b268255e7b51e761772978af29f75f3c1..3674df04b45653dc070b538e397b27325c8f4d98 100644 (file)
@@ -19,6 +19,10 @@ print-XX     print-flags.pcap        print-capXX.out -XX
 print-A                print-flags.pcap        print-A.out     -A
 print-AA       print-flags.pcap        print-AA.out    -AA
 
+# 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 4871655aa065f7a76e74b23ccab805e07601ccf7..cc6afefad09f50eeee33ca776f5b3c9661c2dadf 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
 }