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