]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
Clean up whitespaces/indentation
[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
17 typedef struct ppi_header {
18 nd_uint8_t ppi_ver;
19 nd_uint8_t ppi_flags;
20 nd_uint16_t ppi_len;
21 nd_uint32_t ppi_dlt;
22 } ppi_header_t;
23
24 #define PPI_HDRLEN 8
25
26 #ifdef DLT_PPI
27
28 static void
29 ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
30 {
31 const ppi_header_t *hdr;
32 uint16_t len;
33 uint32_t dlt;
34 const char *dltname;
35
36 hdr = (const ppi_header_t *)bp;
37
38 len = EXTRACT_LE_U_2(hdr->ppi_len);
39 dlt = EXTRACT_LE_U_4(hdr->ppi_dlt);
40 dltname = pcap_datalink_val_to_name(dlt);
41
42 if (!ndo->ndo_qflag) {
43 ND_PRINT("V.%u DLT %s (%u) len %u", EXTRACT_U_1(hdr->ppi_ver),
44 (dltname != NULL ? dltname : "UNKNOWN"), dlt,
45 len);
46 } else {
47 ND_PRINT("%s", (dltname != NULL ? dltname : "UNKNOWN"));
48 }
49
50 ND_PRINT(", length %u: ", length);
51 }
52
53 static u_int
54 ppi_print(netdissect_options *ndo,
55 const struct pcap_pkthdr *h, const u_char *p)
56 {
57 if_printer printer;
58 const ppi_header_t *hdr;
59 u_int caplen = h->caplen;
60 u_int length = h->len;
61 uint16_t len;
62 uint32_t dlt;
63 uint32_t hdrlen;
64 struct pcap_pkthdr nhdr;
65
66 ndo->ndo_protocol = "ppi";
67 if (caplen < sizeof(ppi_header_t)) {
68 nd_print_trunc(ndo);
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_trunc(ndo);
81 return (caplen);
82 }
83 if (len < sizeof(ppi_header_t)) {
84 nd_print_trunc(ndo);
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 ndo->ndo_protocol = "ppi_if";
126 return (ppi_print(ndo, h, p));
127 }
128 #endif /* DLT_PPI */