]> The Tcpdump Group git mirrors - tcpdump/blob - print-lane.c
Add Loris Digioanni, as he's credited as the main programmer on the
[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.15 2002-08-01 08:53:15 risso Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <tcpdump-stdinc.h>
33
34 #include <stdio.h>
35 #include <pcap.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "ether.h"
40 #include "lane.h"
41
42 static const struct tok lecop2str[] = {
43 { 0x0001, "configure request" },
44 { 0x0101, "configure response" },
45 { 0x0002, "join request" },
46 { 0x0102, "join response" },
47 { 0x0003, "ready query" },
48 { 0x0103, "ready indication" },
49 { 0x0004, "register request" },
50 { 0x0104, "register response" },
51 { 0x0005, "unregister request" },
52 { 0x0105, "unregister response" },
53 { 0x0006, "ARP request" },
54 { 0x0106, "ARP response" },
55 { 0x0007, "flush request" },
56 { 0x0107, "flush response" },
57 { 0x0008, "NARP request" },
58 { 0x0009, "topology request" },
59 { 0, NULL }
60 };
61
62 static inline void
63 lane_hdr_print(register const u_char *bp, int length)
64 {
65 register const struct lecdatahdr_8023 *ep;
66
67 ep = (const struct lecdatahdr_8023 *)bp;
68 if (qflag)
69 (void)printf("lecid:%x %s %s %d: ",
70 ntohs(ep->le_header),
71 etheraddr_string(ep->h_source),
72 etheraddr_string(ep->h_dest),
73 length);
74 else
75 (void)printf("lecid:%x %s %s %s %d: ",
76 ntohs(ep->le_header),
77 etheraddr_string(ep->h_source),
78 etheraddr_string(ep->h_dest),
79 etherproto_string(ep->h_type),
80 length);
81 }
82
83 /*
84 * This is the top level routine of the printer. 'p' is the points
85 * to the ether header of the packet, 'h->tv' is the timestamp,
86 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
87 * is the number of bytes actually captured.
88 *
89 * This assumes 802.3, not 802.5, LAN emulation.
90 */
91 void
92 lane_print(const u_char *p, u_int length, u_int caplen)
93 {
94 struct lane_controlhdr *lec;
95 struct lecdatahdr_8023 *ep;
96 u_short ether_type;
97 u_short extracted_ethertype;
98
99 if (caplen < sizeof(struct lane_controlhdr)) {
100 printf("[|lane]");
101 return;
102 }
103
104 lec = (struct lane_controlhdr *)p;
105 if (ntohs(lec->lec_header) == 0xff00) {
106 /*
107 * LE Control.
108 */
109 printf("lec: proto %x vers %x %s",
110 lec->lec_proto, lec->lec_vers,
111 tok2str(lecop2str, "opcode-#%u", ntohs(lec->lec_opcode)));
112 return;
113 }
114
115 if (caplen < sizeof(struct lecdatahdr_8023)) {
116 printf("[|lane]");
117 return;
118 }
119
120 if (eflag)
121 lane_hdr_print(p, length);
122
123 /*
124 * Some printers want to get back at the ethernet addresses,
125 * and/or check that they're not walking off the end of the packet.
126 * Rather than pass them all the way down, we set these globals.
127 */
128 packetp = p + 2; /* skip the LECID */
129 snapend = p + caplen;
130
131 length -= sizeof(struct lecdatahdr_8023);
132 caplen -= sizeof(struct lecdatahdr_8023);
133 ep = (struct lecdatahdr_8023 *)p;
134 p += sizeof(struct lecdatahdr_8023);
135
136 ether_type = ntohs(ep->h_type);
137
138 /*
139 * Is it (gag) an 802.3 encapsulation?
140 */
141 extracted_ethertype = 0;
142 if (ether_type <= ETHERMTU) {
143 /* Try to print the LLC-layer header & higher layers */
144 if (llc_print(p, length, caplen, ep->h_source, ep->h_dest,
145 &extracted_ethertype) == 0) {
146 /* ether_type not known, print raw packet */
147 if (!eflag)
148 lane_hdr_print((u_char *)ep, length + sizeof(*ep));
149 if (extracted_ethertype) {
150 printf("(LLC %s) ",
151 etherproto_string(htons(extracted_ethertype)));
152 }
153 if (!xflag && !qflag)
154 default_print(p, caplen);
155 }
156 } else if (ether_encap_print(ether_type, p, length, caplen,
157 &extracted_ethertype) == 0) {
158 /* ether_type not known, print raw packet */
159 if (!eflag)
160 lane_hdr_print((u_char *)ep, length + sizeof(*ep));
161 if (!xflag && !qflag)
162 default_print(p, caplen);
163 }
164 if (xflag)
165 default_print(p, caplen);
166 }
167
168 void
169 lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
170 {
171 int caplen = h->caplen;
172 int length = h->len;
173
174 ++infodelay;
175 ts_print(&h->ts);
176
177 lane_print(p, length, caplen);
178
179 putchar('\n');
180 --infodelay;
181 if (infoprint)
182 info(0);
183 }