print-cip.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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: Classical-IP over ATM printer */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <string.h>
  27. #include <netdissect-stdinc.h>
  28. #include "netdissect.h"
  29. #include "addrtoname.h"
  30. static const unsigned char rfcllc[] = {
  31. 0xaa, /* DSAP: non-ISO */
  32. 0xaa, /* SSAP: non-ISO */
  33. 0x03, /* Ctrl: Unnumbered Information Command PDU */
  34. 0x00, /* OUI: EtherType */
  35. 0x00,
  36. 0x00 };
  37. static inline void
  38. cip_print(netdissect_options *ndo, u_int length)
  39. {
  40. /*
  41. * There is no MAC-layer header, so just print the length.
  42. */
  43. ND_PRINT((ndo, "%u: ", length));
  44. }
  45. /*
  46. * This is the top level routine of the printer. 'p' points
  47. * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
  48. * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  49. * is the number of bytes actually captured.
  50. */
  51. u_int
  52. cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
  53. {
  54. u_int caplen = h->caplen;
  55. u_int length = h->len;
  56. size_t cmplen;
  57. int llc_hdrlen;
  58. cmplen = sizeof(rfcllc);
  59. if (cmplen > caplen)
  60. cmplen = caplen;
  61. if (cmplen > length)
  62. cmplen = length;
  63. if (ndo->ndo_eflag)
  64. cip_print(ndo, length);
  65. if (cmplen == 0) {
  66. ND_PRINT((ndo, "[|cip]"));
  67. return 0;
  68. }
  69. if (memcmp(rfcllc, p, cmplen) == 0) {
  70. /*
  71. * LLC header is present. Try to print it & higher layers.
  72. */
  73. llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
  74. if (llc_hdrlen < 0) {
  75. /* packet type not known, print raw packet */
  76. if (!ndo->ndo_suppress_default_print)
  77. ND_DEFAULTPRINT(p, caplen);
  78. llc_hdrlen = -llc_hdrlen;
  79. }
  80. } else {
  81. /*
  82. * LLC header is absent; treat it as just IP.
  83. */
  84. llc_hdrlen = 0;
  85. ip_print(ndo, p, length);
  86. }
  87. return (llc_hdrlen);
  88. }
  89. /*
  90. * Local Variables:
  91. * c-style: whitesmith
  92. * c-basic-offset: 8
  93. * End:
  94. */