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