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