print-symantec.c revision 162017
178344Sobrien/*
298184Sgordon * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
378344Sobrien *	The Regents of the University of California.  All rights reserved.
4118224Smtm *
5118224Smtm * Redistribution and use in source and binary forms, with or without
6123533Sseanc * modification, are permitted provided that: (1) source code distributions
7145184Sglebius * retain the above copyright notice and this paragraph in its entirety, (2)
8118224Smtm * distributions including binary code include the above copyright notice and
9127345Sbrooks * this paragraph in its entirety in the documentation or other materials
10118224Smtm * provided with the distribution, and (3) all advertising materials mentioning
11148760Spjd * features or use of this software display the following acknowledgement:
12118224Smtm * ``This product includes software developed by the University of California,
13149053Spjd * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14151245Semax * the University nor the names of its contributors may be used to endorse
15118224Smtm * or promote products derived from this software without specific prior
16126618Sbms * written permission.
17145693Sbrooks * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18121749Sume * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19118224Smtm * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20118224Smtm */
21116223Sbde#ifndef lint
22143489Sdougbstatic const char rcsid[] _U_ =
23127043Sjhb    "@(#) $Header: /tcpdump/master/tcpdump/print-symantec.c,v 1.4.2.1 2005/07/07 01:24:39 guy Exp $ (LBL)";
24116223Sbde#endif
25127897Sfjoe
26142962Sbrooks#ifdef HAVE_CONFIG_H
27135252Sseanc#include "config.h"
28118224Smtm#endif
29150835Syar
30145693Sbrooks#include <tcpdump-stdinc.h>
31118224Smtm
32137762Swes#include <stdio.h>
33118224Smtm#include <pcap.h>
34151245Semax
35150490Swollman#include "interface.h"
36118224Smtm#include "addrtoname.h"
37127345Sbrooks#include "ethertype.h"
38135912Strhodes
39137203Sphk#include "ether.h"
40147682Sbrooks
41118224Smtmstruct symantec_header {
42118224Smtm	u_int8_t  stuff1[6];
43150490Swollman	u_int16_t ether_type;
44150490Swollman	u_int8_t  stuff2[36];
45150490Swollman};
46150490Swollman
47150490Swollmanstatic inline void
4878344Sobriensymantec_hdr_print(register const u_char *bp, u_int length)
4978344Sobrien{
5078344Sobrien	register const struct symantec_header *sp;
5178344Sobrien	u_int16_t etype;
52
53	sp = (const struct symantec_header *)bp;
54
55	etype = ntohs(sp->ether_type);
56	if (!qflag) {
57	        if (etype <= ETHERMTU)
58		          (void)printf("invalid ethertype %u", etype);
59                else
60		          (void)printf("ethertype %s (0x%04x)",
61				       tok2str(ethertype_values,"Unknown", etype),
62                                       etype);
63        } else {
64                if (etype <= ETHERMTU)
65                          (void)printf("invalid ethertype %u", etype);
66                else
67                          (void)printf("%s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", etype));
68        }
69
70	(void)printf(", length %u: ", length);
71}
72
73/*
74 * This is the top level routine of the printer.  'p' points
75 * to the ether header of the packet, 'h->ts' is the timestamp,
76 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
77 * is the number of bytes actually captured.
78 */
79u_int
80symantec_if_print(const struct pcap_pkthdr *h, const u_char *p)
81{
82	u_int length = h->len;
83	u_int caplen = h->caplen;
84	struct symantec_header *sp;
85	u_short ether_type;
86	u_short extracted_ether_type;
87
88	if (caplen < sizeof (struct symantec_header)) {
89		printf("[|symantec]");
90		return caplen;
91	}
92
93	if (eflag)
94		symantec_hdr_print(p, length);
95
96	length -= sizeof (struct symantec_header);
97	caplen -= sizeof (struct symantec_header);
98	sp = (struct symantec_header *)p;
99	p += sizeof (struct symantec_header);
100
101	ether_type = ntohs(sp->ether_type);
102
103	if (ether_type <= ETHERMTU) {
104		/* ether_type not known, print raw packet */
105		if (!eflag)
106			symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header));
107
108		if (!suppress_default_print)
109			default_print(p, caplen);
110	} else if (ether_encap_print(ether_type, p, length, caplen,
111	    &extracted_ether_type) == 0) {
112		/* ether_type not known, print raw packet */
113		if (!eflag)
114			symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header));
115
116		if (!suppress_default_print)
117			default_print(p, caplen);
118	}
119
120	return (sizeof (struct symantec_header));
121}
122