2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Hacked version of print-ether.c Larry Lile <lile@stdio.com>
23 * Further tweaked to more closely resemble print-fddi.c
24 * Guy Harris <guy@alum.mit.edu>
27 static const char rcsid
[] =
28 "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.12 2001-07-04 22:03:14 fenner Exp $";
35 #include <sys/param.h>
37 #include <sys/socket.h>
39 #include <netinet/in.h>
45 #include "interface.h"
46 #include "addrtoname.h"
47 #include "ethertype.h"
52 /* Extract src, dst addresses */
54 extract_token_addrs(const struct token_header
*trp
, char *fsrc
, char *fdst
)
56 memcpy(fdst
, (char *)trp
->token_dhost
, 6);
57 memcpy(fsrc
, (char *)trp
->token_shost
, 6);
61 * Print the TR MAC header
64 token_print(register const struct token_header
*trp
, register u_int length
,
65 register const u_char
*fsrc
, register const u_char
*fdst
)
67 char *srcname
, *dstname
;
69 srcname
= etheraddr_string(fsrc
);
70 dstname
= etheraddr_string(fdst
);
73 (void) printf("%02x %02x %s %s %d: ",
79 printf("%s %s %d: ", srcname
, dstname
, length
);
82 static char *broadcast_indicator
[] = {
83 "Non-Broadcast", "Non-Broadcast",
84 "Non-Broadcast", "Non-Broadcast",
85 "All-routes", "All-routes",
86 "Single-route", "Single-route"
89 static char *direction
[] = {
93 static char *largest_frame
[] = {
105 * This is the top level routine of the printer. 'p' is the points
106 * to the TR header of the packet, 'tvp' is the timestamp,
107 * 'length' is the length of the packet off the wire, and 'caplen'
108 * is the number of bytes actually captured.
111 token_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
113 u_int caplen
= h
->caplen
;
114 u_int length
= h
->len
;
115 struct token_header
*trp
;
116 u_short extracted_ethertype
;
117 struct ether_header ehdr
;
118 u_int route_len
= 0, seg
;
120 trp
= (struct token_header
*)p
;
125 if (caplen
< TOKEN_HDRLEN
) {
126 printf("[|token-ring]");
130 * Get the TR addresses into a canonical form
132 extract_token_addrs(trp
, (char*)ESRC(&ehdr
), (char*)EDST(&ehdr
));
134 * Some printers want to get back at the ethernet addresses,
135 * and/or check that they're not walking off the end of the packet.
136 * Rather than pass them all the way down, we set these globals.
138 snapend
= p
+ caplen
;
140 * Actually, the only printers that use packetp are print-arp.c
141 * and print-bootp.c, and they assume that packetp points to an
142 * Ethernet header. The right thing to do is to fix them to know
143 * which link type is in use when they excavate. XXX
145 packetp
= (u_char
*)&ehdr
;
147 /* Adjust for source routing information in the MAC header */
148 if (IS_SOURCE_ROUTED(trp
)) {
149 /* Clear source-routed bit */
150 *ESRC(&ehdr
) &= 0x7f;
153 token_print(trp
, length
, ESRC(&ehdr
), EDST(&ehdr
));
155 route_len
= RIF_LENGTH(trp
);
157 printf("%s ", broadcast_indicator
[BROADCAST(trp
)]);
158 printf("%s", direction
[DIRECTION(trp
)]);
160 for (seg
= 0; seg
< SEGMENT_COUNT(trp
); seg
++)
161 printf(" [%d:%d]", RING_NUMBER(trp
, seg
),
162 BRIDGE_NUMBER(trp
, seg
));
164 printf("rt = %x", ntohs(trp
->token_rcf
));
166 for (seg
= 0; seg
< SEGMENT_COUNT(trp
); seg
++)
167 printf(":%x", ntohs(trp
->token_rseg
[seg
]));
169 printf(" (%s) ", largest_frame
[LARGEST_FRAME(trp
)]);
172 token_print(trp
, length
, ESRC(&ehdr
), EDST(&ehdr
));
175 /* Skip over token ring MAC header and routing information */
176 length
-= TOKEN_HDRLEN
+ route_len
;
177 p
+= TOKEN_HDRLEN
+ route_len
;
178 caplen
-= TOKEN_HDRLEN
+ route_len
;
180 /* Frame Control field determines interpretation of packet */
181 extracted_ethertype
= 0;
182 if (FRAME_TYPE(trp
) == TOKEN_FC_LLC
) {
183 /* Try to print the LLC-layer header & higher layers */
184 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
), EDST(&ehdr
),
185 &extracted_ethertype
) == 0) {
186 /* ether_type not known, print raw packet */
189 length
+ TOKEN_HDRLEN
+ route_len
,
190 ESRC(&ehdr
), EDST(&ehdr
));
191 if (extracted_ethertype
) {
193 etherproto_string(htons(extracted_ethertype
)));
195 if (!xflag
&& !qflag
)
196 default_print(p
, caplen
);
199 /* Some kinds of TR packet we cannot handle intelligently */
200 /* XXX - dissect MAC packets if frame type is 0 */
202 token_print(trp
, length
+ TOKEN_HDRLEN
+ route_len
,
203 ESRC(&ehdr
), EDST(&ehdr
));
204 if (!xflag
&& !qflag
)
205 default_print(p
, caplen
);
208 default_print(p
, caplen
);