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