print-symantec.c revision 146773
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_ = 23146773Ssam "@(#) $Header: /tcpdump/master/tcpdump/print-symantec.c,v 1.4 2004/04/05 00:13:59 mcr 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" 36146773Ssam#include "addrtoname.h" 37146773Ssam#include "ethertype.h" 38146773Ssam 39146773Ssam#include "ether.h" 40146773Ssam 41146773Ssamstruct symantec_header { 42146773Ssam u_int8_t stuff1[6]; 43146773Ssam u_int16_t ether_type; 44146773Ssam u_int8_t stuff2[36]; 45146773Ssam}; 46146773Ssam 47146773Ssamstatic inline void 48146773Ssamsymantec_hdr_print(register const u_char *bp, u_int length) 49146773Ssam{ 50146773Ssam register const struct symantec_header *sp; 51146773Ssam u_int16_t etype; 52146773Ssam 53146773Ssam sp = (const struct symantec_header *)bp; 54146773Ssam 55146773Ssam etype = ntohs(sp->ether_type); 56146773Ssam if (!qflag) { 57146773Ssam if (etype <= ETHERMTU) 58146773Ssam (void)printf("invalid ethertype %u", etype); 59146773Ssam else 60146773Ssam (void)printf("ethertype %s (0x%04x)", 61146773Ssam tok2str(ethertype_values,"Unknown", etype), 62146773Ssam etype); 63146773Ssam } else { 64146773Ssam if (etype <= ETHERMTU) 65146773Ssam (void)printf("invalid ethertype %u", etype); 66146773Ssam else 67146773Ssam (void)printf("%s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", etype)); 68146773Ssam } 69146773Ssam 70146773Ssam (void)printf(", length %u: ", length); 71146773Ssam} 72146773Ssam 73146773Ssam/* 74146773Ssam * This is the top level routine of the printer. 'p' points 75146773Ssam * to the ether header of the packet, 'h->ts' is the timestamp, 76146773Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen' 77146773Ssam * is the number of bytes actually captured. 78146773Ssam */ 79146773Ssamu_int 80146773Ssamsymantec_if_print(const struct pcap_pkthdr *h, const u_char *p) 81146773Ssam{ 82146773Ssam u_int length = h->len; 83146773Ssam u_int caplen = h->caplen; 84146773Ssam struct symantec_header *sp; 85146773Ssam u_short ether_type; 86146773Ssam u_short extracted_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 101146773Ssam ether_type = ntohs(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 108146773Ssam if (!xflag && !qflag) 109146773Ssam default_print(p, caplen); 110146773Ssam } else if (ether_encap_print(ether_type, p, length, caplen, 111146773Ssam &extracted_ether_type) == 0) { 112146773Ssam /* ether_type not known, print raw packet */ 113146773Ssam if (!eflag) 114146773Ssam symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header)); 115146773Ssam 116146773Ssam if (!xflag && !qflag) 117146773Ssam default_print(p, caplen); 118146773Ssam } 119146773Ssam 120146773Ssam return (sizeof (struct symantec_header)); 121146773Ssam} 122