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