1b0453382SBill Fenner /* 2b0453382SBill Fenner * Marko Kiiskila carnil@cs.tut.fi 3b0453382SBill Fenner * 4b0453382SBill Fenner * Tampere University of Technology - Telecommunications Laboratory 5b0453382SBill Fenner * 6b0453382SBill Fenner * Permission to use, copy, modify and distribute this 7b0453382SBill Fenner * software and its documentation is hereby granted, 8b0453382SBill Fenner * provided that both the copyright notice and this 9b0453382SBill Fenner * permission notice appear in all copies of the software, 10b0453382SBill Fenner * derivative works or modified versions, and any portions 11b0453382SBill Fenner * thereof, that both notices appear in supporting 12b0453382SBill Fenner * documentation, and that the use of this software is 13b0453382SBill Fenner * acknowledged in any publications resulting from using 14b0453382SBill Fenner * the software. 15b0453382SBill Fenner * 16b0453382SBill Fenner * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17b0453382SBill Fenner * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR 18b0453382SBill Fenner * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS 19b0453382SBill Fenner * SOFTWARE. 20b0453382SBill Fenner * 21b0453382SBill Fenner */ 22b0453382SBill Fenner 23b0453382SBill Fenner #ifndef lint 24b0453382SBill Fenner static const char rcsid[] = 25b0453382SBill Fenner "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.2 1999/11/21 09:36:56 fenner Exp $ (LBL)"; 26b0453382SBill Fenner #endif 27b0453382SBill Fenner 28b0453382SBill Fenner #ifdef HAVE_CONFIG_H 29b0453382SBill Fenner #include "config.h" 30b0453382SBill Fenner #endif 31b0453382SBill Fenner 32b0453382SBill Fenner #include <sys/param.h> 33b0453382SBill Fenner #include <sys/time.h> 34b0453382SBill Fenner #include <sys/types.h> 35b0453382SBill Fenner #include <sys/socket.h> 36b0453382SBill Fenner 37b0453382SBill Fenner #include <net/if.h> 38b0453382SBill Fenner 39b0453382SBill Fenner #include <netinet/in.h> 40b0453382SBill Fenner #include <netinet/if_ether.h> 41b0453382SBill Fenner #include <netinet/in_systm.h> 42b0453382SBill Fenner #include <netinet/ip.h> 43b0453382SBill Fenner #include <netinet/ip_var.h> 44b0453382SBill Fenner #include <netinet/udp.h> 45b0453382SBill Fenner #include <netinet/udp_var.h> 46b0453382SBill Fenner #include <netinet/tcp.h> 47b0453382SBill Fenner #include <netinet/tcpip.h> 48b0453382SBill Fenner 49b0453382SBill Fenner #include <stdio.h> 50b0453382SBill Fenner #include <pcap.h> 51b0453382SBill Fenner 52b0453382SBill Fenner #include "interface.h" 53b0453382SBill Fenner #include "addrtoname.h" 54b0453382SBill Fenner #include "lane.h" 55b0453382SBill Fenner 56b0453382SBill Fenner static const u_char *packetp; 57b0453382SBill Fenner static const u_char *snapend; 58b0453382SBill Fenner 59b0453382SBill Fenner static inline void 60b0453382SBill Fenner lane_print(register const u_char *bp, int length) 61b0453382SBill Fenner { 62b0453382SBill Fenner register const struct lecdatahdr_8023 *ep; 63b0453382SBill Fenner 64b0453382SBill Fenner ep = (const struct lecdatahdr_8023 *)bp; 65b0453382SBill Fenner if (qflag) 66b0453382SBill Fenner (void)printf("lecid:%d %s %s %d: ", 67b0453382SBill Fenner ntohs(ep->le_header), 68b0453382SBill Fenner etheraddr_string(ep->h_source), 69b0453382SBill Fenner etheraddr_string(ep->h_dest), 70b0453382SBill Fenner length); 71b0453382SBill Fenner else 72b0453382SBill Fenner (void)printf("lecid:%d %s %s %s %d: ", 73b0453382SBill Fenner ntohs(ep->le_header), 74b0453382SBill Fenner etheraddr_string(ep->h_source), 75b0453382SBill Fenner etheraddr_string(ep->h_dest), 76b0453382SBill Fenner etherproto_string(ep->h_type), 77b0453382SBill Fenner length); 78b0453382SBill Fenner } 79b0453382SBill Fenner 80b0453382SBill Fenner /* 81b0453382SBill Fenner * This is the top level routine of the printer. 'p' is the points 82b0453382SBill Fenner * to the ether header of the packet, 'h->tv' is the timestamp, 83b0453382SBill Fenner * 'h->length' is the length of the packet off the wire, and 'h->caplen' 84b0453382SBill Fenner * is the number of bytes actually captured. 85b0453382SBill Fenner */ 86b0453382SBill Fenner void 87b0453382SBill Fenner lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 88b0453382SBill Fenner { 89b0453382SBill Fenner int caplen = h->caplen; 90b0453382SBill Fenner int length = h->len; 91b0453382SBill Fenner struct lecdatahdr_8023 *ep; 92b0453382SBill Fenner u_short ether_type; 93b0453382SBill Fenner u_short extracted_ethertype; 94b0453382SBill Fenner 95b0453382SBill Fenner ts_print(&h->ts); 96b0453382SBill Fenner 97b0453382SBill Fenner if (caplen < sizeof(struct lecdatahdr_8023)) { 98b0453382SBill Fenner printf("[|lane]"); 99b0453382SBill Fenner goto out; 100b0453382SBill Fenner } 101b0453382SBill Fenner 102b0453382SBill Fenner if (eflag) 103b0453382SBill Fenner lane_print(p, length); 104b0453382SBill Fenner 105b0453382SBill Fenner /* 106b0453382SBill Fenner * Some printers want to get back at the ethernet addresses, 107b0453382SBill Fenner * and/or check that they're not walking off the end of the packet. 108b0453382SBill Fenner * Rather than pass them all the way down, we set these globals. 109b0453382SBill Fenner */ 110b0453382SBill Fenner packetp = p; 111b0453382SBill Fenner snapend = p + caplen; 112b0453382SBill Fenner 113b0453382SBill Fenner length -= sizeof(struct lecdatahdr_8023); 114b0453382SBill Fenner caplen -= sizeof(struct lecdatahdr_8023); 115b0453382SBill Fenner ep = (struct lecdatahdr_8023 *)p; 116b0453382SBill Fenner p += sizeof(struct lecdatahdr_8023); 117b0453382SBill Fenner 118b0453382SBill Fenner ether_type = ntohs(ep->h_type); 119b0453382SBill Fenner 120b0453382SBill Fenner /* 121b0453382SBill Fenner * Is it (gag) an 802.3 encapsulation? 122b0453382SBill Fenner */ 123b0453382SBill Fenner extracted_ethertype = 0; 124b0453382SBill Fenner if (ether_type < ETHERMTU) { 125b0453382SBill Fenner /* Try to print the LLC-layer header & higher layers */ 126b0453382SBill Fenner if (llc_print(p, length, caplen, ep->h_source,ep->h_dest)==0) { 127b0453382SBill Fenner /* ether_type not known, print raw packet */ 128b0453382SBill Fenner if (!eflag) 129b0453382SBill Fenner lane_print((u_char *)ep, length); 130b0453382SBill Fenner if (extracted_ethertype) { 131b0453382SBill Fenner printf("(LLC %s) ", 132b0453382SBill Fenner etherproto_string(htons(extracted_ethertype))); 133b0453382SBill Fenner } 134b0453382SBill Fenner if (!xflag && !qflag) 135b0453382SBill Fenner default_print(p, caplen); 136b0453382SBill Fenner } 137b0453382SBill Fenner } else if (ether_encap_print(ether_type, p, length, caplen) == 0) { 138b0453382SBill Fenner /* ether_type not known, print raw packet */ 139b0453382SBill Fenner if (!eflag) 140b0453382SBill Fenner lane_print((u_char *)ep, length + sizeof(*ep)); 141b0453382SBill Fenner if (!xflag && !qflag) 142b0453382SBill Fenner default_print(p, caplen); 143b0453382SBill Fenner } 144b0453382SBill Fenner if (xflag) 145b0453382SBill Fenner default_print(p, caplen); 146b0453382SBill Fenner out: 147b0453382SBill Fenner putchar('\n'); 148b0453382SBill Fenner } 149