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.2 1999-11-21 09:36:56 fenner Exp $ (LBL)";
32 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_var.h>
44 #include <netinet/udp.h>
45 #include <netinet/udp_var.h>
46 #include <netinet/tcp.h>
47 #include <netinet/tcpip.h>
52 #include "interface.h"
53 #include "addrtoname.h"
56 static const u_char
*packetp
;
57 static const u_char
*snapend
;
60 lane_print(register const u_char
*bp
, int length
)
62 register const struct lecdatahdr_8023
*ep
;
64 ep
= (const struct lecdatahdr_8023
*)bp
;
66 (void)printf("lecid:%d %s %s %d: ",
68 etheraddr_string(ep
->h_source
),
69 etheraddr_string(ep
->h_dest
),
72 (void)printf("lecid:%d %s %s %s %d: ",
74 etheraddr_string(ep
->h_source
),
75 etheraddr_string(ep
->h_dest
),
76 etherproto_string(ep
->h_type
),
81 * This is the top level routine of the printer. 'p' is the points
82 * to the ether header of the packet, 'h->tv' is the timestamp,
83 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
84 * is the number of bytes actually captured.
87 lane_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
89 int caplen
= h
->caplen
;
91 struct lecdatahdr_8023
*ep
;
93 u_short extracted_ethertype
;
97 if (caplen
< sizeof(struct lecdatahdr_8023
)) {
103 lane_print(p
, length
);
106 * Some printers want to get back at the ethernet addresses,
107 * and/or check that they're not walking off the end of the packet.
108 * Rather than pass them all the way down, we set these globals.
111 snapend
= p
+ caplen
;
113 length
-= sizeof(struct lecdatahdr_8023
);
114 caplen
-= sizeof(struct lecdatahdr_8023
);
115 ep
= (struct lecdatahdr_8023
*)p
;
116 p
+= sizeof(struct lecdatahdr_8023
);
118 ether_type
= ntohs(ep
->h_type
);
121 * Is it (gag) an 802.3 encapsulation?
123 extracted_ethertype
= 0;
124 if (ether_type
< ETHERMTU
) {
125 /* Try to print the LLC-layer header & higher layers */
126 if (llc_print(p
, length
, caplen
, ep
->h_source
,ep
->h_dest
)==0) {
127 /* ether_type not known, print raw packet */
129 lane_print((u_char
*)ep
, length
);
130 if (extracted_ethertype
) {
132 etherproto_string(htons(extracted_ethertype
)));
134 if (!xflag
&& !qflag
)
135 default_print(p
, caplen
);
137 } else if (ether_encap_print(ether_type
, p
, length
, caplen
) == 0) {
138 /* ether_type not known, print raw packet */
140 lane_print((u_char
*)ep
, length
+ sizeof(*ep
));
141 if (!xflag
&& !qflag
)
142 default_print(p
, caplen
);
145 default_print(p
, caplen
);