Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / tcpdump / print-lane.c
blob8815cfdd9adbadae46df43064fbcb1153a951084
1 /* $NetBSD$ */
3 /*
4 * Marko Kiiskila carnil@cs.tut.fi
6 * Tampere University of Technology - Telecommunications Laboratory
8 * Permission to use, copy, modify and distribute this
9 * software and its documentation is hereby granted,
10 * provided that both the copyright notice and this
11 * permission notice appear in all copies of the software,
12 * derivative works or modified versions, and any portions
13 * thereof, that both notices appear in supporting
14 * documentation, and that the use of this software is
15 * acknowledged in any publications resulting from using
16 * the software.
18 * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
19 * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
20 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
21 * SOFTWARE.
25 #include <sys/cdefs.h>
26 #ifndef lint
27 #if 0
28 static const char rcsid[] _U_ =
29 "@(#) Header: /tcpdump/master/tcpdump/print-lane.c,v 1.23.2.2 2005/11/13 12:12:59 guy Exp (LBL)";
30 #else
31 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
32 #endif
33 #endif
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
39 #include <tcpdump-stdinc.h>
41 #include <stdio.h>
42 #include <pcap.h>
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h"
47 #include "ether.h"
48 #include "lane.h"
50 static const struct tok lecop2str[] = {
51 { 0x0001, "configure request" },
52 { 0x0101, "configure response" },
53 { 0x0002, "join request" },
54 { 0x0102, "join response" },
55 { 0x0003, "ready query" },
56 { 0x0103, "ready indication" },
57 { 0x0004, "register request" },
58 { 0x0104, "register response" },
59 { 0x0005, "unregister request" },
60 { 0x0105, "unregister response" },
61 { 0x0006, "ARP request" },
62 { 0x0106, "ARP response" },
63 { 0x0007, "flush request" },
64 { 0x0107, "flush response" },
65 { 0x0008, "NARP request" },
66 { 0x0009, "topology request" },
67 { 0, NULL }
70 static inline void
71 lane_hdr_print(register const u_char *bp, int length)
73 register const struct lecdatahdr_8023 *ep;
75 ep = (const struct lecdatahdr_8023 *)bp;
76 if (qflag)
77 (void)printf("lecid:%x %s %s %d: ",
78 EXTRACT_16BITS(&ep->le_header),
79 etheraddr_string(ep->h_source),
80 etheraddr_string(ep->h_dest),
81 length);
82 else
83 (void)printf("lecid:%x %s %s %s %d: ",
84 EXTRACT_16BITS(&ep->le_header),
85 etheraddr_string(ep->h_source),
86 etheraddr_string(ep->h_dest),
87 etherproto_string(ep->h_type),
88 length);
92 * This is the top level routine of the printer. 'p' points
93 * to the LANE header of the packet, 'h->ts' is the timestamp,
94 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
95 * is the number of bytes actually captured.
97 * This assumes 802.3, not 802.5, LAN emulation.
99 void
100 lane_print(const u_char *p, u_int length, u_int caplen)
102 struct lane_controlhdr *lec;
103 struct lecdatahdr_8023 *ep;
104 u_short ether_type;
105 u_short extracted_ethertype;
107 if (caplen < sizeof(struct lane_controlhdr)) {
108 printf("[|lane]");
109 return;
112 lec = (struct lane_controlhdr *)p;
113 if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) {
115 * LE Control.
117 printf("lec: proto %x vers %x %s",
118 lec->lec_proto, lec->lec_vers,
119 tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode)));
120 return;
123 if (caplen < sizeof(struct lecdatahdr_8023)) {
124 printf("[|lane]");
125 return;
128 if (eflag)
129 lane_hdr_print(p, length);
132 * Go past the LANE header.
134 length -= sizeof(struct lecdatahdr_8023);
135 caplen -= sizeof(struct lecdatahdr_8023);
136 ep = (struct lecdatahdr_8023 *)p;
137 p += sizeof(struct lecdatahdr_8023);
139 ether_type = EXTRACT_16BITS(&ep->h_type);
142 * Is it (gag) an 802.3 encapsulation?
144 if (ether_type <= ETHERMTU) {
145 /* Try to print the LLC-layer header & higher layers */
146 if (llc_print(p, length, caplen, ep->h_source, ep->h_dest,
147 &extracted_ethertype) == 0) {
148 /* ether_type not known, print raw packet */
149 if (!eflag)
150 lane_hdr_print((u_char *)ep, length + sizeof(*ep));
151 if (extracted_ethertype) {
152 printf("(LLC %s) ",
153 etherproto_string(htons(extracted_ethertype)));
155 if (!suppress_default_print)
156 default_print(p, caplen);
158 } else if (ether_encap_print(ether_type, p, length, caplen,
159 &extracted_ethertype) == 0) {
160 /* ether_type not known, print raw packet */
161 if (!eflag)
162 lane_hdr_print((u_char *)ep, length + sizeof(*ep));
163 if (!suppress_default_print)
164 default_print(p, caplen);
168 u_int
169 lane_if_print(const struct pcap_pkthdr *h, const u_char *p)
171 lane_print(p, h->len, h->caplen);
173 return (sizeof(struct lecdatahdr_8023));