print-ipnet.c 2.5 KB

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