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