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