print-lane.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Marko Kiiskila carnil@cs.tut.fi
  3. *
  4. * Tampere University of Technology - Telecommunications Laboratory
  5. *
  6. * Permission to use, copy, modify and distribute this
  7. * software and its documentation is hereby granted,
  8. * provided that both the copyright notice and this
  9. * permission notice appear in all copies of the software,
  10. * derivative works or modified versions, and any portions
  11. * thereof, that both notices appear in supporting
  12. * documentation, and that the use of this software is
  13. * acknowledged in any publications resulting from using
  14. * the software.
  15. *
  16. * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  17. * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  18. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
  19. * SOFTWARE.
  20. *
  21. */
  22. /* \summary: ATM LANE printer */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <netdissect-stdinc.h>
  27. #include "netdissect.h"
  28. #include "extract.h"
  29. #include "ether.h"
  30. struct lecdatahdr_8023 {
  31. uint16_t le_header;
  32. uint8_t h_dest[ETHER_ADDR_LEN];
  33. uint8_t h_source[ETHER_ADDR_LEN];
  34. uint16_t h_type;
  35. };
  36. struct lane_controlhdr {
  37. uint16_t lec_header;
  38. uint8_t lec_proto;
  39. uint8_t lec_vers;
  40. uint16_t lec_opcode;
  41. };
  42. static const struct tok lecop2str[] = {
  43. { 0x0001, "configure request" },
  44. { 0x0101, "configure response" },
  45. { 0x0002, "join request" },
  46. { 0x0102, "join response" },
  47. { 0x0003, "ready query" },
  48. { 0x0103, "ready indication" },
  49. { 0x0004, "register request" },
  50. { 0x0104, "register response" },
  51. { 0x0005, "unregister request" },
  52. { 0x0105, "unregister response" },
  53. { 0x0006, "ARP request" },
  54. { 0x0106, "ARP response" },
  55. { 0x0007, "flush request" },
  56. { 0x0107, "flush response" },
  57. { 0x0008, "NARP request" },
  58. { 0x0009, "topology request" },
  59. { 0, NULL }
  60. };
  61. static void
  62. lane_hdr_print(netdissect_options *ndo, const u_char *bp)
  63. {
  64. ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp)));
  65. }
  66. /*
  67. * This is the top level routine of the printer. 'p' points
  68. * to the LANE header of the packet, 'h->ts' is the timestamp,
  69. * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  70. * is the number of bytes actually captured.
  71. *
  72. * This assumes 802.3, not 802.5, LAN emulation.
  73. */
  74. void
  75. lane_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
  76. {
  77. const struct lane_controlhdr *lec;
  78. if (caplen < sizeof(struct lane_controlhdr)) {
  79. ND_PRINT((ndo, "[|lane]"));
  80. return;
  81. }
  82. lec = (const struct lane_controlhdr *)p;
  83. if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) {
  84. /*
  85. * LE Control.
  86. */
  87. ND_PRINT((ndo, "lec: proto %x vers %x %s",
  88. lec->lec_proto, lec->lec_vers,
  89. tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode))));
  90. return;
  91. }
  92. /*
  93. * Go past the LE header.
  94. */
  95. length -= 2;
  96. caplen -= 2;
  97. p += 2;
  98. /*
  99. * Now print the encapsulated frame, under the assumption
  100. * that it's an Ethernet frame.
  101. */
  102. ether_print(ndo, p, length, caplen, lane_hdr_print, p - 2);
  103. }
  104. u_int
  105. lane_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
  106. {
  107. lane_print(ndo, p, h->len, h->caplen);
  108. return (sizeof(struct lecdatahdr_8023));
  109. }