start shipping ctfconvert & ctfmerge in /usr/bin
[unleashed.git] / contrib / tcpdump / print-ipnet.c
blobf71c145550b0463dd5df2cea7e7551219417298a
1 /* \summary: Solaris DLT_IPNET printer */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <netdissect-stdinc.h>
9 #include "netdissect.h"
11 typedef struct ipnet_hdr {
12 uint8_t iph_version;
13 uint8_t iph_family;
14 uint16_t iph_htype;
15 uint32_t iph_pktlen;
16 uint32_t iph_ifindex;
17 uint32_t iph_grifindex;
18 uint32_t iph_zsrc;
19 uint32_t iph_zdst;
20 } ipnet_hdr_t;
22 #define IPH_AF_INET 2 /* Matches Solaris's AF_INET */
23 #define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */
25 #ifdef DLT_IPNET
27 static const struct tok ipnet_values[] = {
28 { IPH_AF_INET, "IPv4" },
29 { IPH_AF_INET6, "IPv6" },
30 { 0, NULL }
33 static inline void
34 ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
36 const ipnet_hdr_t *hdr;
37 hdr = (const ipnet_hdr_t *)bp;
39 ND_PRINT((ndo, "%d > %d", hdr->iph_zsrc, hdr->iph_zdst));
41 if (!ndo->ndo_qflag) {
42 ND_PRINT((ndo,", family %s (%d)",
43 tok2str(ipnet_values, "Unknown",
44 hdr->iph_family),
45 hdr->iph_family));
46 } else {
47 ND_PRINT((ndo,", %s",
48 tok2str(ipnet_values,
49 "Unknown Ethertype (0x%04x)",
50 hdr->iph_family)));
53 ND_PRINT((ndo, ", length %u: ", length));
56 static void
57 ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
59 const ipnet_hdr_t *hdr;
61 if (caplen < sizeof(ipnet_hdr_t)) {
62 ND_PRINT((ndo, "[|ipnet]"));
63 return;
66 if (ndo->ndo_eflag)
67 ipnet_hdr_print(ndo, p, length);
69 length -= sizeof(ipnet_hdr_t);
70 caplen -= sizeof(ipnet_hdr_t);
71 hdr = (const ipnet_hdr_t *)p;
72 p += sizeof(ipnet_hdr_t);
74 switch (hdr->iph_family) {
76 case IPH_AF_INET:
77 ip_print(ndo, p, length);
78 break;
80 case IPH_AF_INET6:
81 ip6_print(ndo, p, length);
82 break;
84 default:
85 if (!ndo->ndo_eflag)
86 ipnet_hdr_print(ndo, (const u_char *)hdr,
87 length + sizeof(ipnet_hdr_t));
89 if (!ndo->ndo_suppress_default_print)
90 ND_DEFAULTPRINT(p, caplen);
91 break;
96 * This is the top level routine of the printer. 'p' points
97 * to the ether header of the packet, 'h->ts' is the timestamp,
98 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
99 * is the number of bytes actually captured.
101 u_int
102 ipnet_if_print(netdissect_options *ndo,
103 const struct pcap_pkthdr *h, const u_char *p)
105 ipnet_print(ndo, p, h->len, h->caplen);
107 return (sizeof(ipnet_hdr_t));
111 * Local Variables:
112 * c-style: whitesmith
113 * c-basic-offset: 8
114 * End:
117 #endif /* DLT_IPNET */