]> The Tcpdump Group git mirrors - tcpdump/commitdiff
IP: Print the protocol name before any test
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 3 Sep 2023 19:48:46 +0000 (21:48 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 5 Sep 2023 17:43:52 +0000 (19:43 +0200)
Use nd_print_protocol_caps().

Use ND_ICHECKMSG_U() to print an invalid version, as for IPv6.

Update some test outputs accordingly.

print-ip.c
tests/bad-ipv4-version-pgm-heapoverflow.out
tests/gre-heapoverflow-1.out
tests/kday1.out
tests/kday3.out

index f90c58a041a8b1987724987d4134ec11141841e6..37c30e5e5fa0f45c91d04ddfacd7ea66b1f68c5a 100644 (file)
@@ -332,16 +332,13 @@ ip_print(netdissect_options *ndo,
 
        ndo->ndo_protocol = "ip";
        ip = (const struct ip *)bp;
-       if (IP_V(ip) != 4) { /* print version and fail if != 4 */
-           if (IP_V(ip) == 6)
-             ND_PRINT("IP6, wrong link-layer encapsulation");
-           else
-             ND_PRINT("IP%u", IP_V(ip));
-           nd_print_invalid(ndo);
-           return;
+
+       if (!ndo->ndo_eflag) {
+               nd_print_protocol_caps(ndo);
+               ND_PRINT(" ");
        }
-       if (!ndo->ndo_eflag)
-               ND_PRINT("IP ");
+
+       ND_ICHECKMSG_U("version", IP_V(ip), !=, 4);
 
        ND_TCHECK_SIZE(ip);
        if (length < sizeof (struct ip)) {
@@ -512,6 +509,10 @@ ip_print(netdissect_options *ndo,
 
 trunc:
        nd_print_trunc(ndo);
+       return;
+
+invalid:
+       nd_print_invalid(ndo);
 }
 
 void
index 1380374ddf38f80991ca6db79a512ca9cdb6e3bd..8736981620e9959c3228a6878ccb48ecc5587f49 100644 (file)
@@ -1 +1 @@
-    1  05:27:12.808464432 IP6, wrong link-layer encapsulation (invalid)
+    1  05:27:12.808464432 IP  [version 6 != 4] (invalid)
index e3fd43f190499a4c39da80b887c48ef063a2cad7..9c1078b7b42842eb5de0c2b178f5f92731b9cd1e 100644 (file)
@@ -5,4 +5,4 @@
        0x0030:  3030 3030 3030 3030 3030 3030 3030 3030  0000000000000000
        0x0040:  3030 3030 3030 3030 3030 3030 3030 3030  0000000000000000
        0x0050:  3030 3030                                0000
-    2  05:27:12.808464432 IP0 (invalid)
+    2  05:27:12.808464432 IP  [version 0 != 4] (invalid)
index bb72c695c21b20fb1493f5bb85ed0ba010ca6e2f..9b7ad6115b79f8b5a898d0d38b31a2f219f5d9b4 100644 (file)
@@ -1 +1 @@
-    1  10:23:33.663606 IP6, wrong link-layer encapsulation (invalid)
+    1  10:23:33.663606 IP  [version 6 != 4] (invalid)
index 560847f3ee5ca994fd17c79e72a90dd1ace05d2a..ae4d8179bafb6be92bb9c3b77f6a6b387e14dca0 100644 (file)
@@ -1,6 +1,6 @@
     1  02:25:41.663606 IP (tos 0x10, ttl 64, id 63177, offset 0, flags [DF], proto TCP (6), length 168)
     204.9.54.80.22 > 204.9.51.132.50079: Flags [P.], cksum 0x0282 (incorrect -> 0x3217), seq 1819218606:1819218722, ack 1238485076, win 1039, options [nop,nop,TS val 1340592078 ecr 941371882], length 116
-    2  17:19:33.672232 IP6, wrong link-layer encapsulation (invalid)
+    2  17:19:33.672232 IP  [version 6 != 4] (invalid)
     3  17:19:33.684826 IP (tos 0x10, ttl 62, id 62920, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 4504 (->451a)!)
     204.9.51.132.50079 > 204.243.53.80.22: Flags [.], cksum 0x858b (incorrect -> 0x85a1), ack 1819218722, win 4092, options [nop,nop,TS val 941371913 ecr 1340592084], length 0
     4  17:19:33.703499 IP (tos 0x0, ttl 64, id 63178, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 3e8c (->438c)!)