]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
Merge pull request #492 from vel21ripn/nflog-print
[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 = GET_LE_U_2(hdr->ppi_len);
39 dlt = GET_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", GET_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_t 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 = GET_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 = GET_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 printer = lookup_printer(ndo, dlt);
98 if (printer.printer != NULL) {
99 nhdr = *h;
100 nhdr.caplen = caplen;
101 nhdr.len = length;
102 if (ndo->ndo_void_printer == TRUE) {
103 printer.void_printer(ndo, &nhdr, p);
104 hdrlen = ndo->ndo_ll_header_length;
105 } else
106 hdrlen = printer.uint_printer(ndo, &nhdr, p);
107 } else {
108 if (!ndo->ndo_eflag)
109 ppi_header_print(ndo, (const u_char *)hdr, length + len);
110
111 if (!ndo->ndo_suppress_default_print)
112 ND_DEFAULTPRINT(p, caplen);
113 hdrlen = 0;
114 }
115 return (len + hdrlen);
116 trunc:
117 return (caplen);
118 }
119
120 /*
121 * This is the top level routine of the printer. 'p' points
122 * to the ether header of the packet, 'h->ts' is the timestamp,
123 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
124 * is the number of bytes actually captured.
125 */
126 u_int
127 ppi_if_print(netdissect_options *ndo,
128 const struct pcap_pkthdr *h, const u_char *p)
129 {
130 ndo->ndo_protocol = "ppi_if";
131 return (ppi_print(ndo, h, p));
132 }
133 #endif /* DLT_PPI */