13340d773SGleb Smirnoff /* \summary: Solaris DLT_IPNET printer */ 23340d773SGleb Smirnoff 3*ee67461eSJoseph Mingrone #include <config.h> 427df3f5dSRui Paulo 5*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 627df3f5dSRui Paulo 7*ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK 83340d773SGleb Smirnoff #include "netdissect.h" 939e421e8SCy Schubert #include "extract.h" 1039e421e8SCy Schubert 113c602fabSXin LI 123c602fabSXin LI typedef struct ipnet_hdr { 1339e421e8SCy Schubert nd_uint8_t iph_version; 1439e421e8SCy Schubert nd_uint8_t iph_family; 1539e421e8SCy Schubert nd_uint16_t iph_htype; 1639e421e8SCy Schubert nd_uint32_t iph_pktlen; 1739e421e8SCy Schubert nd_uint32_t iph_ifindex; 1839e421e8SCy Schubert nd_uint32_t iph_grifindex; 1939e421e8SCy Schubert nd_uint32_t iph_zsrc; 2039e421e8SCy Schubert nd_uint32_t iph_zdst; 213c602fabSXin LI } ipnet_hdr_t; 223c602fabSXin LI 233c602fabSXin LI #define IPH_AF_INET 2 /* Matches Solaris's AF_INET */ 243c602fabSXin LI #define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */ 2527df3f5dSRui Paulo 2627df3f5dSRui Paulo #ifdef DLT_IPNET 2727df3f5dSRui Paulo 283c602fabSXin LI static const struct tok ipnet_values[] = { 2927df3f5dSRui Paulo { IPH_AF_INET, "IPv4" }, 3027df3f5dSRui Paulo { IPH_AF_INET6, "IPv6" }, 3127df3f5dSRui Paulo { 0, NULL } 3227df3f5dSRui Paulo }; 3327df3f5dSRui Paulo 34*ee67461eSJoseph Mingrone static void 353c602fabSXin LI ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) 3627df3f5dSRui Paulo { 3727df3f5dSRui Paulo const ipnet_hdr_t *hdr; 3827df3f5dSRui Paulo hdr = (const ipnet_hdr_t *)bp; 3927df3f5dSRui Paulo 40*ee67461eSJoseph Mingrone ND_PRINT("%u > %u", GET_BE_U_4(hdr->iph_zsrc), 41*ee67461eSJoseph Mingrone GET_BE_U_4(hdr->iph_zdst)); 4227df3f5dSRui Paulo 4327df3f5dSRui Paulo if (!ndo->ndo_qflag) { 44*ee67461eSJoseph Mingrone ND_PRINT(", family %s (%u)", 4527df3f5dSRui Paulo tok2str(ipnet_values, "Unknown", 46*ee67461eSJoseph Mingrone GET_U_1(hdr->iph_family)), 47*ee67461eSJoseph Mingrone GET_U_1(hdr->iph_family)); 4827df3f5dSRui Paulo } else { 49*ee67461eSJoseph Mingrone ND_PRINT(", %s", 5027df3f5dSRui Paulo tok2str(ipnet_values, 5127df3f5dSRui Paulo "Unknown Ethertype (0x%04x)", 52*ee67461eSJoseph Mingrone GET_U_1(hdr->iph_family))); 5327df3f5dSRui Paulo } 5427df3f5dSRui Paulo 55*ee67461eSJoseph Mingrone ND_PRINT(", length %u: ", length); 5627df3f5dSRui Paulo } 5727df3f5dSRui Paulo 5827df3f5dSRui Paulo static void 593c602fabSXin LI ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) 6027df3f5dSRui Paulo { 613340d773SGleb Smirnoff const ipnet_hdr_t *hdr; 6227df3f5dSRui Paulo 63*ee67461eSJoseph Mingrone ND_TCHECK_LEN(p, sizeof(ipnet_hdr_t)); 64*ee67461eSJoseph Mingrone ndo->ndo_ll_hdr_len += sizeof(ipnet_hdr_t); 6527df3f5dSRui Paulo 6627df3f5dSRui Paulo if (ndo->ndo_eflag) 6727df3f5dSRui Paulo ipnet_hdr_print(ndo, p, length); 6827df3f5dSRui Paulo 6927df3f5dSRui Paulo length -= sizeof(ipnet_hdr_t); 7027df3f5dSRui Paulo caplen -= sizeof(ipnet_hdr_t); 713340d773SGleb Smirnoff hdr = (const ipnet_hdr_t *)p; 7227df3f5dSRui Paulo p += sizeof(ipnet_hdr_t); 7327df3f5dSRui Paulo 74*ee67461eSJoseph Mingrone switch (GET_U_1(hdr->iph_family)) { 7527df3f5dSRui Paulo 7627df3f5dSRui Paulo case IPH_AF_INET: 7727df3f5dSRui Paulo ip_print(ndo, p, length); 7827df3f5dSRui Paulo break; 7927df3f5dSRui Paulo 8027df3f5dSRui Paulo case IPH_AF_INET6: 81cac3dcd5SXin LI ip6_print(ndo, p, length); 8227df3f5dSRui Paulo break; 8327df3f5dSRui Paulo 8427df3f5dSRui Paulo default: 8527df3f5dSRui Paulo if (!ndo->ndo_eflag) 863340d773SGleb Smirnoff ipnet_hdr_print(ndo, (const u_char *)hdr, 8727df3f5dSRui Paulo length + sizeof(ipnet_hdr_t)); 8827df3f5dSRui Paulo 8927df3f5dSRui Paulo if (!ndo->ndo_suppress_default_print) 903c602fabSXin LI ND_DEFAULTPRINT(p, caplen); 9127df3f5dSRui Paulo break; 9227df3f5dSRui Paulo } 9327df3f5dSRui Paulo } 9427df3f5dSRui Paulo 9527df3f5dSRui Paulo /* 9627df3f5dSRui Paulo * This is the top level routine of the printer. 'p' points 9727df3f5dSRui Paulo * to the ether header of the packet, 'h->ts' is the timestamp, 9827df3f5dSRui Paulo * 'h->len' is the length of the packet off the wire, and 'h->caplen' 9927df3f5dSRui Paulo * is the number of bytes actually captured. 10027df3f5dSRui Paulo */ 101*ee67461eSJoseph Mingrone void 1023c602fabSXin LI ipnet_if_print(netdissect_options *ndo, 10327df3f5dSRui Paulo const struct pcap_pkthdr *h, const u_char *p) 10427df3f5dSRui Paulo { 105*ee67461eSJoseph Mingrone ndo->ndo_protocol = "ipnet"; 10627df3f5dSRui Paulo ipnet_print(ndo, p, h->len, h->caplen); 10727df3f5dSRui Paulo } 10827df3f5dSRui Paulo #endif /* DLT_IPNET */ 109