]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
from Weesan Lee <[email protected]>: display pim bidir support
[tcpdump] / print-ppi.c
1 /*
2 * Oracle
3 */
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7
8 #include <tcpdump-stdinc.h>
9
10 #include <stdio.h>
11 #include <pcap.h>
12
13 #include "netdissect.h"
14 #include "interface.h"
15 #include "extract.h"
16 #include "ppi.h"
17
18 #ifdef DLT_PPI
19
20 static inline void
21 ppi_header_print(struct netdissect_options *ndo, const u_char *bp, u_int length)
22 {
23 const ppi_header_t *hdr;
24 hdr = (const ppi_header_t *)bp;
25 u_int32_t dlt;
26 u_int16_t len;
27
28 len = EXTRACT_16BITS(&hdr->ppi_len);
29 dlt = EXTRACT_32BITS(&hdr->ppi_dlt);
30
31 if (!ndo->ndo_qflag) {
32 ND_PRINT((ndo,", V.%d DLT %s (%d) len %d", hdr->ppi_ver,
33 pcap_datalink_val_to_name(dlt), dlt,
34 len));
35 } else {
36 ND_PRINT((ndo,", %s", pcap_datalink_val_to_name(dlt)));
37 }
38
39 ND_PRINT((ndo, ", length %u: ", length));
40 }
41
42 static void
43 ppi_print(struct netdissect_options *ndo,
44 const struct pcap_pkthdr *h, const u_char *p)
45 {
46 if_ndo_printer ndo_printer;
47 if_printer printer;
48 ppi_header_t *hdr;
49 u_int caplen = h->caplen;
50 u_int length = h->len;
51 u_int32_t dlt;
52
53 if (caplen < sizeof(ppi_header_t)) {
54 ND_PRINT((ndo, "[|ppi]"));
55 return;
56 }
57 hdr = (ppi_header_t *)p;
58 dlt = EXTRACT_32BITS(&hdr->ppi_dlt);
59
60 if (ndo->ndo_eflag)
61 ppi_header_print(ndo, p, length);
62
63 length -= sizeof(ppi_header_t);
64 caplen -= sizeof(ppi_header_t);
65 p += sizeof(ppi_header_t);
66
67 if ((printer = lookup_printer(dlt)) != NULL) {
68 printer(h, p);
69 } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
70 ndo_printer(ndo, h, p);
71 } else {
72 if (!ndo->ndo_eflag)
73 ppi_header_print(ndo, (u_char *)hdr,
74 length + sizeof(ppi_header_t));
75
76 if (!ndo->ndo_suppress_default_print)
77 ndo->ndo_default_print(ndo, p, caplen);
78 }
79 }
80
81 /*
82 * This is the top level routine of the printer. 'p' points
83 * to the ether header of the packet, 'h->ts' is the timestamp,
84 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
85 * is the number of bytes actually captured.
86 */
87 u_int
88 ppi_if_print(struct netdissect_options *ndo,
89 const struct pcap_pkthdr *h, const u_char *p)
90 {
91 ppi_print(ndo, h, p);
92
93 return (sizeof(ppi_header_t));
94 }
95
96 /*
97 * Local Variables:
98 * c-style: whitesmith
99 * c-basic-offset: 8
100 * End:
101 */
102
103 #endif /* DLT_PPI */