]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
Rename the fn_printX() functions to nd_printX()
[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 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 ndo->ndo_protocol = "ppi";
68 if (caplen < sizeof(ppi_header_t)) {
69 ND_PRINT(" %s", tstr);
70 return (caplen);
71 }
72
73 hdr = (const ppi_header_t *)p;
74 ND_TCHECK_2(hdr->ppi_len);
75 len = EXTRACT_LE_U_2(hdr->ppi_len);
76 if (caplen < len) {
77 /*
78 * If we don't have the entire PPI header, don't
79 * bother.
80 */
81 ND_PRINT(" %s", tstr);
82 return (caplen);
83 }
84 if (len < sizeof(ppi_header_t)) {
85 ND_PRINT(" %s", tstr);
86 return (len);
87 }
88 ND_TCHECK_4(hdr->ppi_dlt);
89 dlt = EXTRACT_LE_U_4(hdr->ppi_dlt);
90
91 if (ndo->ndo_eflag)
92 ppi_header_print(ndo, p, length);
93
94 length -= len;
95 caplen -= len;
96 p += len;
97
98 if ((printer = lookup_printer(dlt)) != NULL) {
99 nhdr = *h;
100 nhdr.caplen = caplen;
101 nhdr.len = length;
102 hdrlen = printer(ndo, &nhdr, p);
103 } else {
104 if (!ndo->ndo_eflag)
105 ppi_header_print(ndo, (const u_char *)hdr, length + len);
106
107 if (!ndo->ndo_suppress_default_print)
108 ND_DEFAULTPRINT(p, caplen);
109 hdrlen = 0;
110 }
111 return (len + hdrlen);
112 trunc:
113 return (caplen);
114 }
115
116 /*
117 * This is the top level routine of the printer. 'p' points
118 * to the ether header of the packet, 'h->ts' is the timestamp,
119 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
120 * is the number of bytes actually captured.
121 */
122 u_int
123 ppi_if_print(netdissect_options *ndo,
124 const struct pcap_pkthdr *h, const u_char *p)
125 {
126 ndo->ndo_protocol = "ppi_if";
127 return (ppi_print(ndo, h, p));
128 }
129 #endif /* DLT_PPI */