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