1 /* 2 * Oracle 3 */ 4 5 #include <sys/cdefs.h> 6 #ifndef lint 7 __RCSID("$NetBSD: print-ppi.c,v 1.2 2017/01/24 23:29:14 christos Exp $"); 8 #endif 9 10 #ifdef HAVE_CONFIG_H 11 #include "config.h" 12 #endif 13 14 #include <netdissect-stdinc.h> 15 16 #include "netdissect.h" 17 #include "extract.h" 18 19 typedef struct ppi_header { 20 uint8_t ppi_ver; 21 uint8_t ppi_flags; 22 uint16_t ppi_len; 23 uint32_t ppi_dlt; 24 } ppi_header_t; 25 26 #define PPI_HDRLEN 8 27 28 #ifdef DLT_PPI 29 30 static inline void 31 ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length) 32 { 33 const ppi_header_t *hdr; 34 uint16_t len; 35 uint32_t dlt; 36 37 hdr = (const ppi_header_t *)bp; 38 39 len = EXTRACT_LE_16BITS(&hdr->ppi_len); 40 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt); 41 42 if (!ndo->ndo_qflag) { 43 ND_PRINT((ndo, "V.%d DLT %s (%d) len %d", hdr->ppi_ver, 44 pcap_datalink_val_to_name(dlt), dlt, 45 len)); 46 } else { 47 ND_PRINT((ndo, "%s", pcap_datalink_val_to_name(dlt))); 48 } 49 50 ND_PRINT((ndo, ", 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 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 if (caplen < sizeof(ppi_header_t)) { 67 ND_PRINT((ndo, "[|ppi]")); 68 return (caplen); 69 } 70 71 hdr = (const ppi_header_t *)p; 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 dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt); 86 87 if (ndo->ndo_eflag) 88 ppi_header_print(ndo, p, length); 89 90 length -= len; 91 caplen -= len; 92 p += len; 93 94 if ((printer = lookup_printer(dlt)) != NULL) { 95 nhdr = *h; 96 nhdr.caplen = caplen; 97 nhdr.len = length; 98 hdrlen = printer(ndo, &nhdr, p); 99 } else { 100 if (!ndo->ndo_eflag) 101 ppi_header_print(ndo, (const u_char *)hdr, length + len); 102 103 if (!ndo->ndo_suppress_default_print) 104 ND_DEFAULTPRINT(p, caplen); 105 hdrlen = 0; 106 } 107 return (len + hdrlen); 108 } 109 110 /* 111 * This is the top level routine of the printer. 'p' points 112 * to the ether header of the packet, 'h->ts' is the timestamp, 113 * 'h->len' is the length of the packet off the wire, and 'h->caplen' 114 * is the number of bytes actually captured. 115 */ 116 u_int 117 ppi_if_print(netdissect_options *ndo, 118 const struct pcap_pkthdr *h, const u_char *p) 119 { 120 return (ppi_print(ndo, h, p)); 121 } 122 123 /* 124 * Local Variables: 125 * c-style: whitesmith 126 * c-basic-offset: 8 127 * End: 128 */ 129 130 #endif /* DLT_PPI */ 131