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 245b0fe478SBruce M Simpson static const char rcsid[] _U_ = 255b0fe478SBruce M Simpson "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.20.2.2 2003/11/16 08:51:31 guy Exp $ (LBL)"; 26b0453382SBill Fenner #endif 27b0453382SBill Fenner 28b0453382SBill Fenner #ifdef HAVE_CONFIG_H 29b0453382SBill Fenner #include "config.h" 30b0453382SBill Fenner #endif 31b0453382SBill Fenner 325b0fe478SBruce M Simpson #include <tcpdump-stdinc.h> 33b0453382SBill Fenner 34b0453382SBill Fenner #include <stdio.h> 35b0453382SBill Fenner #include <pcap.h> 36b0453382SBill Fenner 37b0453382SBill Fenner #include "interface.h" 38b0453382SBill Fenner #include "addrtoname.h" 395b0fe478SBruce M Simpson #include "extract.h" 40685295f4SBill Fenner #include "ether.h" 41b0453382SBill Fenner #include "lane.h" 42b0453382SBill Fenner 435b0fe478SBruce M Simpson static const struct tok lecop2str[] = { 445b0fe478SBruce M Simpson { 0x0001, "configure request" }, 455b0fe478SBruce M Simpson { 0x0101, "configure response" }, 465b0fe478SBruce M Simpson { 0x0002, "join request" }, 475b0fe478SBruce M Simpson { 0x0102, "join response" }, 485b0fe478SBruce M Simpson { 0x0003, "ready query" }, 495b0fe478SBruce M Simpson { 0x0103, "ready indication" }, 505b0fe478SBruce M Simpson { 0x0004, "register request" }, 515b0fe478SBruce M Simpson { 0x0104, "register response" }, 525b0fe478SBruce M Simpson { 0x0005, "unregister request" }, 535b0fe478SBruce M Simpson { 0x0105, "unregister response" }, 545b0fe478SBruce M Simpson { 0x0006, "ARP request" }, 555b0fe478SBruce M Simpson { 0x0106, "ARP response" }, 565b0fe478SBruce M Simpson { 0x0007, "flush request" }, 575b0fe478SBruce M Simpson { 0x0107, "flush response" }, 585b0fe478SBruce M Simpson { 0x0008, "NARP request" }, 595b0fe478SBruce M Simpson { 0x0009, "topology request" }, 605b0fe478SBruce M Simpson { 0, NULL } 615b0fe478SBruce M Simpson }; 625b0fe478SBruce M Simpson 63b0453382SBill Fenner static inline void 645b0fe478SBruce M Simpson lane_hdr_print(register const u_char *bp, int length) 65b0453382SBill Fenner { 66b0453382SBill Fenner register const struct lecdatahdr_8023 *ep; 67b0453382SBill Fenner 68b0453382SBill Fenner ep = (const struct lecdatahdr_8023 *)bp; 69b0453382SBill Fenner if (qflag) 705b0fe478SBruce M Simpson (void)printf("lecid:%x %s %s %d: ", 715b0fe478SBruce M Simpson EXTRACT_16BITS(&ep->le_header), 72b0453382SBill Fenner etheraddr_string(ep->h_source), 73b0453382SBill Fenner etheraddr_string(ep->h_dest), 74b0453382SBill Fenner length); 75b0453382SBill Fenner else 765b0fe478SBruce M Simpson (void)printf("lecid:%x %s %s %s %d: ", 775b0fe478SBruce M Simpson EXTRACT_16BITS(&ep->le_header), 78b0453382SBill Fenner etheraddr_string(ep->h_source), 79b0453382SBill Fenner etheraddr_string(ep->h_dest), 80b0453382SBill Fenner etherproto_string(ep->h_type), 81b0453382SBill Fenner length); 82b0453382SBill Fenner } 83b0453382SBill Fenner 84b0453382SBill Fenner /* 855b0fe478SBruce M Simpson * This is the top level routine of the printer. 'p' points 865b0fe478SBruce M Simpson * to the LANE header of the packet, 'h->ts' is the timestamp, 87b0453382SBill Fenner * 'h->length' is the length of the packet off the wire, and 'h->caplen' 88b0453382SBill Fenner * is the number of bytes actually captured. 895b0fe478SBruce M Simpson * 905b0fe478SBruce M Simpson * This assumes 802.3, not 802.5, LAN emulation. 91b0453382SBill Fenner */ 92b0453382SBill Fenner void 935b0fe478SBruce M Simpson lane_print(const u_char *p, u_int length, u_int caplen) 94b0453382SBill Fenner { 955b0fe478SBruce M Simpson struct lane_controlhdr *lec; 96b0453382SBill Fenner struct lecdatahdr_8023 *ep; 97b0453382SBill Fenner u_short ether_type; 98b0453382SBill Fenner u_short extracted_ethertype; 99b0453382SBill Fenner 1005b0fe478SBruce M Simpson if (caplen < sizeof(struct lane_controlhdr)) { 1015b0fe478SBruce M Simpson printf("[|lane]"); 1025b0fe478SBruce M Simpson return; 1035b0fe478SBruce M Simpson } 1045b0fe478SBruce M Simpson 1055b0fe478SBruce M Simpson lec = (struct lane_controlhdr *)p; 1065b0fe478SBruce M Simpson if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) { 1075b0fe478SBruce M Simpson /* 1085b0fe478SBruce M Simpson * LE Control. 1095b0fe478SBruce M Simpson */ 1105b0fe478SBruce M Simpson printf("lec: proto %x vers %x %s", 1115b0fe478SBruce M Simpson lec->lec_proto, lec->lec_vers, 1125b0fe478SBruce M Simpson tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode))); 1135b0fe478SBruce M Simpson return; 1145b0fe478SBruce M Simpson } 115b0453382SBill Fenner 116b0453382SBill Fenner if (caplen < sizeof(struct lecdatahdr_8023)) { 117b0453382SBill Fenner printf("[|lane]"); 1185b0fe478SBruce M Simpson return; 119b0453382SBill Fenner } 120b0453382SBill Fenner 121b0453382SBill Fenner if (eflag) 1225b0fe478SBruce M Simpson lane_hdr_print(p, length); 123b0453382SBill Fenner 124b0453382SBill Fenner /* 1255b0fe478SBruce M Simpson * Go past the LANE header. 126b0453382SBill Fenner */ 127b0453382SBill Fenner length -= sizeof(struct lecdatahdr_8023); 128b0453382SBill Fenner caplen -= sizeof(struct lecdatahdr_8023); 129b0453382SBill Fenner ep = (struct lecdatahdr_8023 *)p; 130b0453382SBill Fenner p += sizeof(struct lecdatahdr_8023); 131b0453382SBill Fenner 1325b0fe478SBruce M Simpson ether_type = EXTRACT_16BITS(&ep->h_type); 133b0453382SBill Fenner 134b0453382SBill Fenner /* 135b0453382SBill Fenner * Is it (gag) an 802.3 encapsulation? 136b0453382SBill Fenner */ 137b0453382SBill Fenner extracted_ethertype = 0; 1385b0fe478SBruce M Simpson if (ether_type <= ETHERMTU) { 139b0453382SBill Fenner /* Try to print the LLC-layer header & higher layers */ 140685295f4SBill Fenner if (llc_print(p, length, caplen, ep->h_source, ep->h_dest, 141685295f4SBill Fenner &extracted_ethertype) == 0) { 142b0453382SBill Fenner /* ether_type not known, print raw packet */ 143b0453382SBill Fenner if (!eflag) 1445b0fe478SBruce M Simpson lane_hdr_print((u_char *)ep, length + sizeof(*ep)); 145b0453382SBill Fenner if (extracted_ethertype) { 146b0453382SBill Fenner printf("(LLC %s) ", 147b0453382SBill Fenner etherproto_string(htons(extracted_ethertype))); 148b0453382SBill Fenner } 149b0453382SBill Fenner if (!xflag && !qflag) 150b0453382SBill Fenner default_print(p, caplen); 151b0453382SBill Fenner } 152685295f4SBill Fenner } else if (ether_encap_print(ether_type, p, length, caplen, 153685295f4SBill Fenner &extracted_ethertype) == 0) { 154b0453382SBill Fenner /* ether_type not known, print raw packet */ 155b0453382SBill Fenner if (!eflag) 1565b0fe478SBruce M Simpson lane_hdr_print((u_char *)ep, length + sizeof(*ep)); 157b0453382SBill Fenner if (!xflag && !qflag) 158b0453382SBill Fenner default_print(p, caplen); 159b0453382SBill Fenner } 1605b0fe478SBruce M Simpson } 1615b0fe478SBruce M Simpson 1625b0fe478SBruce M Simpson u_int 1635b0fe478SBruce M Simpson lane_if_print(const struct pcap_pkthdr *h, const u_char *p) 1645b0fe478SBruce M Simpson { 1655b0fe478SBruce M Simpson lane_print(p, h->len, h->caplen); 1665b0fe478SBruce M Simpson 1675b0fe478SBruce M Simpson return (sizeof(struct lecdatahdr_8023)); 168b0453382SBill Fenner } 169