Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 1 | /* \summary: Solaris DLT_IPNET printer */ |
| 2 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 3 | #ifdef HAVE_CONFIG_H |
| 4 | #include "config.h" |
| 5 | #endif |
| 6 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 7 | #include <netdissect-stdinc.h> |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 8 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 9 | #include "netdissect.h" |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 10 | |
| 11 | typedef struct ipnet_hdr { |
| 12 | uint8_t iph_version; |
| 13 | uint8_t iph_family; |
| 14 | uint16_t iph_htype; |
| 15 | uint32_t iph_pktlen; |
| 16 | uint32_t iph_ifindex; |
| 17 | uint32_t iph_grifindex; |
| 18 | uint32_t iph_zsrc; |
| 19 | uint32_t iph_zdst; |
| 20 | } ipnet_hdr_t; |
| 21 | |
| 22 | #define IPH_AF_INET 2 /* Matches Solaris's AF_INET */ |
| 23 | #define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 24 | |
| 25 | #ifdef DLT_IPNET |
| 26 | |
| 27 | static const struct tok ipnet_values[] = { |
| 28 | { IPH_AF_INET, "IPv4" }, |
| 29 | { IPH_AF_INET6, "IPv6" }, |
| 30 | { 0, NULL } |
| 31 | }; |
| 32 | |
| 33 | static inline void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 34 | ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 35 | { |
| 36 | const ipnet_hdr_t *hdr; |
| 37 | hdr = (const ipnet_hdr_t *)bp; |
| 38 | |
| 39 | ND_PRINT((ndo, "%d > %d", hdr->iph_zsrc, hdr->iph_zdst)); |
| 40 | |
| 41 | if (!ndo->ndo_qflag) { |
| 42 | ND_PRINT((ndo,", family %s (%d)", |
| 43 | tok2str(ipnet_values, "Unknown", |
| 44 | hdr->iph_family), |
| 45 | hdr->iph_family)); |
| 46 | } else { |
| 47 | ND_PRINT((ndo,", %s", |
| 48 | tok2str(ipnet_values, |
| 49 | "Unknown Ethertype (0x%04x)", |
| 50 | hdr->iph_family))); |
| 51 | } |
| 52 | |
| 53 | ND_PRINT((ndo, ", length %u: ", length)); |
| 54 | } |
| 55 | |
| 56 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 57 | ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 58 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 59 | const ipnet_hdr_t *hdr; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 60 | |
| 61 | if (caplen < sizeof(ipnet_hdr_t)) { |
| 62 | ND_PRINT((ndo, "[|ipnet]")); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | if (ndo->ndo_eflag) |
| 67 | ipnet_hdr_print(ndo, p, length); |
| 68 | |
| 69 | length -= sizeof(ipnet_hdr_t); |
| 70 | caplen -= sizeof(ipnet_hdr_t); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 71 | hdr = (const ipnet_hdr_t *)p; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 72 | p += sizeof(ipnet_hdr_t); |
| 73 | |
| 74 | switch (hdr->iph_family) { |
| 75 | |
| 76 | case IPH_AF_INET: |
| 77 | ip_print(ndo, p, length); |
| 78 | break; |
| 79 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 80 | case IPH_AF_INET6: |
| 81 | ip6_print(ndo, p, length); |
| 82 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 83 | |
| 84 | default: |
| 85 | if (!ndo->ndo_eflag) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 86 | ipnet_hdr_print(ndo, (const u_char *)hdr, |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 87 | length + sizeof(ipnet_hdr_t)); |
| 88 | |
| 89 | if (!ndo->ndo_suppress_default_print) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 90 | ND_DEFAULTPRINT(p, caplen); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 91 | break; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * This is the top level routine of the printer. 'p' points |
| 97 | * to the ether header of the packet, 'h->ts' is the timestamp, |
| 98 | * 'h->len' is the length of the packet off the wire, and 'h->caplen' |
| 99 | * is the number of bytes actually captured. |
| 100 | */ |
| 101 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 102 | ipnet_if_print(netdissect_options *ndo, |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 103 | const struct pcap_pkthdr *h, const u_char *p) |
| 104 | { |
| 105 | ipnet_print(ndo, p, h->len, h->caplen); |
| 106 | |
| 107 | return (sizeof(ipnet_hdr_t)); |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Local Variables: |
| 112 | * c-style: whitesmith |
| 113 | * c-basic-offset: 8 |
| 114 | * End: |
| 115 | */ |
| 116 | |
| 117 | #endif /* DLT_IPNET */ |