Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-token.c
blobd9a64455713459ca97d5b2a3202d24ff72d9fe49
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Hacked version of print-ether.c Larry Lile <lile@stdio.com>
25 * Further tweaked to more closely resemble print-fddi.c
26 * Guy Harris <guy@alum.mit.edu>
28 #include <sys/cdefs.h>
29 #ifndef lint
30 #if 0
31 static const char rcsid[] _U_ =
32 "@(#) Header: /tcpdump/master/tcpdump/print-token.c,v 1.25.2.2 2005/11/13 12:13:01 guy Exp";
33 #else
34 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
35 #endif
36 #endif
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
42 #include <tcpdump-stdinc.h>
44 #include <pcap.h>
45 #include <stdio.h>
46 #include <string.h>
48 #include "interface.h"
49 #include "addrtoname.h"
50 #include "ethertype.h"
52 #include "ether.h"
53 #include "token.h"
55 /* Extract src, dst addresses */
56 static inline void
57 extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst)
59 memcpy(fdst, (const char *)trp->token_dhost, 6);
60 memcpy(fsrc, (const char *)trp->token_shost, 6);
64 * Print the TR MAC header
66 static inline void
67 token_hdr_print(register const struct token_header *trp, register u_int length,
68 register const u_char *fsrc, register const u_char *fdst)
70 const char *srcname, *dstname;
72 srcname = etheraddr_string(fsrc);
73 dstname = etheraddr_string(fdst);
75 if (vflag)
76 (void) printf("%02x %02x %s %s %d: ",
77 trp->token_ac,
78 trp->token_fc,
79 srcname, dstname,
80 length);
81 else
82 printf("%s %s %d: ", srcname, dstname, length);
85 static const char *broadcast_indicator[] = {
86 "Non-Broadcast", "Non-Broadcast",
87 "Non-Broadcast", "Non-Broadcast",
88 "All-routes", "All-routes",
89 "Single-route", "Single-route"
92 static const char *direction[] = {
93 "Forward", "Backward"
96 static const char *largest_frame[] = {
97 "516",
98 "1500",
99 "2052",
100 "4472",
101 "8144",
102 "11407",
103 "17800",
104 "??"
107 u_int
108 token_print(const u_char *p, u_int length, u_int caplen)
110 const struct token_header *trp;
111 u_short extracted_ethertype;
112 struct ether_header ehdr;
113 u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
114 int seg;
116 trp = (const struct token_header *)p;
118 if (caplen < TOKEN_HDRLEN) {
119 printf("[|token-ring]");
120 return hdr_len;
124 * Get the TR addresses into a canonical form
126 extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));
128 /* Adjust for source routing information in the MAC header */
129 if (IS_SOURCE_ROUTED(trp)) {
130 /* Clear source-routed bit */
131 *ESRC(&ehdr) &= 0x7f;
133 if (eflag)
134 token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
136 route_len = RIF_LENGTH(trp);
137 if (vflag) {
138 printf("%s ", broadcast_indicator[BROADCAST(trp)]);
139 printf("%s", direction[DIRECTION(trp)]);
141 for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
142 printf(" [%d:%d]", RING_NUMBER(trp, seg),
143 BRIDGE_NUMBER(trp, seg));
144 } else {
145 printf("rt = %x", ntohs(trp->token_rcf));
147 for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
148 printf(":%x", ntohs(trp->token_rseg[seg]));
150 printf(" (%s) ", largest_frame[LARGEST_FRAME(trp)]);
151 } else {
152 if (eflag)
153 token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
156 /* Skip over token ring MAC header and routing information */
157 hdr_len += route_len;
158 length -= hdr_len;
159 p += hdr_len;
160 caplen -= hdr_len;
162 /* Frame Control field determines interpretation of packet */
163 if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
164 /* Try to print the LLC-layer header & higher layers */
165 if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
166 &extracted_ethertype) == 0) {
167 /* ether_type not known, print raw packet */
168 if (!eflag)
169 token_hdr_print(trp,
170 length + TOKEN_HDRLEN + route_len,
171 ESRC(&ehdr), EDST(&ehdr));
172 if (extracted_ethertype) {
173 printf("(LLC %s) ",
174 etherproto_string(htons(extracted_ethertype)));
176 if (!suppress_default_print)
177 default_print(p, caplen);
179 } else {
180 /* Some kinds of TR packet we cannot handle intelligently */
181 /* XXX - dissect MAC packets if frame type is 0 */
182 if (!eflag)
183 token_hdr_print(trp, length + TOKEN_HDRLEN + route_len,
184 ESRC(&ehdr), EDST(&ehdr));
185 if (!suppress_default_print)
186 default_print(p, caplen);
188 return (hdr_len);
192 * This is the top level routine of the printer. 'p' points
193 * to the TR header of the packet, 'h->ts' is the timestamp,
194 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
195 * is the number of bytes actually captured.
197 u_int
198 token_if_print(const struct pcap_pkthdr *h, const u_char *p)
200 return (token_print(p, h->len, h->caplen));