print-ppi.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Oracle
  3. */
  4. /* \summary: Oracle DLT_PPI printer */
  5. #ifdef HAVE_CONFIG_H
  6. #include "config.h"
  7. #endif
  8. #include <netdissect-stdinc.h>
  9. #include "netdissect.h"
  10. #include "extract.h"
  11. typedef struct ppi_header {
  12. uint8_t ppi_ver;
  13. uint8_t ppi_flags;
  14. uint16_t ppi_len;
  15. uint32_t ppi_dlt;
  16. } ppi_header_t;
  17. #define PPI_HDRLEN 8
  18. #ifdef DLT_PPI
  19. static inline void
  20. ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
  21. {
  22. const ppi_header_t *hdr;
  23. uint16_t len;
  24. uint32_t dlt;
  25. const char *dltname;
  26. hdr = (const ppi_header_t *)bp;
  27. len = EXTRACT_LE_16BITS(&hdr->ppi_len);
  28. dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
  29. dltname = pcap_datalink_val_to_name(dlt);
  30. if (!ndo->ndo_qflag) {
  31. ND_PRINT((ndo, "V.%d DLT %s (%d) len %d", hdr->ppi_ver,
  32. (dltname != NULL ? dltname : "UNKNOWN"), dlt,
  33. len));
  34. } else {
  35. ND_PRINT((ndo, "%s", (dltname != NULL ? dltname : "UNKNOWN")));
  36. }
  37. ND_PRINT((ndo, ", length %u: ", length));
  38. }
  39. static u_int
  40. ppi_print(netdissect_options *ndo,
  41. const struct pcap_pkthdr *h, const u_char *p)
  42. {
  43. if_printer printer;
  44. const ppi_header_t *hdr;
  45. u_int caplen = h->caplen;
  46. u_int length = h->len;
  47. uint16_t len;
  48. uint32_t dlt;
  49. uint32_t hdrlen;
  50. struct pcap_pkthdr nhdr;
  51. if (caplen < sizeof(ppi_header_t)) {
  52. ND_PRINT((ndo, "[|ppi]"));
  53. return (caplen);
  54. }
  55. hdr = (const ppi_header_t *)p;
  56. len = EXTRACT_LE_16BITS(&hdr->ppi_len);
  57. if (caplen < len) {
  58. /*
  59. * If we don't have the entire PPI header, don't
  60. * bother.
  61. */
  62. ND_PRINT((ndo, "[|ppi]"));
  63. return (caplen);
  64. }
  65. if (len < sizeof(ppi_header_t)) {
  66. ND_PRINT((ndo, "[|ppi]"));
  67. return (len);
  68. }
  69. dlt = EXTRACT_LE_32BITS(&hdr->ppi_dlt);
  70. if (ndo->ndo_eflag)
  71. ppi_header_print(ndo, p, length);
  72. length -= len;
  73. caplen -= len;
  74. p += len;
  75. if ((printer = lookup_printer(dlt)) != NULL) {
  76. nhdr = *h;
  77. nhdr.caplen = caplen;
  78. nhdr.len = length;
  79. hdrlen = printer(ndo, &nhdr, p);
  80. } else {
  81. if (!ndo->ndo_eflag)
  82. ppi_header_print(ndo, (const u_char *)hdr, length + len);
  83. if (!ndo->ndo_suppress_default_print)
  84. ND_DEFAULTPRINT(p, caplen);
  85. hdrlen = 0;
  86. }
  87. return (len + hdrlen);
  88. }
  89. /*
  90. * This is the top level routine of the printer. 'p' points
  91. * to the ether header of the packet, 'h->ts' is the timestamp,
  92. * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  93. * is the number of bytes actually captured.
  94. */
  95. u_int
  96. ppi_if_print(netdissect_options *ndo,
  97. const struct pcap_pkthdr *h, const u_char *p)
  98. {
  99. return (ppi_print(ndo, h, p));
  100. }
  101. /*
  102. * Local Variables:
  103. * c-style: whitesmith
  104. * c-basic-offset: 8
  105. * End:
  106. */
  107. #endif /* DLT_PPI */