blob: 72cd1b867fd502b9b5699f1ee669a0f10011aed6 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
2 * Oracle
3 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07004
5/* \summary: Oracle DLT_PPI printer */
6
JP Abgrall53f17a92014-02-12 14:02:41 -08007#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
Elliott Hughese2e3bd12017-05-15 10:59:29 -070011#include <netdissect-stdinc.h>
JP Abgrall53f17a92014-02-12 14:02:41 -080012
Elliott Hughese2e3bd12017-05-15 10:59:29 -070013#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080014#include "extract.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070015
16typedef 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
JP Abgrall53f17a92014-02-12 14:02:41 -080024
25#ifdef DLT_PPI
26
27static inline void
Elliott Hughes892a68b2015-10-19 14:43:53 -070028ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -080029{
30 const ppi_header_t *hdr;
Elliott Hughes892a68b2015-10-19 14:43:53 -070031 uint16_t len;
32 uint32_t dlt;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070033 const char *dltname;
JP Abgrall53f17a92014-02-12 14:02:41 -080034
35 hdr = (const ppi_header_t *)bp;
36
Elliott Hughes892a68b2015-10-19 14:43:53 -070037 len = EXTRACT_LE_16BITS(&hdr->ppi_len);
38 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070039 dltname = pcap_datalink_val_to_name(dlt);
JP Abgrall53f17a92014-02-12 14:02:41 -080040
41 if (!ndo->ndo_qflag) {
Elliott Hughes892a68b2015-10-19 14:43:53 -070042 ND_PRINT((ndo, "V.%d DLT %s (%d) len %d", hdr->ppi_ver,
Elliott Hughese2e3bd12017-05-15 10:59:29 -070043 (dltname != NULL ? dltname : "UNKNOWN"), dlt,
JP Abgrall53f17a92014-02-12 14:02:41 -080044 len));
45 } else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -070046 ND_PRINT((ndo, "%s", (dltname != NULL ? dltname : "UNKNOWN")));
JP Abgrall53f17a92014-02-12 14:02:41 -080047 }
48
49 ND_PRINT((ndo, ", length %u: ", length));
50}
51
Elliott Hughese2e3bd12017-05-15 10:59:29 -070052static u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -070053ppi_print(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -080054 const struct pcap_pkthdr *h, const u_char *p)
55{
Elliott Hughese2e3bd12017-05-15 10:59:29 -070056 if_printer printer;
57 const ppi_header_t *hdr;
JP Abgrall53f17a92014-02-12 14:02:41 -080058 u_int caplen = h->caplen;
59 u_int length = h->len;
Elliott Hughes892a68b2015-10-19 14:43:53 -070060 uint16_t len;
61 uint32_t dlt;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070062 uint32_t hdrlen;
63 struct pcap_pkthdr nhdr;
JP Abgrall53f17a92014-02-12 14:02:41 -080064
65 if (caplen < sizeof(ppi_header_t)) {
66 ND_PRINT((ndo, "[|ppi]"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -070067 return (caplen);
JP Abgrall53f17a92014-02-12 14:02:41 -080068 }
Elliott Hughes892a68b2015-10-19 14:43:53 -070069
Elliott Hughese2e3bd12017-05-15 10:59:29 -070070 hdr = (const ppi_header_t *)p;
Elliott Hughes892a68b2015-10-19 14:43:53 -070071 len = EXTRACT_LE_16BITS(&hdr->ppi_len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070072 if (caplen < len) {
73 /*
74 * If we don't have the entire PPI header, don't
75 * bother.
76 */
77 ND_PRINT((ndo, "[|ppi]"));
78 return (caplen);
79 }
Elliott Hughes892a68b2015-10-19 14:43:53 -070080 if (len < sizeof(ppi_header_t)) {
81 ND_PRINT((ndo, "[|ppi]"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -070082 return (len);
Elliott Hughes892a68b2015-10-19 14:43:53 -070083 }
84 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
JP Abgrall53f17a92014-02-12 14:02:41 -080085
86 if (ndo->ndo_eflag)
87 ppi_header_print(ndo, p, length);
88
Elliott Hughes892a68b2015-10-19 14:43:53 -070089 length -= len;
90 caplen -= len;
91 p += len;
JP Abgrall53f17a92014-02-12 14:02:41 -080092
93 if ((printer = lookup_printer(dlt)) != NULL) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -070094 nhdr = *h;
95 nhdr.caplen = caplen;
96 nhdr.len = length;
97 hdrlen = printer(ndo, &nhdr, p);
JP Abgrall53f17a92014-02-12 14:02:41 -080098 } else {
99 if (!ndo->ndo_eflag)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700100 ppi_header_print(ndo, (const u_char *)hdr, length + len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800101
102 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700103 ND_DEFAULTPRINT(p, caplen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700104 hdrlen = 0;
JP Abgrall53f17a92014-02-12 14:02:41 -0800105 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700106 return (len + hdrlen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800107}
108
109/*
110 * This is the top level routine of the printer. 'p' points
111 * to the ether header of the packet, 'h->ts' is the timestamp,
112 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
113 * is the number of bytes actually captured.
114 */
115u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700116ppi_if_print(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -0800117 const struct pcap_pkthdr *h, const u_char *p)
118{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700119 return (ppi_print(ndo, h, p));
JP Abgrall53f17a92014-02-12 14:02:41 -0800120}
121
122/*
123 * Local Variables:
124 * c-style: whitesmith
125 * c-basic-offset: 8
126 * End:
127 */
128
129#endif /* DLT_PPI */