source: rtems-libbsd/freebsd/contrib/tcpdump/print-ipnet.c @ 8440506

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8440506 was 8440506, checked in by Chris Johns <chrisj@…>, on 06/15/15 at 07:42:23

Add tcpdump and libpcap.

  • Update the file builder generator to handle generator specific cflags and includes. The tcpdump and libpcap have localised headers and need specific headers paths to see them. There are also module specific flags and these need to be passed to the lex and yacc generators.
  • Add the tcpdump support.
  • Property mode set to 100644
File size: 2.3 KB
Line 
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
19const struct tok ipnet_values[] = {
20        { IPH_AF_INET,          "IPv4" },
21        { IPH_AF_INET6,         "IPv6" },
22        { 0,                    NULL }
23};
24
25static inline void
26ipnet_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
48static void
49ipnet_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 */
95u_int
96ipnet_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 */
Note: See TracBrowser for help on using the repository browser.