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