]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
Merge branch 'master' of git+ssh://bpf.tcpdump.org/tcpdump/master/git/tcpdump
[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
17 typedef struct ppi_header {
18 uint8_t ppi_ver;
19 uint8_t ppi_flags;
20 uint16_t ppi_len;
21 uint32_t ppi_dlt;
22 } ppi_header_t;
23
24 #define PPI_HDRLEN 8
25
26 #ifdef DLT_PPI
27
28 static inline void
29 ppi_header_print(struct netdissect_options *ndo, const u_char *bp, u_int length)
30 {
31 const ppi_header_t *hdr;
32 u_int32_t dlt;
33 u_int16_t len;
34
35 hdr = (const ppi_header_t *)bp;
36
37 len = EXTRACT_16BITS(&hdr->ppi_len);
38 dlt = EXTRACT_32BITS(&hdr->ppi_dlt);
39
40 if (!ndo->ndo_qflag) {
41 ND_PRINT((ndo,", V.%d DLT %s (%d) len %d", hdr->ppi_ver,
42 pcap_datalink_val_to_name(dlt), dlt,
43 len));
44 } else {
45 ND_PRINT((ndo,", %s", pcap_datalink_val_to_name(dlt)));
46 }
47
48 ND_PRINT((ndo, ", length %u: ", length));
49 }
50
51 static void
52 ppi_print(struct netdissect_options *ndo,
53 const struct pcap_pkthdr *h, const u_char *p)
54 {
55 if_ndo_printer ndo_printer;
56 if_printer printer;
57 ppi_header_t *hdr;
58 u_int caplen = h->caplen;
59 u_int length = h->len;
60 u_int32_t dlt;
61
62 if (caplen < sizeof(ppi_header_t)) {
63 ND_PRINT((ndo, "[|ppi]"));
64 return;
65 }
66 hdr = (ppi_header_t *)p;
67 dlt = EXTRACT_32BITS(&hdr->ppi_dlt);
68
69 if (ndo->ndo_eflag)
70 ppi_header_print(ndo, p, length);
71
72 length -= sizeof(ppi_header_t);
73 caplen -= sizeof(ppi_header_t);
74 p += sizeof(ppi_header_t);
75
76 if ((printer = lookup_printer(dlt)) != NULL) {
77 printer(h, p);
78 } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
79 ndo_printer(ndo, h, p);
80 } else {
81 if (!ndo->ndo_eflag)
82 ppi_header_print(ndo, (u_char *)hdr,
83 length + sizeof(ppi_header_t));
84
85 if (!ndo->ndo_suppress_default_print)
86 ndo->ndo_default_print(ndo, p, caplen);
87 }
88 }
89
90 /*
91 * This is the top level routine of the printer. 'p' points
92 * to the ether header of the packet, 'h->ts' is the timestamp,
93 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
94 * is the number of bytes actually captured.
95 */
96 u_int
97 ppi_if_print(struct netdissect_options *ndo,
98 const struct pcap_pkthdr *h, const u_char *p)
99 {
100 ppi_print(ndo, h, p);
101
102 return (sizeof(ppi_header_t));
103 }
104
105 /*
106 * Local Variables:
107 * c-style: whitesmith
108 * c-basic-offset: 8
109 * End:
110 */
111
112 #endif /* DLT_PPI */