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