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.17 2002-08-01 08:53:33 risso Exp $";
35 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "ethertype.h"
48 /* Extract src, dst addresses */
50 extract_token_addrs(const struct token_header
*trp
, char *fsrc
, char *fdst
)
52 memcpy(fdst
, (const char *)trp
->token_dhost
, 6);
53 memcpy(fsrc
, (const char *)trp
->token_shost
, 6);
57 * Print the TR MAC header
60 token_hdr_print(register const struct token_header
*trp
, register u_int length
,
61 register const u_char
*fsrc
, register const u_char
*fdst
)
63 const char *srcname
, *dstname
;
65 srcname
= etheraddr_string(fsrc
);
66 dstname
= etheraddr_string(fdst
);
69 (void) printf("%02x %02x %s %s %d: ",
75 printf("%s %s %d: ", srcname
, dstname
, length
);
78 static const char *broadcast_indicator
[] = {
79 "Non-Broadcast", "Non-Broadcast",
80 "Non-Broadcast", "Non-Broadcast",
81 "All-routes", "All-routes",
82 "Single-route", "Single-route"
85 static const char *direction
[] = {
89 static const char *largest_frame
[] = {
101 token_print(const u_char
*p
, u_int length
, u_int caplen
)
103 const struct token_header
*trp
;
104 u_short extracted_ethertype
;
105 struct ether_header ehdr
;
106 u_int route_len
= 0, hdr_len
= TOKEN_HDRLEN
, seg
;
108 trp
= (const struct token_header
*)p
;
110 if (caplen
< TOKEN_HDRLEN
) {
111 printf("[|token-ring]");
115 * Get the TR addresses into a canonical form
117 extract_token_addrs(trp
, (char*)ESRC(&ehdr
), (char*)EDST(&ehdr
));
119 * Some printers want to get back at the ethernet addresses,
120 * and/or check that they're not walking off the end of the packet.
121 * Rather than pass them all the way down, we set these globals.
123 snapend
= p
+ caplen
;
125 * Actually, the only printers that use packetp are print-arp.c
126 * and print-bootp.c, and they assume that packetp points to an
127 * Ethernet header. The right thing to do is to fix them to know
128 * which link type is in use when they excavate. XXX
130 packetp
= (u_char
*)&ehdr
;
132 /* Adjust for source routing information in the MAC header */
133 if (IS_SOURCE_ROUTED(trp
)) {
134 /* Clear source-routed bit */
135 *ESRC(&ehdr
) &= 0x7f;
138 token_hdr_print(trp
, length
, ESRC(&ehdr
), EDST(&ehdr
));
140 route_len
= RIF_LENGTH(trp
);
142 printf("%s ", broadcast_indicator
[BROADCAST(trp
)]);
143 printf("%s", direction
[DIRECTION(trp
)]);
145 for (seg
= 0; seg
< SEGMENT_COUNT(trp
); seg
++)
146 printf(" [%d:%d]", RING_NUMBER(trp
, seg
),
147 BRIDGE_NUMBER(trp
, seg
));
149 printf("rt = %x", ntohs(trp
->token_rcf
));
151 for (seg
= 0; seg
< SEGMENT_COUNT(trp
); seg
++)
152 printf(":%x", ntohs(trp
->token_rseg
[seg
]));
154 printf(" (%s) ", largest_frame
[LARGEST_FRAME(trp
)]);
157 token_hdr_print(trp
, length
, ESRC(&ehdr
), EDST(&ehdr
));
160 /* Skip over token ring MAC header and routing information */
161 hdr_len
+= route_len
;
166 /* Frame Control field determines interpretation of packet */
167 extracted_ethertype
= 0;
168 if (FRAME_TYPE(trp
) == TOKEN_FC_LLC
) {
169 /* Try to print the LLC-layer header & higher layers */
170 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
), EDST(&ehdr
),
171 &extracted_ethertype
) == 0) {
172 /* ether_type not known, print raw packet */
175 length
+ TOKEN_HDRLEN
+ route_len
,
176 ESRC(&ehdr
), EDST(&ehdr
));
177 if (extracted_ethertype
) {
179 etherproto_string(htons(extracted_ethertype
)));
181 if (!xflag
&& !qflag
)
182 default_print(p
, caplen
);
185 /* Some kinds of TR packet we cannot handle intelligently */
186 /* XXX - dissect MAC packets if frame type is 0 */
188 token_hdr_print(trp
, length
+ TOKEN_HDRLEN
+ route_len
,
189 ESRC(&ehdr
), EDST(&ehdr
));
190 if (!xflag
&& !qflag
)
191 default_print(p
, caplen
);
197 * This is the top level routine of the printer. 'p' is the points
198 * to the TR header of the packet, 'tvp' is the timestamp,
199 * 'length' is the length of the packet off the wire, and 'caplen'
200 * is the number of bytes actually captured.
203 token_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
205 u_int caplen
= h
->caplen
;
206 u_int length
= h
->len
;
212 hdr_len
= token_print(p
, length
, caplen
);
215 * If "-x" was specified, print stuff past the Token Ring header,
216 * if there's anything to print.
218 if (xflag
&& caplen
> hdr_len
)
219 default_print(p
+ hdr_len
, caplen
- hdr_len
);