Deleted Added
full compact
print-token.c (75118) print-token.c (98527)
1/*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
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

--- 6 unchanged lines hidden (view full) ---

15 * or promote products derived from this software without specific prior
16 * written permission.
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.
20 *
21 * Hacked version of print-ether.c Larry Lile <lile@stdio.com>
22 *
1/*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
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

--- 6 unchanged lines hidden (view full) ---

15 * or promote products derived from this software without specific prior
16 * written permission.
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.
20 *
21 * Hacked version of print-ether.c Larry Lile <lile@stdio.com>
22 *
23 * $FreeBSD: head/contrib/tcpdump/print-token.c 75118 2001-04-03 07:50:46Z fenner $
23 * Further tweaked to more closely resemble print-fddi.c
24 * Guy Harris <guy@alum.mit.edu>
25 *
26 * $FreeBSD: head/contrib/tcpdump/print-token.c 98527 2002-06-21 00:49:02Z fenner $
24 */
25#ifndef lint
26static const char rcsid[] =
27 */
28#ifndef lint
29static const char rcsid[] =
27 "@(#) $Header: /home/ncvs/src/contrib/tcpdump/print-token.c,v 1.1 1999/02/20 11:17:55 julian Exp $";
30 "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.13 2001/09/18 15:46:37 fenner Exp $";
28#endif
29
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
30#include <sys/param.h>
31#include <sys/time.h>
32#include <sys/socket.h>
33
37#include <sys/param.h>
38#include <sys/time.h>
39#include <sys/socket.h>
40
34#if __STDC__
35struct mbuf;
36struct rtentry;
37#endif
38#include <net/if.h>
39
40#include "token.h"
41
42#include <netinet/in.h>
41#include <netinet/in.h>
43#include <net/ethernet.h>
44#include <netinet/in_systm.h>
45#include <netinet/ip.h>
46#include <netinet/ip_var.h>
47#include <netinet/udp.h>
48#include <netinet/udp_var.h>
49#include <netinet/tcp.h>
50#include <netinet/tcpip.h>
51
42
52#include <stdio.h>
53#include <pcap.h>
43#include <pcap.h>
44#include <stdio.h>
45#include <string.h>
54
55#include "interface.h"
56#include "addrtoname.h"
57#include "ethertype.h"
46
47#include "interface.h"
48#include "addrtoname.h"
49#include "ethertype.h"
58#include "llc.h"
59
50
60const u_char *packetp;
61const u_char *snapend;
51#include "ether.h"
52#include "token.h"
62
53
54/* Extract src, dst addresses */
63static inline void
55static inline void
64token_print(register const u_char *bp, u_int length)
56extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst)
65{
57{
66 register const struct token_header *tp;
67 register const struct llc *lp;
68 u_short ether_type;
58 memcpy(fdst, (const char *)trp->token_dhost, 6);
59 memcpy(fsrc, (const char *)trp->token_shost, 6);
60}
69
61
70 tp = (const struct token_header *)bp;
71 lp = (struct llc *)(bp + TOKEN_HDR_LEN);
62/*
63 * Print the TR MAC header
64 */
65static inline void
66token_print(register const struct token_header *trp, register u_int length,
67 register const u_char *fsrc, register const u_char *fdst)
68{
69 const char *srcname, *dstname;
72
70
73 if (IS_SOURCE_ROUTED) {
74 tp->ether_shost[0] = tp->ether_shost[0] & 0x7f;
75 lp = (struct llc *)(bp + TOKEN_HDR_LEN + RIF_LENGTH);
76 }
71 srcname = etheraddr_string(fsrc);
72 dstname = etheraddr_string(fdst);
77
73
78 /*
79 * Ethertype on ethernet is a short, but ethertype in an llc-snap has
80 * been defined as 2 u_chars. This is a stupid little hack to fix
81 * this for now but something better should be done using ntohs()
82 * XXX
83 */
84 ether_type = ((u_short)lp->ethertype[1] << 16) | lp->ethertype[0];
85
86 if (qflag)
87 (void)printf("%s %s %d: ",
88 etheraddr_string(ESRC(tp)),
89 etheraddr_string(EDST(tp)),
90 length);
74 if (vflag)
75 (void) printf("%02x %02x %s %s %d: ",
76 trp->token_ac,
77 trp->token_fc,
78 srcname, dstname,
79 length);
91 else
80 else
92 (void)printf("%s %s %s %d: ",
93 etheraddr_string(ESRC(tp)),
94 etheraddr_string(EDST(tp)),
95 etherproto_string(ether_type),
96 length);
81 printf("%s %s %d: ", srcname, dstname, length);
97}
98
82}
83
84static const char *broadcast_indicator[] = {
85 "Non-Broadcast", "Non-Broadcast",
86 "Non-Broadcast", "Non-Broadcast",
87 "All-routes", "All-routes",
88 "Single-route", "Single-route"
89};
90
91static const char *direction[] = {
92 "Forward", "Backward"
93};
94
95static const char *largest_frame[] = {
96 "516",
97 "1500",
98 "2052",
99 "4472",
100 "8144",
101 "11407",
102 "17800",
103 "??"
104};
105
99/*
100 * This is the top level routine of the printer. 'p' is the points
106/*
107 * This is the top level routine of the printer. 'p' is the points
101 * to the ether header of the packet, 'tvp' is the timestamp,
108 * to the TR header of the packet, 'tvp' is the timestamp,
102 * 'length' is the length of the packet off the wire, and 'caplen'
103 * is the number of bytes actually captured.
104 */
105void
106token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
107{
108 u_int caplen = h->caplen;
109 u_int length = h->len;
109 * 'length' is the length of the packet off the wire, and 'caplen'
110 * is the number of bytes actually captured.
111 */
112void
113token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
114{
115 u_int caplen = h->caplen;
116 u_int length = h->len;
110 struct token_header *tp;
111 u_short ether_type;
117 const struct token_header *trp;
112 u_short extracted_ethertype;
118 u_short extracted_ethertype;
113 u_int route_len = 0, seg;
114 struct llc *lp;
119 struct ether_header ehdr;
120 u_int route_len = 0, seg;
115
121
116 tp = (struct token_header *)p;
122 trp = (const struct token_header *)p;
117
123
124 ++infodelay;
118 ts_print(&h->ts);
119
125 ts_print(&h->ts);
126
120 if (caplen < TOKEN_HDR_LEN) {
127 if (caplen < TOKEN_HDRLEN) {
121 printf("[|token-ring]");
122 goto out;
123 }
128 printf("[|token-ring]");
129 goto out;
130 }
124
125 /*
131 /*
132 * Get the TR addresses into a canonical form
133 */
134 extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));
135 /*
126 * Some printers want to get back at the ethernet addresses,
127 * and/or check that they're not walking off the end of the packet.
128 * Rather than pass them all the way down, we set these globals.
129 */
136 * Some printers want to get back at the ethernet addresses,
137 * and/or check that they're not walking off the end of the packet.
138 * Rather than pass them all the way down, we set these globals.
139 */
130 tp = (struct token_header *)p;
140 snapend = p + caplen;
141 /*
142 * Actually, the only printers that use packetp are print-arp.c
143 * and print-bootp.c, and they assume that packetp points to an
144 * Ethernet header. The right thing to do is to fix them to know
145 * which link type is in use when they excavate. XXX
146 */
147 packetp = (u_char *)&ehdr;
131
148
132 /* Adjust for source routing information in the MAC header */
133 if (IS_SOURCE_ROUTED) {
149 /* Adjust for source routing information in the MAC header */
150 if (IS_SOURCE_ROUTED(trp)) {
151 /* Clear source-routed bit */
152 *ESRC(&ehdr) &= 0x7f;
134
153
135 if (eflag)
136 token_print(p, length);
154 if (eflag)
155 token_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
137
156
138 route_len = RIF_LENGTH;
139 if (vflag) {
140 if (vflag > 1)
141 printf("ac %x fc %x ", tp->ac, tp->fc);
142 ether_type = ntohs((int)lp->ethertype);
143
144 printf("%s ", broadcast_indicator[BROADCAST]);
145 printf("%s", direction[DIRECTION]);
157 route_len = RIF_LENGTH(trp);
158 if (vflag) {
159 printf("%s ", broadcast_indicator[BROADCAST(trp)]);
160 printf("%s", direction[DIRECTION(trp)]);
146
161
147 for (seg = 0; seg < SEGMENT_COUNT; seg++)
148 printf(" [%d:%d]", RING_NUMBER(seg), BRIDGE_NUMBER(seg));
149 } else {
150 printf("rt = %x", ntohs(tp->rcf));
162 for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
163 printf(" [%d:%d]", RING_NUMBER(trp, seg),
164 BRIDGE_NUMBER(trp, seg));
165 } else {
166 printf("rt = %x", ntohs(trp->token_rcf));
151
167
152 for (seg = 0; seg < SEGMENT_COUNT; seg++)
153 printf(":%x", ntohs(tp->rseg[seg]));
154 }
155 printf(" (%s) ", largest_frame[LARGEST_FRAME]);
156 } else {
157 if (eflag)
158 token_print(p, length);
159 }
168 for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
169 printf(":%x", ntohs(trp->token_rseg[seg]));
170 }
171 printf(" (%s) ", largest_frame[LARGEST_FRAME(trp)]);
172 } else {
173 if (eflag)
174 token_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
175 }
160
176
161 /* Set pointer to llc header, adjusted for routing information */
162 lp = (struct llc *)(p + TOKEN_HDR_LEN + route_len);
177 /* Skip over token ring MAC header and routing information */
178 length -= TOKEN_HDRLEN + route_len;
179 p += TOKEN_HDRLEN + route_len;
180 caplen -= TOKEN_HDRLEN + route_len;
163
181
164 packetp = p;
165 snapend = p + caplen;
166
167 /* Skip over token ring MAC header */
168 length -= TOKEN_HDR_LEN + route_len;
169 caplen -= TOKEN_HDR_LEN + route_len;
170 p += TOKEN_HDR_LEN + route_len;
171
182 /* Frame Control field determines interpretation of packet */
172 extracted_ethertype = 0;
183 extracted_ethertype = 0;
173 /* Try to print the LLC-layer header & higher layers */
174 if (llc_print(p, length, caplen, ESRC(tp), EDST(tp), &extracted_ethertype) == 0) {
175 /* ether_type not known, print raw packet */
176 if (!eflag)
177 token_print((u_char *)tp, length);
178 if (extracted_ethertype) {
179 printf("(LLC %s) ",
180 etherproto_string(htons(extracted_ethertype)));
184 if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
185 /* Try to print the LLC-layer header & higher layers */
186 if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
187 &extracted_ethertype) == 0) {
188 /* ether_type not known, print raw packet */
189 if (!eflag)
190 token_print(trp,
191 length + TOKEN_HDRLEN + route_len,
192 ESRC(&ehdr), EDST(&ehdr));
193 if (extracted_ethertype) {
194 printf("(LLC %s) ",
195 etherproto_string(htons(extracted_ethertype)));
196 }
197 if (!xflag && !qflag)
198 default_print(p, caplen);
181 }
199 }
200 } else {
201 /* Some kinds of TR packet we cannot handle intelligently */
202 /* XXX - dissect MAC packets if frame type is 0 */
203 if (!eflag)
204 token_print(trp, length + TOKEN_HDRLEN + route_len,
205 ESRC(&ehdr), EDST(&ehdr));
182 if (!xflag && !qflag)
183 default_print(p, caplen);
184 }
185 if (xflag)
186 default_print(p, caplen);
206 if (!xflag && !qflag)
207 default_print(p, caplen);
208 }
209 if (xflag)
210 default_print(p, caplen);
187 out:
211out:
188 putchar('\n');
212 putchar('\n');
213 --infodelay;
214 if (infoprint)
215 info(0);
189}
216}