]> The Tcpdump Group git mirrors - tcpdump/blob - print-lane.c
print pppOE. From <[email protected]>
[tcpdump] / print-lane.c
1 /*
2 * Marko Kiiskila carnil@cs.tut.fi
3 *
4 * Tampere University of Technology - Telecommunications Laboratory
5 *
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
14 * the software.
15 *
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
19 * SOFTWARE.
20 *
21 */
22
23 #ifndef lint
24 static const char rcsid[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.1 1999-11-21 03:52:11 assar Exp $ (LBL)";
26 #endif
27
28 #include <sys/param.h>
29 #include <sys/time.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32
33 #include <net/if.h>
34
35 #include <netinet/in.h>
36 #include <netinet/if_ether.h>
37 #include <netinet/in_systm.h>
38 #include <netinet/ip.h>
39 #include <netinet/ip_var.h>
40 #include <netinet/udp.h>
41 #include <netinet/udp_var.h>
42 #include <netinet/tcp.h>
43 #include <netinet/tcpip.h>
44
45 #include <stdio.h>
46 #include <pcap.h>
47
48 #include "interface.h"
49 #include "addrtoname.h"
50 #include "lane.h"
51
52 static const u_char *packetp;
53 static const u_char *snapend;
54
55 static inline void
56 lane_print(register const u_char *bp, int length)
57 {
58 register const struct lecdatahdr_8023 *ep;
59
60 ep = (const struct lecdatahdr_8023 *)bp;
61 if (qflag)
62 (void)printf("lecid:%d %s %s %d: ",
63 ntohs(ep->le_header),
64 etheraddr_string(ep->h_source),
65 etheraddr_string(ep->h_dest),
66 length);
67 else
68 (void)printf("lecid:%d %s %s %s %d: ",
69 ntohs(ep->le_header),
70 etheraddr_string(ep->h_source),
71 etheraddr_string(ep->h_dest),
72 etherproto_string(ep->h_type),
73 length);
74 }
75
76 /*
77 * This is the top level routine of the printer. 'p' is the points
78 * to the ether header of the packet, 'h->tv' is the timestamp,
79 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
80 * is the number of bytes actually captured.
81 */
82 void
83 lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
84 {
85 int caplen = h->caplen;
86 int length = h->len;
87 struct lecdatahdr_8023 *ep;
88 u_short ether_type;
89 u_short extracted_ethertype;
90
91 ts_print(&h->ts);
92
93 if (caplen < sizeof(struct lecdatahdr_8023)) {
94 printf("[|lane]");
95 goto out;
96 }
97
98 if (eflag)
99 lane_print(p, length);
100
101 /*
102 * Some printers want to get back at the ethernet addresses,
103 * and/or check that they're not walking off the end of the packet.
104 * Rather than pass them all the way down, we set these globals.
105 */
106 packetp = p;
107 snapend = p + caplen;
108
109 length -= sizeof(struct lecdatahdr_8023);
110 caplen -= sizeof(struct lecdatahdr_8023);
111 ep = (struct lecdatahdr_8023 *)p;
112 p += sizeof(struct lecdatahdr_8023);
113
114 ether_type = ntohs(ep->h_type);
115
116 /*
117 * Is it (gag) an 802.3 encapsulation?
118 */
119 extracted_ethertype = 0;
120 if (ether_type < ETHERMTU) {
121 /* Try to print the LLC-layer header & higher layers */
122 if (llc_print(p, length, caplen, ep->h_source,ep->h_dest)==0) {
123 /* ether_type not known, print raw packet */
124 if (!eflag)
125 lane_print((u_char *)ep, length);
126 if (extracted_ethertype) {
127 printf("(LLC %s) ",
128 etherproto_string(htons(extracted_ethertype)));
129 }
130 if (!xflag && !qflag)
131 default_print(p, caplen);
132 }
133 } else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
134 /* ether_type not known, print raw packet */
135 if (!eflag)
136 lane_print((u_char *)ep, length + sizeof(*ep));
137 if (!xflag && !qflag)
138 default_print(p, caplen);
139 }
140 if (xflag)
141 default_print(p, caplen);
142 out:
143 putchar('\n');
144 }