156893Sfenner/* 2127668Sbms * Marko Kiiskila carnil@cs.tut.fi 3127668Sbms * 456893Sfenner * Tampere University of Technology - Telecommunications Laboratory 556893Sfenner * 656893Sfenner * Permission to use, copy, modify and distribute this 756893Sfenner * software and its documentation is hereby granted, 856893Sfenner * provided that both the copyright notice and this 956893Sfenner * permission notice appear in all copies of the software, 1056893Sfenner * derivative works or modified versions, and any portions 1156893Sfenner * thereof, that both notices appear in supporting 1256893Sfenner * documentation, and that the use of this software is 1356893Sfenner * acknowledged in any publications resulting from using 1456893Sfenner * the software. 15127668Sbms * 1656893Sfenner * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 1756893Sfenner * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR 1856893Sfenner * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS 1956893Sfenner * SOFTWARE. 20127668Sbms * 2156893Sfenner */ 2256893Sfenner 2356893Sfenner#ifndef lint 24127668Sbmsstatic const char rcsid[] _U_ = 25190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.26 2005-07-07 01:22:17 guy Exp $ (LBL)"; 2656893Sfenner#endif 2756893Sfenner 2856893Sfenner#ifdef HAVE_CONFIG_H 2956893Sfenner#include "config.h" 3056893Sfenner#endif 3156893Sfenner 3298524Sfenner#include <string.h> 3398524Sfenner 34127668Sbms#include <tcpdump-stdinc.h> 3556893Sfenner 3656893Sfenner#include <stdio.h> 3756893Sfenner#include <pcap.h> 3856893Sfenner 3956893Sfenner#include "interface.h" 4056893Sfenner#include "addrtoname.h" 4175115Sfenner#include "ethertype.h" 4275115Sfenner#include "ether.h" 4356893Sfenner 44127668Sbms#define RFC1483LLC_LEN 8 4556893Sfenner 4656893Sfennerstatic unsigned char rfcllc[] = { 4775115Sfenner 0xaa, /* DSAP: non-ISO */ 4875115Sfenner 0xaa, /* SSAP: non-ISO */ 4975115Sfenner 0x03, /* Ctrl: Unnumbered Information Command PDU */ 5075115Sfenner 0x00, /* OUI: EtherType */ 5175115Sfenner 0x00, 5275115Sfenner 0x00 }; 5356893Sfenner 5456893Sfennerstatic inline void 55127668Sbmscip_print(int length) 5656893Sfenner{ 5798524Sfenner /* 5898524Sfenner * There is no MAC-layer header, so just print the length. 5998524Sfenner */ 6098524Sfenner printf("%d: ", length); 6156893Sfenner} 6256893Sfenner 6356893Sfenner/* 64127668Sbms * This is the top level routine of the printer. 'p' points 65127668Sbms * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp, 66146773Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen' 6756893Sfenner * is the number of bytes actually captured. 6856893Sfenner */ 69127668Sbmsu_int 70127668Sbmscip_if_print(const struct pcap_pkthdr *h, const u_char *p) 7156893Sfenner{ 7298524Sfenner u_int caplen = h->caplen; 7398524Sfenner u_int length = h->len; 7456893Sfenner u_short extracted_ethertype; 7556893Sfenner 7656893Sfenner if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) { 7756893Sfenner printf("[|cip]"); 78127668Sbms return (0); 7956893Sfenner } 8056893Sfenner 8156893Sfenner if (eflag) 82127668Sbms cip_print(length); 8356893Sfenner 8498524Sfenner if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) { 8598524Sfenner /* 8698524Sfenner * LLC header is present. Try to print it & higher layers. 8798524Sfenner */ 8875115Sfenner if (llc_print(p, length, caplen, NULL, NULL, 8998524Sfenner &extracted_ethertype) == 0) { 9056893Sfenner /* ether_type not known, print raw packet */ 9156893Sfenner if (!eflag) 92127668Sbms cip_print(length); 9356893Sfenner if (extracted_ethertype) { 9456893Sfenner printf("(LLC %s) ", 9556893Sfenner etherproto_string(htons(extracted_ethertype))); 9656893Sfenner } 97162017Ssam if (!suppress_default_print) 9856893Sfenner default_print(p, caplen); 9956893Sfenner } 10098524Sfenner } else { 10198524Sfenner /* 10298524Sfenner * LLC header is absent; treat it as just IP. 10398524Sfenner */ 104146773Ssam ip_print(gndo, p, length); 10556893Sfenner } 10698524Sfenner 107127668Sbms return (0); 10856893Sfenner} 109146773Ssam 110146773Ssam 111146773Ssam/* 112146773Ssam * Local Variables: 113146773Ssam * c-style: whitesmith 114146773Ssam * c-basic-offset: 8 115146773Ssam * End: 116146773Ssam */ 117