1*3340d773SGleb Smirnoff /* \summary: Solaris DLT_IPNET printer */ 2*3340d773SGleb Smirnoff 327df3f5dSRui Paulo #ifdef HAVE_CONFIG_H 427df3f5dSRui Paulo #include "config.h" 527df3f5dSRui Paulo #endif 627df3f5dSRui Paulo 7*3340d773SGleb Smirnoff #include <netdissect-stdinc.h> 827df3f5dSRui Paulo 9*3340d773SGleb Smirnoff #include "netdissect.h" 103c602fabSXin LI 113c602fabSXin LI typedef struct ipnet_hdr { 123c602fabSXin LI uint8_t iph_version; 133c602fabSXin LI uint8_t iph_family; 143c602fabSXin LI uint16_t iph_htype; 153c602fabSXin LI uint32_t iph_pktlen; 163c602fabSXin LI uint32_t iph_ifindex; 173c602fabSXin LI uint32_t iph_grifindex; 183c602fabSXin LI uint32_t iph_zsrc; 193c602fabSXin LI uint32_t iph_zdst; 203c602fabSXin LI } ipnet_hdr_t; 213c602fabSXin LI 223c602fabSXin LI #define IPH_AF_INET 2 /* Matches Solaris's AF_INET */ 233c602fabSXin LI #define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */ 2427df3f5dSRui Paulo 2527df3f5dSRui Paulo #ifdef DLT_IPNET 2627df3f5dSRui Paulo 273c602fabSXin LI static const struct tok ipnet_values[] = { 2827df3f5dSRui Paulo { IPH_AF_INET, "IPv4" }, 2927df3f5dSRui Paulo { IPH_AF_INET6, "IPv6" }, 3027df3f5dSRui Paulo { 0, NULL } 3127df3f5dSRui Paulo }; 3227df3f5dSRui Paulo 3327df3f5dSRui Paulo static inline void 343c602fabSXin LI ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) 3527df3f5dSRui Paulo { 3627df3f5dSRui Paulo const ipnet_hdr_t *hdr; 3727df3f5dSRui Paulo hdr = (const ipnet_hdr_t *)bp; 3827df3f5dSRui Paulo 3927df3f5dSRui Paulo ND_PRINT((ndo, "%d > %d", hdr->iph_zsrc, hdr->iph_zdst)); 4027df3f5dSRui Paulo 4127df3f5dSRui Paulo if (!ndo->ndo_qflag) { 4227df3f5dSRui Paulo ND_PRINT((ndo,", family %s (%d)", 4327df3f5dSRui Paulo tok2str(ipnet_values, "Unknown", 4427df3f5dSRui Paulo hdr->iph_family), 4527df3f5dSRui Paulo hdr->iph_family)); 4627df3f5dSRui Paulo } else { 4727df3f5dSRui Paulo ND_PRINT((ndo,", %s", 4827df3f5dSRui Paulo tok2str(ipnet_values, 4927df3f5dSRui Paulo "Unknown Ethertype (0x%04x)", 5027df3f5dSRui Paulo hdr->iph_family))); 5127df3f5dSRui Paulo } 5227df3f5dSRui Paulo 5327df3f5dSRui Paulo ND_PRINT((ndo, ", length %u: ", length)); 5427df3f5dSRui Paulo } 5527df3f5dSRui Paulo 5627df3f5dSRui Paulo static void 573c602fabSXin LI ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) 5827df3f5dSRui Paulo { 59*3340d773SGleb Smirnoff const ipnet_hdr_t *hdr; 6027df3f5dSRui Paulo 6127df3f5dSRui Paulo if (caplen < sizeof(ipnet_hdr_t)) { 6227df3f5dSRui Paulo ND_PRINT((ndo, "[|ipnet]")); 6327df3f5dSRui Paulo return; 6427df3f5dSRui Paulo } 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); 71*3340d773SGleb Smirnoff hdr = (const ipnet_hdr_t *)p; 7227df3f5dSRui Paulo p += sizeof(ipnet_hdr_t); 7327df3f5dSRui Paulo 7427df3f5dSRui Paulo switch (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) 86*3340d773SGleb 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 */ 10127df3f5dSRui Paulo u_int 1023c602fabSXin LI ipnet_if_print(netdissect_options *ndo, 10327df3f5dSRui Paulo const struct pcap_pkthdr *h, const u_char *p) 10427df3f5dSRui Paulo { 10527df3f5dSRui Paulo ipnet_print(ndo, p, h->len, h->caplen); 10627df3f5dSRui Paulo 10727df3f5dSRui Paulo return (sizeof(ipnet_hdr_t)); 10827df3f5dSRui Paulo } 10927df3f5dSRui Paulo 11027df3f5dSRui Paulo /* 11127df3f5dSRui Paulo * Local Variables: 11227df3f5dSRui Paulo * c-style: whitesmith 11327df3f5dSRui Paulo * c-basic-offset: 8 11427df3f5dSRui Paulo * End: 11527df3f5dSRui Paulo */ 11627df3f5dSRui Paulo 11727df3f5dSRui Paulo #endif /* DLT_IPNET */ 118