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
[] _U_
=
28 "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.27 2005-11-13 12:12:43 guy Exp $";
35 #include <tcpdump-stdinc.h>
41 #include "interface.h"
43 #include "addrtoname.h"
44 #include "ethertype.h"
49 /* Extract src, dst addresses */
51 extract_token_addrs(const struct token_header
*trp
, char *fsrc
, char *fdst
)
53 memcpy(fdst
, (const char *)trp
->token_dhost
, 6);
54 memcpy(fsrc
, (const char *)trp
->token_shost
, 6);
58 * Print the TR MAC header
61 token_hdr_print(register const struct token_header
*trp
, register u_int length
,
62 register const u_char
*fsrc
, register const u_char
*fdst
)
64 const char *srcname
, *dstname
;
66 srcname
= etheraddr_string(fsrc
);
67 dstname
= etheraddr_string(fdst
);
70 (void) printf("%02x %02x %s %s %d: ",
76 printf("%s %s %d: ", srcname
, dstname
, length
);
79 static const char *broadcast_indicator
[] = {
80 "Non-Broadcast", "Non-Broadcast",
81 "Non-Broadcast", "Non-Broadcast",
82 "All-routes", "All-routes",
83 "Single-route", "Single-route"
86 static const char *direction
[] = {
90 static const char *largest_frame
[] = {
102 token_print(const u_char
*p
, u_int length
, u_int caplen
)
104 const struct token_header
*trp
;
105 u_short extracted_ethertype
;
106 struct ether_header ehdr
;
107 u_int route_len
= 0, hdr_len
= TOKEN_HDRLEN
;
110 trp
= (const struct token_header
*)p
;
112 if (caplen
< TOKEN_HDRLEN
) {
113 printf("[|token-ring]");
118 * Get the TR addresses into a canonical form
120 extract_token_addrs(trp
, (char*)ESRC(&ehdr
), (char*)EDST(&ehdr
));
122 /* Adjust for source routing information in the MAC header */
123 if (IS_SOURCE_ROUTED(trp
)) {
124 /* Clear source-routed bit */
125 *ESRC(&ehdr
) &= 0x7f;
128 token_hdr_print(trp
, length
, ESRC(&ehdr
), EDST(&ehdr
));
130 if (caplen
< TOKEN_HDRLEN
+ 2) {
131 printf("[|token-ring]");
134 route_len
= RIF_LENGTH(trp
);
135 hdr_len
+= route_len
;
136 if (caplen
< hdr_len
) {
137 printf("[|token-ring]");
141 printf("%s ", broadcast_indicator
[BROADCAST(trp
)]);
142 printf("%s", direction
[DIRECTION(trp
)]);
144 for (seg
= 0; seg
< SEGMENT_COUNT(trp
); seg
++)
145 printf(" [%d:%d]", RING_NUMBER(trp
, seg
),
146 BRIDGE_NUMBER(trp
, seg
));
148 printf("rt = %x", EXTRACT_16BITS(&trp
->token_rcf
));
150 for (seg
= 0; seg
< SEGMENT_COUNT(trp
); seg
++)
151 printf(":%x", EXTRACT_16BITS(&trp
->token_rseg
[seg
]));
153 printf(" (%s) ", largest_frame
[LARGEST_FRAME(trp
)]);
156 token_hdr_print(trp
, length
, ESRC(&ehdr
), EDST(&ehdr
));
159 /* Skip over token ring MAC header and routing information */
164 /* Frame Control field determines interpretation of packet */
165 if (FRAME_TYPE(trp
) == TOKEN_FC_LLC
) {
166 /* Try to print the LLC-layer header & higher layers */
167 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
), EDST(&ehdr
),
168 &extracted_ethertype
) == 0) {
169 /* ether_type not known, print raw packet */
172 length
+ TOKEN_HDRLEN
+ route_len
,
173 ESRC(&ehdr
), EDST(&ehdr
));
174 if (extracted_ethertype
) {
176 etherproto_string(htons(extracted_ethertype
)));
178 if (!suppress_default_print
)
179 default_print(p
, caplen
);
182 /* Some kinds of TR packet we cannot handle intelligently */
183 /* XXX - dissect MAC packets if frame type is 0 */
185 token_hdr_print(trp
, length
+ TOKEN_HDRLEN
+ route_len
,
186 ESRC(&ehdr
), EDST(&ehdr
));
187 if (!suppress_default_print
)
188 default_print(p
, caplen
);
194 * This is the top level routine of the printer. 'p' points
195 * to the TR header of the packet, 'h->ts' is the timestamp,
196 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
197 * is the number of bytes actually captured.
200 token_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
202 return (token_print(p
, h
->len
, h
->caplen
));