]> The Tcpdump Group git mirrors - tcpdump/blob - print-ipnet.c
Use the new GET_ macros instead of the EXTRACT_ ones
[tcpdump] / print-ipnet.c
1 /* \summary: Solaris DLT_IPNET printer */
2
3 #ifdef HAVE_CONFIG_H
4 #include <config.h>
5 #endif
6
7 #include "netdissect-stdinc.h"
8
9 #include "netdissect.h"
10 #include "extract.h"
11
12
13 typedef struct ipnet_hdr {
14 nd_uint8_t iph_version;
15 nd_uint8_t iph_family;
16 nd_uint16_t iph_htype;
17 nd_uint32_t iph_pktlen;
18 nd_uint32_t iph_ifindex;
19 nd_uint32_t iph_grifindex;
20 nd_uint32_t iph_zsrc;
21 nd_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 void
36 ipnet_hdr_print(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_TCHECK_SIZE(hdr);
42 ND_PRINT("%u > %u", GET_BE_U_4(hdr->iph_zsrc),
43 GET_BE_U_4(hdr->iph_zdst));
44
45 if (!ndo->ndo_qflag) {
46 ND_PRINT(", family %s (%u)",
47 tok2str(ipnet_values, "Unknown",
48 GET_U_1(hdr->iph_family)),
49 GET_U_1(hdr->iph_family));
50 } else {
51 ND_PRINT(", %s",
52 tok2str(ipnet_values,
53 "Unknown Ethertype (0x%04x)",
54 GET_U_1(hdr->iph_family)));
55 }
56
57 ND_PRINT(", length %u: ", length);
58 return;
59 trunc:
60 nd_print_trunc(ndo);
61 }
62
63 static void
64 ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
65 {
66 const ipnet_hdr_t *hdr;
67
68 ndo->ndo_protocol = "ipnet";
69 if (caplen < sizeof(ipnet_hdr_t))
70 goto trunc;
71
72 if (ndo->ndo_eflag)
73 ipnet_hdr_print(ndo, p, length);
74
75 length -= sizeof(ipnet_hdr_t);
76 caplen -= sizeof(ipnet_hdr_t);
77 hdr = (const ipnet_hdr_t *)p;
78 p += sizeof(ipnet_hdr_t);
79
80 ND_TCHECK_1(hdr->iph_family);
81 switch (GET_U_1(hdr->iph_family)) {
82
83 case IPH_AF_INET:
84 ip_print(ndo, p, length);
85 break;
86
87 case IPH_AF_INET6:
88 ip6_print(ndo, p, length);
89 break;
90
91 default:
92 if (!ndo->ndo_eflag)
93 ipnet_hdr_print(ndo, (const u_char *)hdr,
94 length + sizeof(ipnet_hdr_t));
95
96 if (!ndo->ndo_suppress_default_print)
97 ND_DEFAULTPRINT(p, caplen);
98 break;
99 }
100 return;
101 trunc:
102 nd_print_trunc(ndo);
103 }
104
105 /*
106 * This is the top level routine of the printer. 'p' points
107 * to the ether header of the packet, 'h->ts' is the timestamp,
108 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
109 * is the number of bytes actually captured.
110 */
111 u_int
112 ipnet_if_print(netdissect_options *ndo,
113 const struct pcap_pkthdr *h, const u_char *p)
114 {
115 ndo->ndo_protocol = "ipnet_if";
116 ipnet_print(ndo, p, h->len, h->caplen);
117
118 return (sizeof(ipnet_hdr_t));
119 }
120 #endif /* DLT_IPNET */