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.14 2002-07-11 09:17:24 guy Exp $ (LBL)";
32 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
38 #include <netinet/in.h>
43 #include "interface.h"
44 #include "addrtoname.h"
48 static const struct tok lecop2str
[] = {
49 { 0x0001, "configure request" },
50 { 0x0101, "configure response" },
51 { 0x0002, "join request" },
52 { 0x0102, "join response" },
53 { 0x0003, "ready query" },
54 { 0x0103, "ready indication" },
55 { 0x0004, "register request" },
56 { 0x0104, "register response" },
57 { 0x0005, "unregister request" },
58 { 0x0105, "unregister response" },
59 { 0x0006, "ARP request" },
60 { 0x0106, "ARP response" },
61 { 0x0007, "flush request" },
62 { 0x0107, "flush response" },
63 { 0x0008, "NARP request" },
64 { 0x0009, "topology request" },
69 lane_hdr_print(register const u_char
*bp
, int length
)
71 register const struct lecdatahdr_8023
*ep
;
73 ep
= (const struct lecdatahdr_8023
*)bp
;
75 (void)printf("lecid:%x %s %s %d: ",
77 etheraddr_string(ep
->h_source
),
78 etheraddr_string(ep
->h_dest
),
81 (void)printf("lecid:%x %s %s %s %d: ",
83 etheraddr_string(ep
->h_source
),
84 etheraddr_string(ep
->h_dest
),
85 etherproto_string(ep
->h_type
),
90 * This is the top level routine of the printer. 'p' is the points
91 * to the ether header of the packet, 'h->tv' is the timestamp,
92 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
93 * is the number of bytes actually captured.
95 * This assumes 802.3, not 802.5, LAN emulation.
98 lane_print(const u_char
*p
, u_int length
, u_int caplen
)
100 struct lane_controlhdr
*lec
;
101 struct lecdatahdr_8023
*ep
;
103 u_short extracted_ethertype
;
105 if (caplen
< sizeof(struct lane_controlhdr
)) {
110 lec
= (struct lane_controlhdr
*)p
;
111 if (ntohs(lec
->lec_header
) == 0xff00) {
115 printf("lec: proto %x vers %x %s",
116 lec
->lec_proto
, lec
->lec_vers
,
117 tok2str(lecop2str
, "opcode-#%u", ntohs(lec
->lec_opcode
)));
121 if (caplen
< sizeof(struct lecdatahdr_8023
)) {
127 lane_hdr_print(p
, length
);
130 * Some printers want to get back at the ethernet addresses,
131 * and/or check that they're not walking off the end of the packet.
132 * Rather than pass them all the way down, we set these globals.
134 packetp
= p
+ 2; /* skip the LECID */
135 snapend
= p
+ caplen
;
137 length
-= sizeof(struct lecdatahdr_8023
);
138 caplen
-= sizeof(struct lecdatahdr_8023
);
139 ep
= (struct lecdatahdr_8023
*)p
;
140 p
+= sizeof(struct lecdatahdr_8023
);
142 ether_type
= ntohs(ep
->h_type
);
145 * Is it (gag) an 802.3 encapsulation?
147 extracted_ethertype
= 0;
148 if (ether_type
<= ETHERMTU
) {
149 /* Try to print the LLC-layer header & higher layers */
150 if (llc_print(p
, length
, caplen
, ep
->h_source
, ep
->h_dest
,
151 &extracted_ethertype
) == 0) {
152 /* ether_type not known, print raw packet */
154 lane_hdr_print((u_char
*)ep
, length
+ sizeof(*ep
));
155 if (extracted_ethertype
) {
157 etherproto_string(htons(extracted_ethertype
)));
159 if (!xflag
&& !qflag
)
160 default_print(p
, caplen
);
162 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
163 &extracted_ethertype
) == 0) {
164 /* ether_type not known, print raw packet */
166 lane_hdr_print((u_char
*)ep
, length
+ sizeof(*ep
));
167 if (!xflag
&& !qflag
)
168 default_print(p
, caplen
);
171 default_print(p
, caplen
);
175 lane_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
177 int caplen
= h
->caplen
;
183 lane_print(p
, length
, caplen
);