print-symantec.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. */
  21. /* \summary: Symantec Enterprise Firewall printer */
  22. #ifdef HAVE_CONFIG_H
  23. #include "config.h"
  24. #endif
  25. #include <netdissect-stdinc.h>
  26. #include "netdissect.h"
  27. #include "extract.h"
  28. #include "ethertype.h"
  29. #include "ether.h"
  30. struct symantec_header {
  31. uint8_t stuff1[6];
  32. uint16_t ether_type;
  33. uint8_t stuff2[36];
  34. };
  35. static inline void
  36. symantec_hdr_print(netdissect_options *ndo, register const u_char *bp, u_int length)
  37. {
  38. register const struct symantec_header *sp;
  39. uint16_t etype;
  40. sp = (const struct symantec_header *)bp;
  41. etype = EXTRACT_16BITS(&sp->ether_type);
  42. if (!ndo->ndo_qflag) {
  43. if (etype <= ETHERMTU)
  44. ND_PRINT((ndo, "invalid ethertype %u", etype));
  45. else
  46. ND_PRINT((ndo, "ethertype %s (0x%04x)",
  47. tok2str(ethertype_values,"Unknown", etype),
  48. etype));
  49. } else {
  50. if (etype <= ETHERMTU)
  51. ND_PRINT((ndo, "invalid ethertype %u", etype));
  52. else
  53. ND_PRINT((ndo, "%s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", etype)));
  54. }
  55. ND_PRINT((ndo, ", length %u: ", length));
  56. }
  57. /*
  58. * This is the top level routine of the printer. 'p' points
  59. * to the ether header of the packet, 'h->ts' is the timestamp,
  60. * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  61. * is the number of bytes actually captured.
  62. */
  63. u_int
  64. symantec_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
  65. {
  66. u_int length = h->len;
  67. u_int caplen = h->caplen;
  68. const struct symantec_header *sp;
  69. u_short ether_type;
  70. if (caplen < sizeof (struct symantec_header)) {
  71. ND_PRINT((ndo, "[|symantec]"));
  72. return caplen;
  73. }
  74. if (ndo->ndo_eflag)
  75. symantec_hdr_print(ndo, p, length);
  76. length -= sizeof (struct symantec_header);
  77. caplen -= sizeof (struct symantec_header);
  78. sp = (const struct symantec_header *)p;
  79. p += sizeof (struct symantec_header);
  80. ether_type = EXTRACT_16BITS(&sp->ether_type);
  81. if (ether_type <= ETHERMTU) {
  82. /* ether_type not known, print raw packet */
  83. if (!ndo->ndo_eflag)
  84. symantec_hdr_print(ndo, (const u_char *)sp, length + sizeof (struct symantec_header));
  85. if (!ndo->ndo_suppress_default_print)
  86. ND_DEFAULTPRINT(p, caplen);
  87. } else if (ethertype_print(ndo, ether_type, p, length, caplen, NULL, NULL) == 0) {
  88. /* ether_type not known, print raw packet */
  89. if (!ndo->ndo_eflag)
  90. symantec_hdr_print(ndo, (const u_char *)sp, length + sizeof (struct symantec_header));
  91. if (!ndo->ndo_suppress_default_print)
  92. ND_DEFAULTPRINT(p, caplen);
  93. }
  94. return (sizeof (struct symantec_header));
  95. }