1146773Ssam/*
2146773Ssam * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3146773Ssam *	The Regents of the University of California.  All rights reserved.
4146773Ssam *
5146773Ssam * Redistribution and use in source and binary forms, with or without
6146773Ssam * modification, are permitted provided that: (1) source code distributions
7146773Ssam * retain the above copyright notice and this paragraph in its entirety, (2)
8146773Ssam * distributions including binary code include the above copyright notice and
9146773Ssam * this paragraph in its entirety in the documentation or other materials
10146773Ssam * provided with the distribution, and (3) all advertising materials mentioning
11146773Ssam * features or use of this software display the following acknowledgement:
12146773Ssam * ``This product includes software developed by the University of California,
13146773Ssam * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14146773Ssam * the University nor the names of its contributors may be used to endorse
15146773Ssam * or promote products derived from this software without specific prior
16146773Ssam * written permission.
17146773Ssam * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18146773Ssam * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19146773Ssam * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20146773Ssam */
21146773Ssam#ifndef lint
22146773Ssamstatic const char rcsid[] _U_ =
23190207Srpaulo    "@(#) $Header: /tcpdump/master/tcpdump/print-symantec.c,v 1.5 2005-07-07 01:22:21 guy Exp $ (LBL)";
24146773Ssam#endif
25146773Ssam
26146773Ssam#ifdef HAVE_CONFIG_H
27146773Ssam#include "config.h"
28146773Ssam#endif
29146773Ssam
30146773Ssam#include <tcpdump-stdinc.h>
31146773Ssam
32146773Ssam#include <stdio.h>
33146773Ssam#include <pcap.h>
34146773Ssam
35146773Ssam#include "interface.h"
36214478Srpaulo#include "extract.h"
37146773Ssam#include "addrtoname.h"
38146773Ssam#include "ethertype.h"
39146773Ssam
40146773Ssam#include "ether.h"
41146773Ssam
42146773Ssamstruct symantec_header {
43146773Ssam	u_int8_t  stuff1[6];
44146773Ssam	u_int16_t ether_type;
45146773Ssam	u_int8_t  stuff2[36];
46146773Ssam};
47146773Ssam
48146773Ssamstatic inline void
49146773Ssamsymantec_hdr_print(register const u_char *bp, u_int length)
50146773Ssam{
51146773Ssam	register const struct symantec_header *sp;
52146773Ssam	u_int16_t etype;
53146773Ssam
54146773Ssam	sp = (const struct symantec_header *)bp;
55146773Ssam
56214478Srpaulo	etype = EXTRACT_16BITS(&sp->ether_type);
57146773Ssam	if (!qflag) {
58146773Ssam	        if (etype <= ETHERMTU)
59146773Ssam		          (void)printf("invalid ethertype %u", etype);
60146773Ssam                else
61146773Ssam		          (void)printf("ethertype %s (0x%04x)",
62146773Ssam				       tok2str(ethertype_values,"Unknown", etype),
63146773Ssam                                       etype);
64146773Ssam        } else {
65146773Ssam                if (etype <= ETHERMTU)
66146773Ssam                          (void)printf("invalid ethertype %u", etype);
67146773Ssam                else
68146773Ssam                          (void)printf("%s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", etype));
69146773Ssam        }
70146773Ssam
71146773Ssam	(void)printf(", length %u: ", length);
72146773Ssam}
73146773Ssam
74146773Ssam/*
75146773Ssam * This is the top level routine of the printer.  'p' points
76146773Ssam * to the ether header of the packet, 'h->ts' is the timestamp,
77146773Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen'
78146773Ssam * is the number of bytes actually captured.
79146773Ssam */
80146773Ssamu_int
81146773Ssamsymantec_if_print(const struct pcap_pkthdr *h, const u_char *p)
82146773Ssam{
83146773Ssam	u_int length = h->len;
84146773Ssam	u_int caplen = h->caplen;
85146773Ssam	struct symantec_header *sp;
86146773Ssam	u_short ether_type;
87146773Ssam
88146773Ssam	if (caplen < sizeof (struct symantec_header)) {
89146773Ssam		printf("[|symantec]");
90146773Ssam		return caplen;
91146773Ssam	}
92146773Ssam
93146773Ssam	if (eflag)
94146773Ssam		symantec_hdr_print(p, length);
95146773Ssam
96146773Ssam	length -= sizeof (struct symantec_header);
97146773Ssam	caplen -= sizeof (struct symantec_header);
98146773Ssam	sp = (struct symantec_header *)p;
99146773Ssam	p += sizeof (struct symantec_header);
100146773Ssam
101214478Srpaulo	ether_type = EXTRACT_16BITS(&sp->ether_type);
102146773Ssam
103146773Ssam	if (ether_type <= ETHERMTU) {
104146773Ssam		/* ether_type not known, print raw packet */
105146773Ssam		if (!eflag)
106146773Ssam			symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header));
107146773Ssam
108162017Ssam		if (!suppress_default_print)
109146773Ssam			default_print(p, caplen);
110235530Sdelphij	} else if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
111146773Ssam		/* ether_type not known, print raw packet */
112146773Ssam		if (!eflag)
113146773Ssam			symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header));
114146773Ssam
115162017Ssam		if (!suppress_default_print)
116146773Ssam			default_print(p, caplen);
117146773Ssam	}
118146773Ssam
119146773Ssam	return (sizeof (struct symantec_header));
120146773Ssam}
121