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