]> The Tcpdump Group git mirrors - tcpdump/blob - print-ipnet.c
Fix a bunch of de-constifications.
[tcpdump] / print-ipnet.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <tcpdump-stdinc.h>
6
7 #include "interface.h"
8
9 typedef struct ipnet_hdr {
10 uint8_t iph_version;
11 uint8_t iph_family;
12 uint16_t iph_htype;
13 uint32_t iph_pktlen;
14 uint32_t iph_ifindex;
15 uint32_t iph_grifindex;
16 uint32_t iph_zsrc;
17 uint32_t iph_zdst;
18 } ipnet_hdr_t;
19
20 #define IPH_AF_INET 2 /* Matches Solaris's AF_INET */
21 #define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */
22
23 #ifdef DLT_IPNET
24
25 static const struct tok ipnet_values[] = {
26 { IPH_AF_INET, "IPv4" },
27 { IPH_AF_INET6, "IPv6" },
28 { 0, NULL }
29 };
30
31 static inline void
32 ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
33 {
34 const ipnet_hdr_t *hdr;
35 hdr = (const ipnet_hdr_t *)bp;
36
37 ND_PRINT((ndo, "%d > %d", hdr->iph_zsrc, hdr->iph_zdst));
38
39 if (!ndo->ndo_qflag) {
40 ND_PRINT((ndo,", family %s (%d)",
41 tok2str(ipnet_values, "Unknown",
42 hdr->iph_family),
43 hdr->iph_family));
44 } else {
45 ND_PRINT((ndo,", %s",
46 tok2str(ipnet_values,
47 "Unknown Ethertype (0x%04x)",
48 hdr->iph_family)));
49 }
50
51 ND_PRINT((ndo, ", length %u: ", length));
52 }
53
54 static void
55 ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
56 {
57 const ipnet_hdr_t *hdr;
58
59 if (caplen < sizeof(ipnet_hdr_t)) {
60 ND_PRINT((ndo, "[|ipnet]"));
61 return;
62 }
63
64 if (ndo->ndo_eflag)
65 ipnet_hdr_print(ndo, p, length);
66
67 length -= sizeof(ipnet_hdr_t);
68 caplen -= sizeof(ipnet_hdr_t);
69 hdr = (const ipnet_hdr_t *)p;
70 p += sizeof(ipnet_hdr_t);
71
72 switch (hdr->iph_family) {
73
74 case IPH_AF_INET:
75 ip_print(ndo, p, length);
76 break;
77
78 case IPH_AF_INET6:
79 ip6_print(ndo, p, length);
80 break;
81
82 default:
83 if (!ndo->ndo_eflag)
84 ipnet_hdr_print(ndo, (const u_char *)hdr,
85 length + sizeof(ipnet_hdr_t));
86
87 if (!ndo->ndo_suppress_default_print)
88 ND_DEFAULTPRINT(p, caplen);
89 break;
90 }
91 }
92
93 /*
94 * This is the top level routine of the printer. 'p' points
95 * to the ether header of the packet, 'h->ts' is the timestamp,
96 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
97 * is the number of bytes actually captured.
98 */
99 u_int
100 ipnet_if_print(netdissect_options *ndo,
101 const struct pcap_pkthdr *h, const u_char *p)
102 {
103 ipnet_print(ndo, p, h->len, h->caplen);
104
105 return (sizeof(ipnet_hdr_t));
106 }
107
108 /*
109 * Local Variables:
110 * c-style: whitesmith
111 * c-basic-offset: 8
112 * End:
113 */
114
115 #endif /* DLT_IPNET */