]> The Tcpdump Group git mirrors - tcpdump/blob - print-lane.c
remove extra prototype (now in interface.h)
[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.3 2000-01-09 10:00:22 assar 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/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
48 #include <stdio.h>
49 #include <pcap.h>
50
51 #include "interface.h"
52 #include "addrtoname.h"
53 #include "lane.h"
54
55 static const u_char *packetp;
56 static const u_char *snapend;
57
58 static inline void
59 lane_print(register const u_char *bp, int length)
60 {
61 register const struct lecdatahdr_8023 *ep;
62
63 ep = (const struct lecdatahdr_8023 *)bp;
64 if (qflag)
65 (void)printf("lecid:%d %s %s %d: ",
66 ntohs(ep->le_header),
67 etheraddr_string(ep->h_source),
68 etheraddr_string(ep->h_dest),
69 length);
70 else
71 (void)printf("lecid:%d %s %s %s %d: ",
72 ntohs(ep->le_header),
73 etheraddr_string(ep->h_source),
74 etheraddr_string(ep->h_dest),
75 etherproto_string(ep->h_type),
76 length);
77 }
78
79 /*
80 * This is the top level routine of the printer. 'p' is the points
81 * to the ether header of the packet, 'h->tv' is the timestamp,
82 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
83 * is the number of bytes actually captured.
84 */
85 void
86 lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
87 {
88 int caplen = h->caplen;
89 int length = h->len;
90 struct lecdatahdr_8023 *ep;
91 u_short ether_type;
92 u_short extracted_ethertype;
93
94 ts_print(&h->ts);
95
96 if (caplen < sizeof(struct lecdatahdr_8023)) {
97 printf("[|lane]");
98 goto out;
99 }
100
101 if (eflag)
102 lane_print(p, length);
103
104 /*
105 * Some printers want to get back at the ethernet addresses,
106 * and/or check that they're not walking off the end of the packet.
107 * Rather than pass them all the way down, we set these globals.
108 */
109 packetp = p;
110 snapend = p + caplen;
111
112 length -= sizeof(struct lecdatahdr_8023);
113 caplen -= sizeof(struct lecdatahdr_8023);
114 ep = (struct lecdatahdr_8023 *)p;
115 p += sizeof(struct lecdatahdr_8023);
116
117 ether_type = ntohs(ep->h_type);
118
119 /*
120 * Is it (gag) an 802.3 encapsulation?
121 */
122 extracted_ethertype = 0;
123 if (ether_type < ETHERMTU) {
124 /* Try to print the LLC-layer header & higher layers */
125 if (llc_print(p, length, caplen, ep->h_source,ep->h_dest)==0) {
126 /* ether_type not known, print raw packet */
127 if (!eflag)
128 lane_print((u_char *)ep, length);
129 if (extracted_ethertype) {
130 printf("(LLC %s) ",
131 etherproto_string(htons(extracted_ethertype)));
132 }
133 if (!xflag && !qflag)
134 default_print(p, caplen);
135 }
136 } else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
137 /* ether_type not known, print raw packet */
138 if (!eflag)
139 lane_print((u_char *)ep, length + sizeof(*ep));
140 if (!xflag && !qflag)
141 default_print(p, caplen);
142 }
143 if (xflag)
144 default_print(p, caplen);
145 out:
146 putchar('\n');
147 }