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