blob: b403536362464ba049724d911b6e7f168f3ef977 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
2 * Oracle
3 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07004#define NETDISSECT_REWORKED
JP Abgrall53f17a92014-02-12 14:02:41 -08005#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <tcpdump-stdinc.h>
10
JP Abgrall53f17a92014-02-12 14:02:41 -080011#include "interface.h"
12#include "extract.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070013
14typedef struct ppi_header {
15 uint8_t ppi_ver;
16 uint8_t ppi_flags;
17 uint16_t ppi_len;
18 uint32_t ppi_dlt;
19} ppi_header_t;
20
21#define PPI_HDRLEN 8
JP Abgrall53f17a92014-02-12 14:02:41 -080022
23#ifdef DLT_PPI
24
25static inline void
Elliott Hughes892a68b2015-10-19 14:43:53 -070026ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -080027{
28 const ppi_header_t *hdr;
Elliott Hughes892a68b2015-10-19 14:43:53 -070029 uint16_t len;
30 uint32_t dlt;
JP Abgrall53f17a92014-02-12 14:02:41 -080031
32 hdr = (const ppi_header_t *)bp;
33
Elliott Hughes892a68b2015-10-19 14:43:53 -070034 len = EXTRACT_LE_16BITS(&hdr->ppi_len);
35 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
JP Abgrall53f17a92014-02-12 14:02:41 -080036
37 if (!ndo->ndo_qflag) {
Elliott Hughes892a68b2015-10-19 14:43:53 -070038 ND_PRINT((ndo, "V.%d DLT %s (%d) len %d", hdr->ppi_ver,
JP Abgrall53f17a92014-02-12 14:02:41 -080039 pcap_datalink_val_to_name(dlt), dlt,
40 len));
41 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -070042 ND_PRINT((ndo, "%s", pcap_datalink_val_to_name(dlt)));
JP Abgrall53f17a92014-02-12 14:02:41 -080043 }
44
45 ND_PRINT((ndo, ", length %u: ", length));
46}
47
48static void
Elliott Hughes892a68b2015-10-19 14:43:53 -070049ppi_print(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -080050 const struct pcap_pkthdr *h, const u_char *p)
51{
52 if_ndo_printer ndo_printer;
53 if_printer printer;
54 ppi_header_t *hdr;
55 u_int caplen = h->caplen;
56 u_int length = h->len;
Elliott Hughes892a68b2015-10-19 14:43:53 -070057 uint16_t len;
58 uint32_t dlt;
JP Abgrall53f17a92014-02-12 14:02:41 -080059
60 if (caplen < sizeof(ppi_header_t)) {
61 ND_PRINT((ndo, "[|ppi]"));
62 return;
63 }
Elliott Hughes892a68b2015-10-19 14:43:53 -070064
JP Abgrall53f17a92014-02-12 14:02:41 -080065 hdr = (ppi_header_t *)p;
Elliott Hughes892a68b2015-10-19 14:43:53 -070066 len = EXTRACT_LE_16BITS(&hdr->ppi_len);
67 if (len < sizeof(ppi_header_t)) {
68 ND_PRINT((ndo, "[|ppi]"));
69 return;
70 }
71 if (caplen < len) {
72 ND_PRINT((ndo, "[|ppi]"));
73 return;
74 }
75 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
JP Abgrall53f17a92014-02-12 14:02:41 -080076
77 if (ndo->ndo_eflag)
78 ppi_header_print(ndo, p, length);
79
Elliott Hughes892a68b2015-10-19 14:43:53 -070080 length -= len;
81 caplen -= len;
82 p += len;
JP Abgrall53f17a92014-02-12 14:02:41 -080083
84 if ((printer = lookup_printer(dlt)) != NULL) {
85 printer(h, p);
86 } else if ((ndo_printer = lookup_ndo_printer(dlt)) != NULL) {
87 ndo_printer(ndo, h, p);
88 } else {
89 if (!ndo->ndo_eflag)
Elliott Hughes892a68b2015-10-19 14:43:53 -070090 ppi_header_print(ndo, (u_char *)hdr, length + len);
JP Abgrall53f17a92014-02-12 14:02:41 -080091
92 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -070093 ND_DEFAULTPRINT(p, caplen);
JP Abgrall53f17a92014-02-12 14:02:41 -080094 }
95}
96
97/*
98 * This is the top level routine of the printer. 'p' points
99 * to the ether header of the packet, 'h->ts' is the timestamp,
100 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
101 * is the number of bytes actually captured.
102 */
103u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700104ppi_if_print(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -0800105 const struct pcap_pkthdr *h, const u_char *p)
106{
107 ppi_print(ndo, h, p);
108
109 return (sizeof(ppi_header_t));
110}
111
112/*
113 * Local Variables:
114 * c-style: whitesmith
115 * c-basic-offset: 8
116 * End:
117 */
118
119#endif /* DLT_PPI */