]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
Fix a bunch of de-constifications.
[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 u_int
49 ppi_print(netdissect_options *ndo,
50 const struct pcap_pkthdr *h, const u_char *p)
51 {
52 if_printer printer;
53 const 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 uint32_t hdrlen;
59
60 if (caplen < sizeof(ppi_header_t)) {
61 ND_PRINT((ndo, "[|ppi]"));
62 return (caplen);
63 }
64
65 hdr = (const ppi_header_t *)p;
66 len = EXTRACT_LE_16BITS(&hdr->ppi_len);
67 if (caplen < len) {
68 /*
69 * If we don't have the entire PPI header, don't
70 * bother.
71 */
72 ND_PRINT((ndo, "[|ppi]"));
73 return (caplen);
74 }
75 if (len < sizeof(ppi_header_t)) {
76 ND_PRINT((ndo, "[|ppi]"));
77 return (len);
78 }
79 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
80
81 if (ndo->ndo_eflag)
82 ppi_header_print(ndo, p, length);
83
84 length -= len;
85 caplen -= len;
86 p += len;
87
88 if ((printer = lookup_printer(dlt)) != NULL) {
89 hdrlen = printer(ndo, h, p);
90 } else {
91 if (!ndo->ndo_eflag)
92 ppi_header_print(ndo, (const u_char *)hdr, length + len);
93
94 if (!ndo->ndo_suppress_default_print)
95 ND_DEFAULTPRINT(p, caplen);
96 hdrlen = 0;
97 }
98 return (len + hdrlen);
99 }
100
101 /*
102 * This is the top level routine of the printer. 'p' points
103 * to the ether header of the packet, 'h->ts' is the timestamp,
104 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
105 * is the number of bytes actually captured.
106 */
107 u_int
108 ppi_if_print(netdissect_options *ndo,
109 const struct pcap_pkthdr *h, const u_char *p)
110 {
111 return (ppi_print(ndo, h, p));
112 }
113
114 /*
115 * Local Variables:
116 * c-style: whitesmith
117 * c-basic-offset: 8
118 * End:
119 */
120
121 #endif /* DLT_PPI */