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>
24 static const char rcsid[] =
25 "@(#) $Header: /home/ncvs/src/contrib/tcpdump/print-token.c,v 1.1 1999/02/20 11:17:55 julian Exp $";
28 #include <sys/param.h>
30 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <net/ethernet.h>
42 #include <netinet/in_systm.h>
43 #include <netinet/ip.h>
44 #include <netinet/ip_var.h>
45 #include <netinet/udp.h>
46 #include <netinet/udp_var.h>
47 #include <netinet/tcp.h>
48 #include <netinet/tcpip.h>
53 #include "interface.h"
54 #include "addrtoname.h"
55 #include "ethertype.h"
58 const u_char *packetp;
59 const u_char *snapend;
62 token_print(register const u_char *bp, u_int length)
64 register const struct token_header *tp;
65 register const struct llc *lp;
68 tp = (const struct token_header *)bp;
69 lp = (struct llc *)(bp + TOKEN_HDR_LEN);
71 if (IS_SOURCE_ROUTED) {
72 tp->ether_shost[0] = tp->ether_shost[0] & 0x7f;
73 lp = (struct llc *)(bp + TOKEN_HDR_LEN + RIF_LENGTH);
77 * Ethertype on ethernet is a short, but ethertype in an llc-snap has
78 * been defined as 2 u_chars. This is a stupid little hack to fix
79 * this for now but something better should be done using ntohs()
82 ether_type = ((u_short)lp->ethertype[1] << 16) | lp->ethertype[0];
85 (void)printf("%s %s %d: ",
86 etheraddr_string(ESRC(tp)),
87 etheraddr_string(EDST(tp)),
90 (void)printf("%s %s %s %d: ",
91 etheraddr_string(ESRC(tp)),
92 etheraddr_string(EDST(tp)),
93 etherproto_string(ether_type),
98 * This is the top level routine of the printer. 'p' is the points
99 * to the ether header of the packet, 'tvp' is the timestamp,
100 * 'length' is the length of the packet off the wire, and 'caplen'
101 * is the number of bytes actually captured.
104 token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
106 u_int caplen = h->caplen;
107 u_int length = h->len;
108 struct token_header *tp;
110 extern u_short extracted_ethertype;
111 u_int route_len = 0, seg;
114 tp = (struct token_header *)p;
118 if (caplen < TOKEN_HDR_LEN) {
119 printf("[|token-ring]");
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.
128 tp = (struct token_header *)p;
130 /* Adjust for source routing information in the MAC header */
131 if (IS_SOURCE_ROUTED) {
134 token_print(p, length);
136 route_len = RIF_LENGTH;
139 printf("ac %x fc %x ", tp->ac, tp->fc);
140 ether_type = ntohs((int)lp->ethertype);
142 printf("%s ", broadcast_indicator[BROADCAST]);
143 printf("%s", direction[DIRECTION]);
145 for (seg = 0; seg < SEGMENT_COUNT; seg++)
146 printf(" [%d:%d]", RING_NUMBER(seg), BRIDGE_NUMBER(seg));
148 printf("rt = %x", ntohs(tp->rcf));
150 for (seg = 0; seg < SEGMENT_COUNT; seg++)
151 printf(":%x", ntohs(tp->rseg[seg]));
153 printf(" (%s) ", largest_frame[LARGEST_FRAME]);
156 token_print(p, length);
159 /* Set pointer to llc header, adjusted for routing information */
160 lp = (struct llc *)(p + TOKEN_HDR_LEN + route_len);
163 snapend = p + caplen;
165 /* Skip over token ring MAC header */
166 length -= TOKEN_HDR_LEN + route_len;
167 caplen -= TOKEN_HDR_LEN + route_len;
168 p += TOKEN_HDR_LEN + route_len;
170 extracted_ethertype = 0;
171 /* Try to print the LLC-layer header & higher layers */
172 if (llc_print(p, length, caplen, ESRC(tp), EDST(tp)) == 0) {
173 /* ether_type not known, print raw packet */
175 token_print((u_char *)tp, length);
176 if (extracted_ethertype) {
178 etherproto_string(htons(extracted_ethertype)));
180 if (!xflag && !qflag)
181 default_print(p, caplen);
184 default_print(p, caplen);