📄 _token.c
字号:
/*
* 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>
*
* $FreeBSD: src/contrib/tcpdump/print-token.c,v 1.3 2000/01/30 01:00:54 fenner Exp $
*/
#if 0
static const char rcsid[] =
"@(#) $Header: /home/ncvs/src/contrib/tcpdump/print-token.c,v 1.1 1999/02/20 11:17:55 julian Exp $";
#endif
#include <stdio.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include <pcap.h>
#include "token.h"
#include "interfac.h"
#include "a2name.h"
#include "ethertyp.h"
#include "llc.h"
static void token_print (const u_char * bp, u_int length)
{
struct token_header *tp;
struct llc *lp;
u_short ether_type;
tp = (struct token_header *) bp;
lp = (struct llc *) (bp + TOKEN_HDR_LEN);
if (IS_SOURCE_ROUTED(tp))
{
tp->ether_shost[0] = tp->ether_shost[0] & 0x7f;
lp = (struct llc *) (bp + TOKEN_HDR_LEN + RIF_LENGTH(tp));
}
/*
* Ethertype on ethernet is a short, but ethertype in an llc-snap has
* been defined as 2 u_chars. This is a stupid little hack to fix
* this for now but something better should be done using ntohs()
* XXX
*/
ether_type = ((u_short) lp->ethertype[1] << 16) | lp->ethertype[0];
if (qflag)
PRINTF ("%s %s %d: ",
etheraddr_string (ESRC (tp)),
etheraddr_string (EDST (tp)), length);
else PRINTF ("%s %s %s %d: ",
etheraddr_string (ESRC (tp)),
etheraddr_string (EDST (tp)),
etherproto_string (ether_type), length);
}
/*
* This is the top level routine of the printer. 'p' is the points
* to the ether header of the packet, 'tvp' is the timestamp,
* 'length' is the length of the packet off the wire, and 'caplen'
* is the number of bytes actually captured.
*/
void token_if_print (u_char *user, const struct pcap_pkthdr *h, const u_char *p)
{
struct token_header *tp = (struct token_header *) p;
struct llc *lp;
u_int caplen = h->caplen;
u_int length = h->len;
u_int route_len = 0, seg;
u_short ether_type;
ts_print (&h->ts);
if (caplen < TOKEN_HDR_LEN)
{
PUTS ("[|token-ring]");
goto out;
}
/*
* Some printers want to get back at the ethernet addresses,
* and/or check that they're not walking off the end of the packet.
* Rather than pass them all the way down, we set these globals.
*/
tp = (struct token_header *) p;
/* Adjust for source routing information in the MAC header
*/
if (IS_SOURCE_ROUTED(tp))
{
if (eflag)
token_print (p, length);
route_len = RIF_LENGTH(tp);
if (vflag)
{
if (vflag > 1)
PRINTF ("ac %x fc %x ", tp->ac, tp->fc);
ether_type = ntohs ((int) lp->ethertype);
PRINTF ("%s ", broadcast_indicator [BROADCAST(tp)]);
PRINTF ("%s", direction [DIRECTION(tp)]);
for (seg = 0; seg < SEGMENT_COUNT(tp); seg++)
PRINTF (" [%d:%d]", RING_NUMBER(tp,seg), BRIDGE_NUMBER(tp,seg));
}
else
{
PRINTF ("rt = %x", ntohs(tp->rcf));
for (seg = 0; seg < SEGMENT_COUNT(tp); seg++)
PRINTF (":%x", ntohs(tp->rseg[seg]));
}
PRINTF (" (%s) ", largest_frame[LARGEST_FRAME(tp)]);
}
else
{
if (eflag)
token_print (p, length);
}
/* Set pointer to llc header, adjusted for routing information
*/
lp = (struct llc*) (p + TOKEN_HDR_LEN + route_len);
packetp = p;
snapend = p + caplen;
/* Skip over token ring MAC header
*/
length -= TOKEN_HDR_LEN + route_len;
caplen -= TOKEN_HDR_LEN + route_len;
p += TOKEN_HDR_LEN + route_len;
extracted_ethertype = 0;
/* Try to print the LLC-layer header & higher layers
*/
if (llc_print (p, length, caplen, ESRC (tp), EDST (tp)) == 0)
{
/* ether_type not known, print raw packet
*/
if (!eflag)
token_print ((u_char *) tp, length);
if (extracted_ethertype)
PRINTF ("(LLC %s) ", etherproto_string (htons(extracted_ethertype)));
if (!xflag && !qflag)
default_print (p, caplen);
}
if (xflag)
default_print (p, caplen);
out:
PUTCHAR ('\n');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -