2000-07-25 13:28:11 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Hacked version of print-ether.c Larry Lile <lile@stdio.com>
|
|
|
|
*
|
|
|
|
* Further tweaked to more closely resemble print-fddi.c
|
|
|
|
* Guy Harris <guy@alum.mit.edu>
|
|
|
|
*/
|
2003-11-16 17:36:07 +08:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] _U_ =
|
2005-11-13 20:12:41 +08:00
|
|
|
"@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.27 2005-11-13 12:12:43 guy Exp $";
|
2003-11-16 17:36:07 +08:00
|
|
|
#endif
|
2000-07-25 13:28:11 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-08-01 16:52:55 +08:00
|
|
|
#include <tcpdump-stdinc.h>
|
2000-07-25 13:28:11 +08:00
|
|
|
|
|
|
|
#include <pcap.h>
|
|
|
|
#include <stdio.h>
|
2000-10-03 12:19:07 +08:00
|
|
|
#include <string.h>
|
2000-07-25 13:28:11 +08:00
|
|
|
|
|
|
|
#include "interface.h"
|
2010-02-21 16:27:00 +08:00
|
|
|
#include "extract.h"
|
2000-07-25 13:28:11 +08:00
|
|
|
#include "addrtoname.h"
|
|
|
|
#include "ethertype.h"
|
|
|
|
|
2000-09-23 16:03:27 +08:00
|
|
|
#include "ether.h"
|
2000-07-25 13:28:11 +08:00
|
|
|
#include "token.h"
|
|
|
|
|
|
|
|
/* Extract src, dst addresses */
|
|
|
|
static inline void
|
|
|
|
extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst)
|
|
|
|
{
|
2001-09-18 23:46:36 +08:00
|
|
|
memcpy(fdst, (const char *)trp->token_dhost, 6);
|
|
|
|
memcpy(fsrc, (const char *)trp->token_shost, 6);
|
2000-07-25 13:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the TR MAC header
|
|
|
|
*/
|
|
|
|
static inline void
|
2002-04-07 17:50:30 +08:00
|
|
|
token_hdr_print(register const struct token_header *trp, register u_int length,
|
2000-07-25 13:28:11 +08:00
|
|
|
register const u_char *fsrc, register const u_char *fdst)
|
|
|
|
{
|
2001-09-18 23:46:36 +08:00
|
|
|
const char *srcname, *dstname;
|
2000-07-25 13:28:11 +08:00
|
|
|
|
|
|
|
srcname = etheraddr_string(fsrc);
|
|
|
|
dstname = etheraddr_string(fdst);
|
|
|
|
|
|
|
|
if (vflag)
|
|
|
|
(void) printf("%02x %02x %s %s %d: ",
|
|
|
|
trp->token_ac,
|
|
|
|
trp->token_fc,
|
|
|
|
srcname, dstname,
|
|
|
|
length);
|
|
|
|
else
|
|
|
|
printf("%s %s %d: ", srcname, dstname, length);
|
|
|
|
}
|
|
|
|
|
2001-09-18 23:46:36 +08:00
|
|
|
static const char *broadcast_indicator[] = {
|
2000-07-25 13:28:11 +08:00
|
|
|
"Non-Broadcast", "Non-Broadcast",
|
|
|
|
"Non-Broadcast", "Non-Broadcast",
|
|
|
|
"All-routes", "All-routes",
|
|
|
|
"Single-route", "Single-route"
|
|
|
|
};
|
|
|
|
|
2001-09-18 23:46:36 +08:00
|
|
|
static const char *direction[] = {
|
2000-07-25 13:28:11 +08:00
|
|
|
"Forward", "Backward"
|
|
|
|
};
|
|
|
|
|
2001-09-18 23:46:36 +08:00
|
|
|
static const char *largest_frame[] = {
|
2000-07-25 13:28:11 +08:00
|
|
|
"516",
|
|
|
|
"1500",
|
|
|
|
"2052",
|
|
|
|
"4472",
|
|
|
|
"8144",
|
|
|
|
"11407",
|
|
|
|
"17800",
|
|
|
|
"??"
|
|
|
|
};
|
|
|
|
|
2002-05-29 18:06:24 +08:00
|
|
|
u_int
|
2002-04-07 17:50:30 +08:00
|
|
|
token_print(const u_char *p, u_int length, u_int caplen)
|
2000-07-25 13:28:11 +08:00
|
|
|
{
|
2001-09-18 23:46:36 +08:00
|
|
|
const struct token_header *trp;
|
2000-07-25 13:28:11 +08:00
|
|
|
u_short extracted_ethertype;
|
|
|
|
struct ether_header ehdr;
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
|
|
|
|
int seg;
|
2000-07-25 13:28:11 +08:00
|
|
|
|
2001-09-18 23:46:36 +08:00
|
|
|
trp = (const struct token_header *)p;
|
2000-07-25 13:28:11 +08:00
|
|
|
|
|
|
|
if (caplen < TOKEN_HDRLEN) {
|
|
|
|
printf("[|token-ring]");
|
2002-05-29 18:06:24 +08:00
|
|
|
return hdr_len;
|
2000-07-25 13:28:11 +08:00
|
|
|
}
|
2002-12-18 16:53:18 +08:00
|
|
|
|
2000-07-25 13:28:11 +08:00
|
|
|
/*
|
|
|
|
* Get the TR addresses into a canonical form
|
|
|
|
*/
|
|
|
|
extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));
|
2002-12-18 16:53:18 +08:00
|
|
|
|
2000-07-25 13:28:11 +08:00
|
|
|
/* Adjust for source routing information in the MAC header */
|
|
|
|
if (IS_SOURCE_ROUTED(trp)) {
|
|
|
|
/* Clear source-routed bit */
|
|
|
|
*ESRC(&ehdr) &= 0x7f;
|
|
|
|
|
|
|
|
if (eflag)
|
2002-04-07 17:50:30 +08:00
|
|
|
token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
|
2000-07-25 13:28:11 +08:00
|
|
|
|
2010-02-22 03:29:46 +08:00
|
|
|
if (caplen < TOKEN_HDRLEN + 2) {
|
|
|
|
printf("[|token-ring]");
|
|
|
|
return hdr_len;
|
|
|
|
}
|
2000-07-25 13:28:11 +08:00
|
|
|
route_len = RIF_LENGTH(trp);
|
2010-02-22 03:29:46 +08:00
|
|
|
hdr_len += route_len;
|
|
|
|
if (caplen < hdr_len) {
|
|
|
|
printf("[|token-ring]");
|
|
|
|
return hdr_len;
|
|
|
|
}
|
2000-07-25 13:28:11 +08:00
|
|
|
if (vflag) {
|
|
|
|
printf("%s ", broadcast_indicator[BROADCAST(trp)]);
|
|
|
|
printf("%s", direction[DIRECTION(trp)]);
|
2002-06-12 01:08:37 +08:00
|
|
|
|
2000-07-25 13:28:11 +08:00
|
|
|
for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
|
|
|
|
printf(" [%d:%d]", RING_NUMBER(trp, seg),
|
|
|
|
BRIDGE_NUMBER(trp, seg));
|
|
|
|
} else {
|
2010-02-21 16:27:00 +08:00
|
|
|
printf("rt = %x", EXTRACT_16BITS(&trp->token_rcf));
|
2002-06-12 01:08:37 +08:00
|
|
|
|
2000-07-25 13:28:11 +08:00
|
|
|
for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
|
2010-02-21 16:27:00 +08:00
|
|
|
printf(":%x", EXTRACT_16BITS(&trp->token_rseg[seg]));
|
2000-07-25 13:28:11 +08:00
|
|
|
}
|
|
|
|
printf(" (%s) ", largest_frame[LARGEST_FRAME(trp)]);
|
|
|
|
} else {
|
|
|
|
if (eflag)
|
2002-04-07 17:50:30 +08:00
|
|
|
token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
|
2000-07-25 13:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip over token ring MAC header and routing information */
|
2002-05-29 18:06:24 +08:00
|
|
|
length -= hdr_len;
|
|
|
|
p += hdr_len;
|
|
|
|
caplen -= hdr_len;
|
2000-07-25 13:28:11 +08:00
|
|
|
|
|
|
|
/* Frame Control field determines interpretation of packet */
|
|
|
|
if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
|
|
|
|
/* Try to print the LLC-layer header & higher layers */
|
2000-12-18 13:41:58 +08:00
|
|
|
if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
|
|
|
|
&extracted_ethertype) == 0) {
|
2000-07-25 13:28:11 +08:00
|
|
|
/* ether_type not known, print raw packet */
|
|
|
|
if (!eflag)
|
2002-04-07 17:50:30 +08:00
|
|
|
token_hdr_print(trp,
|
Put the LINUX_SLL_P_ definitions back, and check for at least some of
them in "print-sll.c" - as a cooked-mode capture may be reading from
non-Ethernet, non-802.x devices, it may well see some
ETH_P_/LINUX_SLL_P_ types that don't mean "this is an 802.2 LLC frame".
We currently assume that the ETH_P_ values won't change in the kernel,
so we don't have to explicitly map them.
In various link-layer packet printers, if we don't handle the next layer
up of packet type, and are printing the link-layer header, use the
correct pointer to that header (i.e., if we've stepped "p" past the
link-layer header, don't use "p", use a pointer to the beginning of the
packet), and use the correct length (i.e., if we've subtracted the
length of the link-layer header, add it back in, so that we always print
the full packet length).
2000-12-23 06:45:09 +08:00
|
|
|
length + TOKEN_HDRLEN + route_len,
|
2000-07-25 13:28:11 +08:00
|
|
|
ESRC(&ehdr), EDST(&ehdr));
|
|
|
|
if (extracted_ethertype) {
|
|
|
|
printf("(LLC %s) ",
|
|
|
|
etherproto_string(htons(extracted_ethertype)));
|
|
|
|
}
|
2005-07-07 09:22:15 +08:00
|
|
|
if (!suppress_default_print)
|
2000-07-25 13:28:11 +08:00
|
|
|
default_print(p, caplen);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Some kinds of TR packet we cannot handle intelligently */
|
|
|
|
/* XXX - dissect MAC packets if frame type is 0 */
|
|
|
|
if (!eflag)
|
2002-04-07 17:50:30 +08:00
|
|
|
token_hdr_print(trp, length + TOKEN_HDRLEN + route_len,
|
Put the LINUX_SLL_P_ definitions back, and check for at least some of
them in "print-sll.c" - as a cooked-mode capture may be reading from
non-Ethernet, non-802.x devices, it may well see some
ETH_P_/LINUX_SLL_P_ types that don't mean "this is an 802.2 LLC frame".
We currently assume that the ETH_P_ values won't change in the kernel,
so we don't have to explicitly map them.
In various link-layer packet printers, if we don't handle the next layer
up of packet type, and are printing the link-layer header, use the
correct pointer to that header (i.e., if we've stepped "p" past the
link-layer header, don't use "p", use a pointer to the beginning of the
packet), and use the correct length (i.e., if we've subtracted the
length of the link-layer header, add it back in, so that we always print
the full packet length).
2000-12-23 06:45:09 +08:00
|
|
|
ESRC(&ehdr), EDST(&ehdr));
|
2005-07-07 09:22:15 +08:00
|
|
|
if (!suppress_default_print)
|
2000-07-25 13:28:11 +08:00
|
|
|
default_print(p, caplen);
|
|
|
|
}
|
2002-05-29 18:06:24 +08:00
|
|
|
return (hdr_len);
|
2002-04-07 17:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-06 05:25:34 +08:00
|
|
|
* This is the top level routine of the printer. 'p' points
|
|
|
|
* to the TR header of the packet, 'h->ts' is the timestamp,
|
2004-03-18 07:24:35 +08:00
|
|
|
* 'h->len' is the length of the packet off the wire, and 'h->caplen'
|
2002-04-07 17:50:30 +08:00
|
|
|
* is the number of bytes actually captured.
|
|
|
|
*/
|
2002-12-19 17:39:10 +08:00
|
|
|
u_int
|
|
|
|
token_if_print(const struct pcap_pkthdr *h, const u_char *p)
|
2002-04-07 17:50:30 +08:00
|
|
|
{
|
2002-12-19 17:39:10 +08:00
|
|
|
return (token_print(p, h->len, h->caplen));
|
2000-07-25 13:28:11 +08:00
|
|
|
}
|