Skip to content

Commit a9f3e09

Browse files
committed
Raw IPv4/IPv6: Add ipv4_if_print() and ipv6_if_print() printers
With this change tcpdump prints errors when an IPv6 packet is in a LINKTYPE_IPV4 file and when an IPv4 packet is in a LINKTYPE_IPV6 file. Update the printer summary. And some test files printed with or without '-e'. Update the linktype of hoobr_rt6_print.pcap from "Raw IPv4" to "Raw IPv6" to keep test validity for packet #3. Update 2 test outputs.
1 parent 8faff40 commit a9f3e09

13 files changed

+46
-7
lines changed

netdissect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ extern void ieee802_15_4_tap_if_print IF_PRINTER_ARGS;
561561
extern void ipfc_if_print IF_PRINTER_ARGS;
562562
extern void ipnet_if_print IF_PRINTER_ARGS;
563563
extern void ipoib_if_print IF_PRINTER_ARGS;
564+
extern void ipv4_if_print IF_PRINTER_ARGS;
565+
extern void ipv6_if_print IF_PRINTER_ARGS;
564566
extern void juniper_atm1_if_print IF_PRINTER_ARGS;
565567
extern void juniper_atm2_if_print IF_PRINTER_ARGS;
566568
extern void juniper_chdlc_if_print IF_PRINTER_ARGS;

print-raw.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2020
*/
2121

22-
/* \summary: Raw IP printer */
22+
/* \summary: Raw IPv4/IPv6 printer and similar */
2323

2424
#include <config.h>
2525

@@ -63,3 +63,33 @@ raw_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
6363
break;
6464
}
6565
}
66+
67+
/*
68+
* The DLT_IPV4 packet has no header. It contains a raw IPv4 packet.
69+
*/
70+
71+
void
72+
ipv4_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
73+
{
74+
ndo->ndo_protocol = "ip";
75+
ndo->ndo_ll_hdr_len += 0;
76+
77+
if (ndo->ndo_eflag)
78+
ND_PRINT("IP ");
79+
ip_print(ndo, p, h->len);
80+
}
81+
82+
/*
83+
* The DLT_IPV6 packet has no header. It contains a raw IPv6 packet.
84+
*/
85+
86+
void
87+
ipv6_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
88+
{
89+
ndo->ndo_protocol = "ip6";
90+
ndo->ndo_ll_hdr_len += 0;
91+
92+
if (ndo->ndo_eflag)
93+
ND_PRINT("IP6 ");
94+
ip6_print(ndo, p, h->len);
95+
}

print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ static const struct printer printers[] = {
205205
#endif
206206
{ raw_if_print, DLT_RAW },
207207
#ifdef DLT_IPV4
208-
{ raw_if_print, DLT_IPV4 },
208+
{ ipv4_if_print, DLT_IPV4 },
209209
#endif
210210
#ifdef DLT_IPV6
211-
{ raw_if_print, DLT_IPV6 },
211+
{ ipv6_if_print, DLT_IPV6 },
212212
#endif
213213
#ifdef DLT_SLIP_BSDOS
214214
{ sl_bsdos_if_print, DLT_SLIP_BSDOS },

tests/LINKTYPE_IPV4_invalid-e.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2025-07-09 06:00:34.349949 IP [version 6 != 4] (invalid)

tests/LINKTYPE_IPV4_invalid.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2025-07-09 06:00:34.349949 IP [version 6 != 4] (invalid)

tests/LINKTYPE_IPV4_invalid.pcap

117 Bytes
Binary file not shown.

tests/LINKTYPE_IPV6_invalid-e.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2025-07-09 05:59:39.284233 IP6 [version 4 != 6] (invalid)

tests/LINKTYPE_IPV6_invalid.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2025-07-09 05:59:39.284233 IP6 [version 4 != 6] (invalid)

tests/LINKTYPE_IPV6_invalid.pcap

97 Bytes
Binary file not shown.

tests/TESTLIST

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,4 +1039,7 @@ LINKTYPE_IPV4 LINKTYPE_IPV4.pcap LINKTYPE_IPV4.out
10391039
LINKTYPE_IPV4-e LINKTYPE_IPV4.pcap LINKTYPE_IPV4-e.out -e
10401040
LINKTYPE_IPV6 LINKTYPE_IPV6.pcap LINKTYPE_IPV6.out
10411041
LINKTYPE_IPV6-e LINKTYPE_IPV6.pcap LINKTYPE_IPV6-e.out -e
1042-
1042+
LINKTYPE_IPV4_invalid LINKTYPE_IPV4_invalid.pcap LINKTYPE_IPV4_invalid.out
1043+
LINKTYPE_IPV4_invalid-e LINKTYPE_IPV4_invalid.pcap LINKTYPE_IPV4_invalid-e.out -e
1044+
LINKTYPE_IPV6_invalid LINKTYPE_IPV6_invalid.pcap LINKTYPE_IPV6_invalid.out
1045+
LINKTYPE_IPV6_invalid-e LINKTYPE_IPV6_invalid.pcap LINKTYPE_IPV6_invalid-e.out -e

0 commit comments

Comments
 (0)