]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppi.c
dc9f2a36cc9056ddb20b5518e4f3c3435181db3d
[tcpdump] / print-ppi.c
1 /*
2 * Oracle
3 */
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7
8 #include <tcpdump-stdinc.h>
9
10 #include <stdio.h>
11
12 #include "netdissect.h"
13 #include "interface.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(struct netdissect_options *ndo, const u_char *bp, u_int length)
29 {
30 const ppi_header_t *hdr;
31 u_int32_t dlt;
32 u_int16_t len;
33
34 hdr = (const ppi_header_t *)bp;
35
36 len = EXTRACT_16BITS(&hdr->ppi_len);
37 dlt = EXTRACT_32BITS(&hdr->ppi_dlt);
38
39 if (!ndo->ndo_qflag) {
40 ND_PRINT((ndo,", V.%d DLT %s (%d) len %d", hdr->ppi_ver,
41 pcap_datalink_val_to_name(dlt), dlt,
42 len));
43 } else {
44 ND_PRINT((ndo,", %s", pcap_datalink_val_to_name(dlt)));
45 }
46
47 ND_PRINT((ndo, ", length %u: ", length));
48 }
49
50 static void
51 ppi_print(struct netdissect_options *ndo,
52 const struct pcap_pkthdr *h, const u_char *p)
53 {
54 if_ndo_printer ndo_printer;
55 if_printer printer;
56 ppi_header_t *hdr;
57 u_int caplen = h->caplen;
58 u_int length = h->len;
59 u_int32_t dlt;
60
61 if (caplen < sizeof(ppi_header_t)) {
62 ND_PRINT((ndo, "[|ppi]"));
63 return;
64 }
65 hdr = (ppi_header_t *)p;
66 dlt = EXTRACT_32BITS(&hdr->ppi_dlt);
67
68 if (ndo->ndo_eflag)
69 ppi_header_print(ndo, p, length);
70
71 length -= sizeof(ppi_header_t);
72 caplen -= sizeof(ppi_header_t);
73 p += sizeof(ppi_header_t);
74
75 if ((printer = lookup_printer(dlt)) != NULL) {
76 printer(h, p);
77 } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
78 ndo_printer(ndo, h, p);
79 } else {
80 if (!ndo->ndo_eflag)
81 ppi_header_print(ndo, (u_char *)hdr,
82 length + sizeof(ppi_header_t));
83
84 if (!ndo->ndo_suppress_default_print)
85 ndo->ndo_default_print(ndo, p, caplen);
86 }
87 }
88
89 /*
90 * This is the top level routine of the printer. 'p' points
91 * to the ether header of the packet, 'h->ts' is the timestamp,
92 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
93 * is the number of bytes actually captured.
94 */
95 u_int
96 ppi_if_print(struct netdissect_options *ndo,
97 const struct pcap_pkthdr *h, const u_char *p)
98 {
99 ppi_print(ndo, h, p);
100
101 return (sizeof(ppi_header_t));
102 }
103
104 /*
105 * Local Variables:
106 * c-style: whitesmith
107 * c-basic-offset: 8
108 * End:
109 */
110
111 #endif /* DLT_PPI */