2 * Marko Kiiskila carnil@cs.tut.fi
4 * Tampere University of Technology - Telecommunications Laboratory
6 * Permission to use, copy, modify and distribute this
7 * software and its documentation is hereby granted,
8 * provided that both the copyright notice and this
9 * permission notice appear in all copies of the software,
10 * derivative works or modified versions, and any portions
11 * thereof, that both notices appear in supporting
12 * documentation, and that the use of this software is
13 * acknowledged in any publications resulting from using
16 * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
24 static const char rcsid
[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.16 2002-09-05 21:25:43 guy Exp $ (LBL)";
32 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
42 static const struct tok lecop2str
[] = {
43 { 0x0001, "configure request" },
44 { 0x0101, "configure response" },
45 { 0x0002, "join request" },
46 { 0x0102, "join response" },
47 { 0x0003, "ready query" },
48 { 0x0103, "ready indication" },
49 { 0x0004, "register request" },
50 { 0x0104, "register response" },
51 { 0x0005, "unregister request" },
52 { 0x0105, "unregister response" },
53 { 0x0006, "ARP request" },
54 { 0x0106, "ARP response" },
55 { 0x0007, "flush request" },
56 { 0x0107, "flush response" },
57 { 0x0008, "NARP request" },
58 { 0x0009, "topology request" },
63 lane_hdr_print(register const u_char
*bp
, int length
)
65 register const struct lecdatahdr_8023
*ep
;
67 ep
= (const struct lecdatahdr_8023
*)bp
;
69 (void)printf("lecid:%x %s %s %d: ",
71 etheraddr_string(ep
->h_source
),
72 etheraddr_string(ep
->h_dest
),
75 (void)printf("lecid:%x %s %s %s %d: ",
77 etheraddr_string(ep
->h_source
),
78 etheraddr_string(ep
->h_dest
),
79 etherproto_string(ep
->h_type
),
84 * This is the top level routine of the printer. 'p' points
85 * to the LANE header of the packet, 'h->ts' is the timestamp,
86 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
87 * is the number of bytes actually captured.
89 * This assumes 802.3, not 802.5, LAN emulation.
92 lane_print(const u_char
*p
, u_int length
, u_int caplen
)
94 struct lane_controlhdr
*lec
;
95 struct lecdatahdr_8023
*ep
;
97 u_short extracted_ethertype
;
99 if (caplen
< sizeof(struct lane_controlhdr
)) {
104 lec
= (struct lane_controlhdr
*)p
;
105 if (ntohs(lec
->lec_header
) == 0xff00) {
109 printf("lec: proto %x vers %x %s",
110 lec
->lec_proto
, lec
->lec_vers
,
111 tok2str(lecop2str
, "opcode-#%u", ntohs(lec
->lec_opcode
)));
115 if (caplen
< sizeof(struct lecdatahdr_8023
)) {
121 lane_hdr_print(p
, length
);
124 * Some printers want to get back at the ethernet addresses,
125 * and/or check that they're not walking off the end of the packet.
126 * Rather than pass them all the way down, we set these globals.
128 packetp
= p
+ 2; /* skip the LECID */
129 snapend
= p
+ caplen
;
131 length
-= sizeof(struct lecdatahdr_8023
);
132 caplen
-= sizeof(struct lecdatahdr_8023
);
133 ep
= (struct lecdatahdr_8023
*)p
;
134 p
+= sizeof(struct lecdatahdr_8023
);
136 ether_type
= ntohs(ep
->h_type
);
139 * Is it (gag) an 802.3 encapsulation?
141 extracted_ethertype
= 0;
142 if (ether_type
<= ETHERMTU
) {
143 /* Try to print the LLC-layer header & higher layers */
144 if (llc_print(p
, length
, caplen
, ep
->h_source
, ep
->h_dest
,
145 &extracted_ethertype
) == 0) {
146 /* ether_type not known, print raw packet */
148 lane_hdr_print((u_char
*)ep
, length
+ sizeof(*ep
));
149 if (extracted_ethertype
) {
151 etherproto_string(htons(extracted_ethertype
)));
153 if (!xflag
&& !qflag
)
154 default_print(p
, caplen
);
156 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
157 &extracted_ethertype
) == 0) {
158 /* ether_type not known, print raw packet */
160 lane_hdr_print((u_char
*)ep
, length
+ sizeof(*ep
));
161 if (!xflag
&& !qflag
)
162 default_print(p
, caplen
);
165 default_print(p
, caplen
);
169 lane_if_print(u_char
*user _U_
, const struct pcap_pkthdr
*h
, const u_char
*p
)
171 int caplen
= h
->caplen
;
177 lane_print(p
, length
, caplen
);