From: Francois-Xavier Le Bail Date: Sun, 3 Sep 2023 19:48:46 +0000 (+0200) Subject: IP: Print the protocol name before any test X-Git-Tag: tcpdump-4.99.5~150 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/269ee0e6f269679036e38b37d974dc0a1db59713?ds=sidebyside IP: Print the protocol name before any test Use nd_print_protocol_caps(). Use ND_ICHECKMSG_U() to print an invalid version, as for IPv6. Update some test outputs accordingly. (cherry picked from commit 8fc1c61427a2715a10342dd28cf75175c53691c8) --- diff --git a/print-ip.c b/print-ip.c index f90c58a0..37c30e5e 100644 --- a/print-ip.c +++ b/print-ip.c @@ -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 diff --git a/tests/bad-ipv4-version-pgm-heapoverflow.out b/tests/bad-ipv4-version-pgm-heapoverflow.out index 1380374d..87369816 100644 --- a/tests/bad-ipv4-version-pgm-heapoverflow.out +++ b/tests/bad-ipv4-version-pgm-heapoverflow.out @@ -1 +1 @@ - 1 05:27:12.808464432 IP6, wrong link-layer encapsulation (invalid) + 1 05:27:12.808464432 IP [version 6 != 4] (invalid) diff --git a/tests/gre-heapoverflow-1.out b/tests/gre-heapoverflow-1.out index e3fd43f1..9c1078b7 100644 --- a/tests/gre-heapoverflow-1.out +++ b/tests/gre-heapoverflow-1.out @@ -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) diff --git a/tests/kday1.out b/tests/kday1.out index bb72c695..9b7ad611 100644 --- a/tests/kday1.out +++ b/tests/kday1.out @@ -1 +1 @@ - 1 10:23:33.663606 IP6, wrong link-layer encapsulation (invalid) + 1 10:23:33.663606 IP [version 6 != 4] (invalid) diff --git a/tests/kday3.out b/tests/kday3.out index 560847f3..ae4d8179 100644 --- a/tests/kday3.out +++ b/tests/kday3.out @@ -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)!)