minimize diffs to tcpdump.org tree, even if cosmetic.

changes include:
- do not chase header if ip/ip6 datagram is framgented, and it is not the
  first fragment
- u_short -> u_int16_t
- buffer boundary checks, including sprintf -> snprintf
- cleanup truncated packet cases
- pull tcpdump.org enhancements/corrections for RIP, IPv6 options, ICMPv6,
  OSPFv3, IPv4 options, BGP

there are a lot of local/conflicting changes.  we'd gradually decrease
# of diffs by synchronizing both ends, and then move to src/dist/tcpdump
and reachover makefile.
This commit is contained in:
itojun 2001-01-28 10:05:05 +00:00
parent 3915684b18
commit ca89dc0998
27 changed files with 1410 additions and 499 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: interface.h,v 1.16 2001/01/19 09:10:13 kleink Exp $ */
/* $NetBSD: interface.h,v 1.17 2001/01/28 10:05:05 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -161,6 +161,7 @@ struct timeval;
#endif
extern void ts_print(const struct timeval *);
extern void relts_print(int);
extern int fn_print(const u_char *, const u_char *);
extern int fn_printn(const u_char *, u_int, const u_char *);
@ -250,11 +251,11 @@ extern void sl_bsdos_if_print(u_char *, const struct pcap_pkthdr *,
const u_char *);
extern void snmp_print(const u_char *, u_int);
extern void sunrpcrequest_print(const u_char *, u_int, const u_char *);
extern void tcp_print(const u_char *, u_int, const u_char *);
extern void tcp_print(const u_char *, u_int, const u_char *, int);
extern void tftp_print(const u_char *, u_int);
extern void token_if_print(u_char *, const struct pcap_pkthdr *,
const u_char *);
extern void udp_print(const u_char *, u_int, const u_char *);
extern void udp_print(const u_char *, u_int, const u_char *, int);
extern void vrrp_print(const u_char *, u_int, const u_char *);
extern void wb_print(const void *, u_int);
extern void hdlc_if_print(u_char *, const struct pcap_pkthdr *,

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntp.h,v 1.3 1997/10/03 19:54:47 christos Exp $ */
/* $NetBSD: ntp.h,v 1.4 2001/01/28 10:05:05 itojun Exp $ */
/* Header: ntp.h,v 1.3 95/05/04 17:52:49 mccanne Exp */
@ -35,8 +35,8 @@ struct l_fixedpt {
};
struct s_fixedpt {
u_short int_part;
u_short fraction;
u_int16_t int_part;
u_int16_t fraction;
};
/* ================= Table 3.3. Packet Variables ================= */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ospf.h,v 1.3 1997/10/03 19:54:50 christos Exp $ */
/* $NetBSD: ospf.h,v 1.4 2001/01/28 10:05:05 itojun Exp $ */
/*
* Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
@ -93,14 +93,14 @@
/* link state advertisement header */
struct lsa_hdr {
u_short ls_age;
u_char ls_options;
u_char ls_type;
u_int16_t ls_age;
u_int8_t ls_options;
u_int8_t ls_type;
struct in_addr ls_stateid;
struct in_addr ls_router;
u_int32_t ls_seq;
u_short ls_chksum;
u_short ls_length;
u_int16_t ls_chksum;
u_int16_t ls_length;
} ;
/* link state advertisement */
@ -111,15 +111,15 @@ struct lsa {
union {
/* Router links advertisements */
struct {
u_char rla_flags;
u_char rla_zero[1];
u_short rla_count;
u_int8_t rla_flags;
u_int8_t rla_zero[1];
u_int16_t rla_count;
struct rlalink {
struct in_addr link_id;
struct in_addr link_data;
u_char link_type;
u_char link_toscount;
u_short link_tos0metric;
u_int8_t link_type;
u_int8_t link_toscount;
u_int16_t link_tos0metric;
} rla_link[1]; /* may repeat */
} un_rla;
@ -158,9 +158,9 @@ struct lsa {
* TOS metric struct (will be 0 or more in router links update)
*/
struct tos_metric {
u_char tos_type;
u_char tos_zero;
u_short tos_metric;
u_int8_t tos_type;
u_int8_t tos_zero;
u_int16_t tos_metric;
} ;
#define OSPF_AUTH_SIZE 8
@ -169,22 +169,22 @@ struct tos_metric {
* the main header
*/
struct ospfhdr {
u_char ospf_version;
u_char ospf_type;
u_short ospf_len;
u_int8_t ospf_version;
u_int8_t ospf_type;
u_int16_t ospf_len;
struct in_addr ospf_routerid;
struct in_addr ospf_areaid;
u_short ospf_chksum;
u_short ospf_authtype;
u_char ospf_authdata[OSPF_AUTH_SIZE];
u_int16_t ospf_chksum;
u_int16_t ospf_authtype;
u_int8_t ospf_authdata[OSPF_AUTH_SIZE];
union {
/* Hello packet */
struct {
struct in_addr hello_mask;
u_short hello_helloint;
u_char hello_options;
u_char hello_priority;
u_int16_t hello_helloint;
u_int8_t hello_options;
u_int8_t hello_priority;
u_int32_t hello_deadint;
struct in_addr hello_dr;
struct in_addr hello_bdr;
@ -193,9 +193,9 @@ struct ospfhdr {
/* Database Description packet */
struct {
u_char db_zero[2];
u_char db_options;
u_char db_flags;
u_int8_t db_zero[2];
u_int8_t db_options;
u_int8_t db_flags;
u_int32_t db_seq;
struct lsa_hdr db_lshdr[1]; /* may repeat */
} un_db;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ospf6.h,v 1.2 1999/07/04 02:57:51 itojun Exp $ */
/* $NetBSD: ospf6.h,v 1.3 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
@ -85,10 +85,10 @@
#define SLA_MASK_METRIC 0x00ffffff
#define SLA_SHIFT_TOS 24
/* asla_tosmetric breakdown */
#define ASLA_FLAG_EXTERNAL 0x80000000
#define ASLA_MASK_TOS 0x7f000000
#define ASLA_SHIFT_TOS 24
/* asla_metric */
#define ASLA_FLAG_EXTERNAL 0x04000000
#define ASLA_FLAG_FWDADDR 0x02000000
#define ASLA_FLAG_ROUTETAG 0x01000000
#define ASLA_MASK_METRIC 0x00ffffff
/* multicast vertex type */
@ -151,6 +151,13 @@ struct lsa {
struct lsa_prefix inter_ap_prefix[1];
} un_inter_ap;
/* AS external links advertisements */
struct {
u_int32_t asla_metric;
struct lsa_prefix asla_prefix[1];
/* some optional fields follow */
} un_asla;
#if 0
/* Summary links advertisements */
struct {
@ -158,16 +165,6 @@ struct lsa {
u_int32_t sla_tosmetric[1]; /* may repeat */
} un_sla;
/* AS external links advertisements */
struct {
struct in_addr asla_mask;
struct aslametric {
u_int32_t asla_tosmetric;
struct in_addr asla_forward;
struct in_addr asla_tag;
} asla_metric[1]; /* may repeat */
} un_asla;
/* Multicast group membership */
struct mcla {
u_int32_t mcla_vtype;

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ah.c,v 1.3 1999/09/04 03:36:41 itojun Exp $ */
/* $NetBSD: print-ah.c,v 1.4 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
@ -27,7 +27,7 @@ static const char rcsid[] =
"@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-ah.c,v 1.3 1999/09/04 03:36:41 itojun Exp $");
__RCSID("$NetBSD: print-ah.c,v 1.4 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -65,7 +65,7 @@ ah_print(register const u_char *bp, register const u_char *bp2)
u_int32_t spi;
ah = (struct ah *)bp;
ep = snapend; /* 'ep' points to the end of avaible data. */
ep = snapend; /* 'ep' points to the end of available data. */
if ((u_char *)(ah + 1) >= ep - sizeof(struct ah))
goto trunc;
@ -73,11 +73,10 @@ ah_print(register const u_char *bp, register const u_char *bp2)
sumlen = ah->ah_len << 2;
spi = (u_int32_t)ntohl(ah->ah_spi);
printf("AH(spi=%u", spi);
printf("AH(spi=0x%08x", spi);
if (vflag)
printf(",sumlen=%d", sumlen);
if (Rflag)
printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(ah + 1)));
printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(ah + 1)));
if (bp + sizeof(struct ah) + sumlen > ep)
fputs("[truncated]", stdout);
fputs("): ", stdout);

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ascii.c,v 1.1 1999/09/30 14:49:12 sjg Exp $ */
/* $NetBSD: print-ascii.c,v 1.2 2001/01/28 10:05:06 itojun Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: print-ascii.c,v 1.1 1999/09/30 14:49:12 sjg Exp $");
__RCSID("$NetBSD: print-ascii.c,v 1.2 2001/01/28 10:05:06 itojun Exp $");
#endif
#include <stdio.h>
#include <sys/types.h>
@ -68,7 +68,8 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
while (--nshorts >= 0) {
s1 = *cp++;
s2 = *cp++;
(void)sprintf(hsp, " %02x%02x", s1, s2);
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x%02x", s1, s2);
hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
*(asp++) = (isgraph(s1) ? s1 : '.');
*(asp++) = (isgraph(s2) ? s2 : '.');
@ -83,7 +84,8 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
}
if (length & 1) {
s1 = *cp++;
(void)sprintf(hsp, " %02x", s1);
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x", s1);
hsp += 3;
*(asp++) = (isgraph(s1) ? s1 : '.');
++i;

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-bgp.c,v 1.2 1999/12/11 18:20:27 thorpej Exp $ */
/* $NetBSD: print-bgp.c,v 1.3 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (C) 1999 WIDE Project.
@ -44,9 +44,11 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include "interface.h"
#include "addrtoname.h"
#include "extract.h"
struct bgp {
u_int8_t bgp_marker[16];
@ -72,6 +74,12 @@ struct bgp_open {
/* options should follow */
};
struct bgp_opt {
u_int8_t bgpopt_type;
u_int8_t bgpopt_len;
/* variable length */
};
struct bgp_notification {
u_int8_t bgpn_marker[16];
u_int16_t bgpn_len;
@ -117,6 +125,12 @@ static const char *bgptype[] = {
};
#define bgp_type(x) num_or_str(bgptype, sizeof(bgptype)/sizeof(bgptype[0]), (x))
static const char *bgpopt_type[] = {
NULL, "Authentication Information",
};
#define bgp_opttype(x) \
num_or_str(bgpopt_type, sizeof(bgpopt_type)/sizeof(bgpopt_type[0]), (x))
static const char *bgpnotify_major[] = {
NULL, "Message Header Error",
"OPEN Message Error", "UPDATE Message Error",
@ -167,8 +181,8 @@ static const char *bgpattr_origin[] = {
static const char *bgpattr_type[] = {
NULL, "ORIGIN", "AS_PATH", "NEXT_HOP",
"MULTI_EXIT_DISC", "LOCAL_PREF", "ATOMIC_AGGREGATE", "AGGREGATOR",
NULL, NULL, NULL, NULL,
NULL, NULL, "MP_REACH_NLRI", "MP_UNREACH_NLRI",
"COMMUNITIES", "ORIGINATOR_ID", "CLUSTER_LIST", "DPA",
"ADVERTISERS", "RCID_PATH", "MP_REACH_NLRI", "MP_UNREACH_NLRI",
};
#define bgp_attr_type(x) \
num_or_str(bgpattr_type, \
@ -176,12 +190,17 @@ static const char *bgpattr_type[] = {
/* Subsequent address family identifier, RFC2283 section 7 */
static const char *bgpattr_nlri_safi[] = {
"Reserved", "Unicast", "Multicast", "Unicast+Multicast",
"Reserved", "Unicast", "Multicast", "Unicast+Multicast",
};
#define bgp_attr_nlri_safi(x) \
num_or_str(bgpattr_nlri_safi, \
sizeof(bgpattr_nlri_safi)/sizeof(bgpattr_nlri_safi[0]), (x))
/* well-known community */
#define BGP_COMMUNITY_NO_EXPORT 0xffffff01
#define BGP_COMMUNITY_NO_ADVERT 0xffffff02
#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
/* RFC1700 address family numbers */
#define AFNUM_INET 1
#define AFNUM_INET6 2
@ -264,7 +283,7 @@ decode_prefix4(const u_char *pd, char *buf, int buflen)
((u_char *)&addr)[(plen + 7) / 8 - 1] &=
((0xff00 >> (plen % 8)) & 0xff);
}
snprintf(buf, buflen, "%s/%d", getname((char *)&addr), plen);
snprintf(buf, buflen, "%s/%d", getname((u_char *)&addr), plen);
return 1 + (plen + 7) / 8;
}
@ -299,7 +318,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
int advance;
int tlen;
const u_char *p;
char buf[256];
char buf[MAXHOSTNAMELEN + 100];
p = dat;
@ -316,13 +335,20 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
break;
}
while (p < dat + len) {
/*
* under RFC1965, p[0] means:
* 1: AS_SET 2: AS_SEQUENCE
* 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
*/
printf(" ");
printf("%s", (p[0] == 1) ? "{" : "");
if (p[0] == 3 || p[0] == 4)
printf("confed");
printf("%s", (p[0] & 1) ? "{" : "");
for (i = 0; i < p[1]; i += 2) {
printf("%s%u", i == 0 ? "" : " ",
ntohs(*(u_int16_t *)&p[2 + i]));
}
printf("%s", (p[0] == 1) ? "}" : "");
printf("%s", (p[0] & 1) ? "}" : "");
p += 2 + p[1] * 2;
}
break;
@ -351,6 +377,31 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
printf(" AS #%u, origin %s", ntohs(*(u_int16_t *)p),
getname(p + 2));
break;
case BGPTYPE_COMMUNITIES:
if (len % 4) {
printf(" invalid len");
break;
}
for (i = 0; i < len; i += 4) {
u_int32_t comm;
comm = (u_int32_t)ntohl(*(u_int32_t *)&p[i]);
switch (comm) {
case BGP_COMMUNITY_NO_EXPORT:
printf(" NO_EXPORT");
break;
case BGP_COMMUNITY_NO_ADVERT:
printf(" NO_ADVERTISE");
break;
case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
printf(" NO_EXPORT_SUBCONFED");
break;
default:
printf(" (AS #%d value 0x%04x)",
(comm >> 16) & 0xffff, comm & 0xffff);
break;
}
}
break;
case BGPTYPE_MP_REACH_NLRI:
af = ntohs(*(u_int16_t *)p);
safi = p[2];
@ -374,20 +425,24 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
tlen = p[0];
if (tlen) {
printf(" nexthop");
if (af == AFNUM_INET)
advance = 4;
#ifdef INET6
else if (af == AFNUM_INET6)
advance = 16;
#endif
for (i = 0; i < tlen; i += advance) {
if (af == AFNUM_INET)
i = 0;
while (i < tlen) {
switch (af) {
case AFNUM_INET:
printf(" %s", getname(p + 1 + i));
i += sizeof(struct in_addr);
break;
#ifdef INET6
else if (af == AFNUM_INET6)
case AFNUM_INET6:
printf(" %s", getname6(p + 1 + i));
i += sizeof(struct in6_addr);
break;
#endif
default:
printf(" (unknown af)");
i = tlen; /*exit loop*/
break;
}
}
printf(",");
}
@ -406,13 +461,23 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
printf(" NLRI");
while (len - (p - dat) > 0) {
if (af == AFNUM_INET)
switch (af) {
case AFNUM_INET:
advance = decode_prefix4(p, buf, sizeof(buf));
printf(" %s", buf);
break;
#ifdef INET6
else if (af == AFNUM_INET6)
case AFNUM_INET6:
advance = decode_prefix6(p, buf, sizeof(buf));
printf(" %s", buf);
break;
#endif
printf(" %s", buf);
default:
printf(" (unknown af)");
advance = 0;
p = dat + len;
break;
}
p += advance;
}
@ -432,13 +497,23 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len)
printf(" Withdraw");
while (len - (p - dat) > 0) {
if (af == AFNUM_INET)
switch (af) {
case AFNUM_INET:
advance = decode_prefix4(p, buf, sizeof(buf));
printf(" %s", buf);
break;
#ifdef INET6
else if (af == AFNUM_INET6)
case AFNUM_INET6:
advance = decode_prefix6(p, buf, sizeof(buf));
printf(" %s", buf);
break;
#endif
printf(" %s", buf);
default:
printf(" (unknown af)");
advance = 0;
p = dat + len;
break;
}
p += advance;
}
@ -452,16 +527,39 @@ static void
bgp_open_print(const u_char *dat, int length)
{
struct bgp_open bgpo;
struct bgp_opt bgpopt;
int hlen;
const u_char *opt;
int i;
TCHECK2(dat[0], sizeof(bgpo));
memcpy(&bgpo, dat, sizeof(bgpo));
hlen = ntohs(bgpo.bgpo_len);
printf(": Version %d,", bgpo.bgpo_version);
printf(" AS #%u,", ntohs(bgpo.bgpo_myas));
printf(" Holdtime %u,", ntohs(bgpo.bgpo_holdtime));
printf(" ID %s,", getname((char *)&bgpo.bgpo_id));
printf(" ID %s,", getname((u_char *)&bgpo.bgpo_id));
printf(" Option length %u", bgpo.bgpo_optlen);
/* ugly! */
opt = &((struct bgp_open *)dat)->bgpo_optlen;
opt++;
for (i = 0; i < bgpo.bgpo_optlen; i++) {
memcpy(&bgpopt, &opt[i], sizeof(bgpopt));
if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
printf(" [|opt %d %d]", bgpopt.bgpopt_len, bgpopt.bgpopt_type);
break;
}
printf(" (option %s, len=%d)", bgp_opttype(bgpopt.bgpopt_type),
bgpopt.bgpopt_len);
i += sizeof(bgpopt) + bgpopt.bgpopt_len;
}
return;
trunc:
printf("[|BGP]");
}
static void
@ -475,19 +573,41 @@ bgp_update_print(const u_char *dat, int length)
int i;
int newline;
TCHECK2(dat[0], sizeof(bgp));
memcpy(&bgp, dat, sizeof(bgp));
hlen = ntohs(bgp.bgp_len);
p = dat + BGP_SIZE; /*XXX*/
printf(":");
/* Unfeasible routes */
len = ntohs(*(u_int16_t *)p);
len = EXTRACT_16BITS(p);
if (len) {
/*
* Without keeping state from the original NLRI message,
* it's not possible to tell if this a v4 or v6 route,
* so only try to decode it if we're not v6 enabled.
*/
#ifdef INET6
printf(" (Withdrawn routes: %d bytes)", len);
#else
char buf[MAXHOSTNAMELEN + 100];
TCHECK2(p[2], len);
i = 2;
printf(" (Withdrawn routes:");
while(i < 2 + len) {
i += decode_prefix4(&p[i], buf, sizeof(buf));
printf(" %s", buf);
}
printf(")\n");
#endif
}
p += 2 + len;
len = ntohs(*(u_int16_t *)p);
TCHECK2(p[0], 2);
len = EXTRACT_16BITS(p);
if (len) {
/* do something more useful!*/
i = 2;
@ -496,6 +616,7 @@ bgp_update_print(const u_char *dat, int length)
while (i < 2 + len) {
int alen, aoff;
TCHECK2(p[i], sizeof(bgpa));
memcpy(&bgpa, &p[i], sizeof(bgpa));
alen = bgp_attr_len(&bgpa);
aoff = bgp_attr_off(&bgpa);
@ -507,11 +628,14 @@ bgp_update_print(const u_char *dat, int length)
printf("("); /* ) */
printf("%s", bgp_attr_type(bgpa.bgpa_type));
if (bgpa.bgpa_flags) {
printf("[%s%s%s%s]",
printf("[%s%s%s%s",
bgpa.bgpa_flags & 0x80 ? "O" : "",
bgpa.bgpa_flags & 0x40 ? "T" : "",
bgpa.bgpa_flags & 0x20 ? "P" : "",
bgpa.bgpa_flags & 0x00 ? "E" : "");
bgpa.bgpa_flags & 0x10 ? "E" : "");
if (bgpa.bgpa_flags & 0xf)
printf("+%x", bgpa.bgpa_flags & 0xf);
printf("]");
}
bgp_attr_print(&bgpa, &p[i + aoff], alen);
@ -533,7 +657,7 @@ bgp_update_print(const u_char *dat, int length)
if (dat + length > p) {
printf("(NLRI:"); /* ) */
while (dat + length > p) {
char buf[256];
char buf[MAXHOSTNAMELEN + 100];
i = decode_prefix4(p, buf, sizeof(buf));
printf(" %s", buf);
if (i < 0)
@ -544,6 +668,9 @@ bgp_update_print(const u_char *dat, int length)
/* ( */
printf(")");
}
return;
trunc:
printf("[|BGP]");
}
static void
@ -552,12 +679,16 @@ bgp_notification_print(const u_char *dat, int length)
struct bgp_notification bgpn;
int hlen;
TCHECK2(dat[0], sizeof(bgpn));
memcpy(&bgpn, dat, sizeof(bgpn));
hlen = ntohs(bgpn.bgpn_len);
printf(": error %s,", bgp_notify_major(bgpn.bgpn_major));
printf(" subcode %s",
bgp_notify_minor(bgpn.bgpn_major, bgpn.bgpn_minor));
return;
trunc:
printf("[|BGP]");
}
static void
@ -565,6 +696,7 @@ bgp_header_print(const u_char *dat, int length)
{
struct bgp bgp;
TCHECK2(dat[0], sizeof(bgp));
memcpy(&bgp, dat, sizeof(bgp));
printf("(%s", bgp_type(bgp.bgp_type)); /* ) */
@ -582,6 +714,9 @@ bgp_header_print(const u_char *dat, int length)
/* ( */
printf(")");
return;
trunc:
printf("[|BGP]");
}
void
@ -623,7 +758,7 @@ bgp_print(const u_char *dat, int length)
}
/* found BGP header */
TCHECK2(p[0], BGP_SIZE); /*XXX*/
TCHECK2(p[0], sizeof(bgp)); /*XXX*/
memcpy(&bgp, p, sizeof(bgp));
if (start != p)
@ -635,7 +770,6 @@ bgp_print(const u_char *dat, int length)
else
printf(" ");
if (TTEST2(p[0], hlen)) {
if (vflag && newline)
bgp_header_print(p, hlen);
newline = 1;
p += hlen;

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-decnet.c,v 1.3 1997/10/03 19:55:05 christos Exp $ */
/* $NetBSD: print-decnet.c,v 1.4 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-decnet.c,v 1.26 97/05/28 12:51:29 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-decnet.c,v 1.3 1997/10/03 19:55:05 christos Exp $");
__RCSID("$NetBSD: print-decnet.c,v 1.4 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -743,13 +743,14 @@ char *
dnnum_string(u_short dnaddr)
{
char *str;
size_t siz;
int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
int node = dnaddr & NODEMASK;
str = (char *)malloc(sizeof("00.0000"));
str = (char *)malloc(siz = sizeof("00.0000"));
if (str == NULL)
error("dnnum_string: malloc");
sprintf(str, "%d.%d", area, node);
snprintf(str, siz, "%d.%d", area, node);
return(str);
}
@ -761,7 +762,7 @@ dnname_string(u_short dnaddr)
dna.a_len = sizeof(short);
memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short));
return (savestr(dnet_htoa(&dna)));
return (strdup(dnet_htoa(&dna)));
#else
return(dnnum_string(dnaddr)); /* punt */
#endif
@ -776,10 +777,7 @@ pdata(u_char *dp, u_int maxlen)
while (x-- > 0) {
c = *dp++;
if (isprint(c))
putchar(c);
else
printf("\\%o", c & 0xFF);
safeputchar(c);
}
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-esp.c,v 1.3 1999/09/04 03:36:41 itojun Exp $ */
/* $NetBSD: print-esp.c,v 1.4 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
@ -27,7 +27,7 @@ static const char rcsid[] =
"@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-esp.c,v 1.3 1999/09/04 03:36:41 itojun Exp $");
__RCSID("$NetBSD: print-esp.c,v 1.4 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -81,16 +81,15 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr)
esp = (struct esp *)bp;
spi = (u_int32_t)ntohl(esp->esp_spi);
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
if ((u_char *)(esp + 1) >= ep - sizeof(struct esp)) {
fputs("[|ESP]", stdout);
goto fail;
}
printf("ESP(spi=%u", spi);
if (Rflag)
printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(esp + 1)));
printf("ESP(spi=0x%08x", spi);
printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(esp + 1)));
printf(")");
fail:

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-icmp.c,v 1.7 2000/10/31 12:17:07 he Exp $ */
/* $NetBSD: print-icmp.c,v 1.8 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-icmp.c,v 1.38 96/09/26 23:36:44 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-icmp.c,v 1.7 2000/10/31 12:17:07 he Exp $");
__RCSID("$NetBSD: print-icmp.c,v 1.8 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -49,20 +49,135 @@ struct rtentry;
#endif
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h> /* for MAXHOSTNAMELEN on some platforms */
#include "interface.h"
#include "addrtoname.h"
#include "extract.h" /* must come after interface.h */
/*
* Interface Control Message Protocol Definitions.
* Per RFC 792, September 1981.
*/
/*
* Structure of an icmp header.
*/
struct icmp {
u_int8_t icmp_type; /* type of message, see below */
u_int8_t icmp_code; /* type sub code */
u_int16_t icmp_cksum; /* ones complement cksum of struct */
union {
u_int8_t ih_pptr; /* ICMP_PARAMPROB */
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq {
u_int16_t icd_id;
u_int16_t icd_seq;
} ih_idseq;
u_int32_t ih_void;
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
struct ih_pmtu {
u_int16_t ipm_void;
u_int16_t ipm_nextmtu;
} ih_pmtu;
} icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr
#define icmp_gwaddr icmp_hun.ih_gwaddr
#define icmp_id icmp_hun.ih_idseq.icd_id
#define icmp_seq icmp_hun.ih_idseq.icd_seq
#define icmp_void icmp_hun.ih_void
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
union {
struct id_ts {
u_int32_t its_otime;
u_int32_t its_rtime;
u_int32_t its_ttime;
} id_ts;
struct id_ip {
struct ip idi_ip;
/* options and then 64 bits of data */
} id_ip;
u_int32_t id_mask;
u_int8_t id_data[1];
} icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime
#define icmp_rtime icmp_dun.id_ts.its_rtime
#define icmp_ttime icmp_dun.id_ts.its_ttime
#define icmp_ip icmp_dun.id_ip.idi_ip
#define icmp_mask icmp_dun.id_mask
#define icmp_data icmp_dun.id_data
};
/*
* Lower bounds on packet lengths for various types.
* For the error advice packets must first insure that the
* packet is large enought to contain the returned ip header.
* Only then can we do the check to see if 64 bits of packet
* data have been returned, since we need to check the returned
* ip header length.
*/
#define ICMP_MINLEN 8 /* abs minimum */
#define ICMP_TSLEN (8 + 3 * sizeof (u_int32_t)) /* timestamp */
#define ICMP_MASKLEN 12 /* address mask */
#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
#define ICMP_ADVLEN(p) (8 + (IP_HL(&(p)->icmp_ip) << 2) + 8)
/* N.B.: must separately check that ip_hl >= 5 */
/*
* Definition of type and code field values.
*/
#define ICMP_ECHOREPLY 0 /* echo reply */
#define ICMP_UNREACH 3 /* dest unreachable, codes: */
#define ICMP_UNREACH_NET 0 /* bad net */
#define ICMP_UNREACH_HOST 1 /* bad host */
#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
#define ICMP_UNREACH_PORT 3 /* bad port */
#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */
#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */
#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */
#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */
#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */
#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */
#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */
#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
#define ICMP_REDIRECT 5 /* shorter route, codes: */
#define ICMP_REDIRECT_NET 0 /* for network */
#define ICMP_REDIRECT_HOST 1 /* for host */
#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
#define ICMP_ECHO 8 /* echo service */
#define ICMP_ROUTERADVERT 9 /* router advertisement */
#define ICMP_ROUTERSOLICIT 10 /* router solicitation */
#define ICMP_TIMXCEED 11 /* time exceeded, code: */
#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
#define ICMP_PARAMPROB 12 /* ip header bad */
#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */
#define ICMP_TSTAMP 13 /* timestamp request */
#define ICMP_TSTAMPREPLY 14 /* timestamp reply */
#define ICMP_IREQ 15 /* information request */
#define ICMP_IREQREPLY 16 /* information reply */
#define ICMP_MASKREQ 17 /* address mask request */
#define ICMP_MASKREPLY 18 /* address mask reply */
#define ICMP_MAXTYPE 18
#define ICMP_INFOTYPE(type) \
((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
/* rfc1700 */
#ifndef ICMP_UNREACH_NET_UNKNOWN
#define ICMP_UNREACH_NET_UNKNOWN 6 /* destination net unknown */
@ -97,14 +212,6 @@ struct rtentry;
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */
#endif
/* rfc1256 */
#ifndef ICMP_ROUTERADVERT
#define ICMP_ROUTERADVERT 9 /* router advertisement */
#endif
#ifndef ICMP_ROUTERSOLICIT
#define ICMP_ROUTERSOLICIT 10 /* router solicitation */
#endif
/* Most of the icmp types */
static struct tok icmp2str[] = {
{ ICMP_ECHOREPLY, "echo reply" },
@ -157,15 +264,15 @@ static struct tok type2str[] = {
/* rfc1191 */
struct mtu_discovery {
short unused;
short nexthopmtu;
u_int16_t unused;
u_int16_t nexthopmtu;
};
/* rfc1256 */
struct ih_rdiscovery {
u_char ird_addrnum;
u_char ird_addrsiz;
u_short ird_lifetime;
u_int8_t ird_addrnum;
u_int8_t ird_addrsiz;
u_int16_t ird_lifetime;
};
struct id_rdiscovery {
@ -190,7 +297,7 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
str = buf;
#if 0
(void)printf("%s > %s: ",
(void)printf("%s > %s: ",
ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
#endif
@ -205,9 +312,9 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
case ICMP_UNREACH_PROTOCOL:
TCHECK(dp->icmp_ip.ip_p);
(void)snprintf(buf, sizeof(buf),
"%s protocol %d unreachable",
ipaddr_string(&dp->icmp_ip.ip_dst),
dp->icmp_ip.ip_p);
"%s protocol %d unreachable",
ipaddr_string(&dp->icmp_ip.ip_dst),
dp->icmp_ip.ip_p);
break;
case ICMP_UNREACH_PORT:
@ -242,20 +349,20 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
break;
case ICMP_UNREACH_NEEDFRAG:
{
{
register const struct mtu_discovery *mp;
mp = (struct mtu_discovery *)&dp->icmp_void;
mtu = EXTRACT_16BITS(&mp->nexthopmtu);
if (mtu)
(void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %d)",
ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
else
(void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag",
ipaddr_string(&dp->icmp_ip.ip_dst));
mtu = EXTRACT_16BITS(&mp->nexthopmtu);
if (mtu) {
(void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %d)",
ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
} else {
(void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag",
ipaddr_string(&dp->icmp_ip.ip_dst));
}
}
break;
default:
@ -277,53 +384,54 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
break;
case ICMP_ROUTERADVERT:
{
{
register const struct ih_rdiscovery *ihp;
register const struct id_rdiscovery *idp;
u_int lifetime, num, size;
(void)strcpy(buf, "router advertisement");
(void)snprintf(buf, sizeof(buf), "router advertisement");
cp = buf + strlen(buf);
ihp = (struct ih_rdiscovery *)&dp->icmp_void;
TCHECK(*ihp);
(void)strcpy(cp, " lifetime ");
(void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf));
cp = buf + strlen(buf);
lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
if (lifetime < 60)
(void)snprintf(cp, sizeof(buf) - strlen(buf),
"%u", lifetime);
else if (lifetime < 60 * 60)
(void)snprintf(cp, sizeof(buf) - strlen(buf),
"%u:%02u", lifetime / 60, lifetime % 60);
else
(void)snprintf(cp, sizeof(buf) - strlen(buf),
if (lifetime < 60) {
(void)snprintf(cp, sizeof(buf) - (cp - buf), "%u",
lifetime);
} else if (lifetime < 60 * 60) {
(void)snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u",
lifetime / 60, lifetime % 60);
} else {
(void)snprintf(cp, sizeof(buf) - (cp - buf),
"%u:%02u:%02u",
lifetime / 3600,
(lifetime % 3600) / 60,
lifetime % 60);
}
cp = buf + strlen(buf);
num = ihp->ird_addrnum;
(void)snprintf(cp, sizeof(buf) - strlen(buf), " %d:", num);
(void)snprintf(cp, sizeof(buf) - (cp - buf), " %d:", num);
cp = buf + strlen(buf);
size = ihp->ird_addrsiz;
if (size != 2) {
(void)snprintf(cp, sizeof(buf) - strlen(buf),
" [size %d]", size);
(void)snprintf(cp, sizeof(buf) - (cp - buf),
" [size %d]", size);
break;
}
idp = (struct id_rdiscovery *)&dp->icmp_data;
while (num-- > 0) {
TCHECK(*idp);
(void)snprintf(cp, sizeof(buf) - strlen(buf),
" {%s %u}",
(void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
ipaddr_string(&idp->ird_addr),
EXTRACT_32BITS(&idp->ird_pref));
cp = buf + strlen(buf);
++idp;
}
}
}
break;
case ICMP_TIMXCEED:
@ -339,8 +447,8 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
break;
default:
(void)snprintf(buf, sizeof(buf),
"time exceeded-#%d", dp->icmp_code);
(void)snprintf(buf, sizeof(buf), "time exceeded-#%d",
dp->icmp_code);
break;
}
break;
@ -348,20 +456,37 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
case ICMP_PARAMPROB:
if (dp->icmp_code)
(void)snprintf(buf, sizeof(buf),
"parameter problem - code %d",
dp->icmp_code);
"parameter problem - code %d", dp->icmp_code);
else {
TCHECK(dp->icmp_pptr);
(void)snprintf(buf, sizeof(buf),
"parameter problem - octet %d",
dp->icmp_pptr);
"parameter problem - octet %d", dp->icmp_pptr);
}
break;
case ICMP_MASKREPLY:
TCHECK(dp->icmp_mask);
(void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
(u_int32_t)ntohl(dp->icmp_mask));
(unsigned)ntohl(dp->icmp_mask));
break;
case ICMP_TSTAMP:
TCHECK(dp->icmp_seq);
(void)snprintf(buf, sizeof(buf),
"time stamp query id %u seq %u",
(unsigned)ntohs(dp->icmp_id),
(unsigned)ntohs(dp->icmp_seq));
break;
case ICMP_TSTAMPREPLY:
TCHECK(dp->icmp_ttime);
(void)snprintf(buf, sizeof(buf),
"time stamp reply id %u seq %u : org 0x%lx recv 0x%lx xmit 0x%lx",
(unsigned)ntohs(dp->icmp_id),
(unsigned)ntohs(dp->icmp_seq),
(unsigned long)ntohl(dp->icmp_otime),
(unsigned long)ntohl(dp->icmp_rtime),
(unsigned long)ntohl(dp->icmp_ttime));
break;
default:

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-icmp6.c,v 1.9 2000/08/03 14:31:04 itojun Exp $ */
/* $NetBSD: print-icmp6.c,v 1.10 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
@ -27,7 +27,7 @@ static const char rcsid[] =
"@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-icmp6.c,v 1.9 2000/08/03 14:31:04 itojun Exp $");
__RCSID("$NetBSD: print-icmp6.c,v 1.10 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -55,17 +55,32 @@ __RCSID("$NetBSD: print-icmp6.c,v 1.9 2000/08/03 14:31:04 itojun Exp $");
#include <arpa/inet.h>
#include <stdio.h>
#include <netdb.h>
#include <netinet/ip6.h>
#include <netinet/icmp6.h>
#include <netinet6/ah.h>
#include "interface.h"
#include "addrtoname.h"
struct nd_opt_advinterval { /* Advertisement interval option */
u_int8_t nd_opt_adv_type;
u_int8_t nd_opt_adv_len;
u_int16_t nd_opt_adv_reserved;
u_int32_t nd_opt_adv_interval;
};
void icmp6_opt_print(const u_char *, int);
void mld6_print(const u_char *);
static struct udphdr *get_upperlayer(u_char *, int *);
static void dnsname_print(const u_char *, const u_char *);
void icmp6_nodeinfo_print(int, const u_char *, const u_char *);
void icmp6_rrenum_print(int, const u_char *, const u_char *);
#ifndef abs
#define abs(a) ((0 < (a)) ? (a) : -(a))
#endif
void
icmp6_print(register const u_char *bp, register const u_char *bp2)
@ -75,10 +90,10 @@ icmp6_print(register const u_char *bp, register const u_char *bp2)
register const char *str;
register const struct ip6_hdr *oip;
register const struct udphdr *ouh;
register int hlen, dport;
register int dport;
register const u_char *ep;
char buf[256];
int icmp6len;
int icmp6len, prot;
#if 0
#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc
@ -88,7 +103,7 @@ icmp6_print(register const u_char *bp, register const u_char *bp2)
ip = (struct ip6_hdr *)bp2;
oip = (struct ip6_hdr *)(dp + 1);
str = buf;
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
if (ip->ip6_plen)
icmp6len = (ntohs(ip->ip6_plen) + sizeof(struct ip6_hdr) -
@ -115,11 +130,7 @@ icmp6_print(register const u_char *bp, register const u_char *bp2)
printf("icmp6: %s unreachable prohibited",
ip6addr_string(&oip->ip6_dst));
break;
#ifdef ICMP6_DST_UNREACH_BEYONDSCOPE
case ICMP6_DST_UNREACH_BEYONDSCOPE:
#else
case ICMP6_DST_UNREACH_NOTNEIGHBOR:
#endif
printf("icmp6: %s beyond scope of source address %s",
ip6addr_string(&oip->ip6_dst),
ip6addr_string(&oip->ip6_src));
@ -129,11 +140,12 @@ icmp6_print(register const u_char *bp, register const u_char *bp2)
ip6addr_string(&oip->ip6_dst));
break;
case ICMP6_DST_UNREACH_NOPORT:
TCHECK(oip->ip6_nxt);
hlen = sizeof(struct ip6_hdr);
ouh = (struct udphdr *)(((u_char *)oip) + hlen);
if ((ouh = get_upperlayer((u_char *)oip, &prot))
== NULL)
goto trunc;
dport = ntohs(ouh->uh_dport);
switch (oip->ip6_nxt) {
switch (prot) {
case IPPROTO_TCP:
printf("icmp6: %s tcp port %s unreachable",
ip6addr_string(&oip->ip6_dst),
@ -316,37 +328,10 @@ icmp6_print(register const u_char *bp, register const u_char *bp2)
break;
#undef REDIRECTLEN
#undef RDR
#ifndef ICMP6_ROUTER_RENUMBERING
#define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
#endif
case ICMP6_ROUTER_RENUMBERING:
switch (dp->icmp6_code) {
#ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
#define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
#endif
case ICMP6_ROUTER_RENUMBERING_COMMAND:
printf("icmp6: router renum command");
break;
#ifndef ICMP6_ROUTER_RENUMBERING_RESULT
#define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
#endif
case ICMP6_ROUTER_RENUMBERING_RESULT:
printf("icmp6: router renum result");
break;
default:
printf("icmp6: router renum code-#%d", dp->icmp6_code);
break;
}
icmp6_rrenum_print(icmp6len, bp, ep);
break;
#ifndef ICMP6_NI_QUERY
#define ICMP6_NI_QUERY 139
#endif
case ICMP6_NI_QUERY:
icmp6_nodeinfo_print(icmp6len, bp, ep);
break;
#ifndef ICMP6_NI_REPLY
#define ICMP6_NI_REPLY 140
#endif
case ICMP6_NI_REPLY:
icmp6_nodeinfo_print(icmp6len, bp, ep);
break;
@ -362,6 +347,79 @@ trunc:
#endif
}
static struct udphdr *
get_upperlayer(register u_char *bp, int *prot)
{
register const u_char *ep;
struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
struct udphdr *uh;
struct ip6_hbh *hbh;
struct ip6_frag *fragh;
struct ah *ah;
int nh, hlen;
/* 'ep' points to the end of available data. */
ep = snapend;
if (TTEST(ip6->ip6_nxt) == 0)
return NULL;
nh = ip6->ip6_nxt;
hlen = sizeof(struct ip6_hdr);
while (bp < snapend) {
bp += hlen;
switch(nh) {
case IPPROTO_UDP:
case IPPROTO_TCP:
uh = (struct udphdr *)bp;
if (TTEST(uh->uh_dport)) {
*prot = nh;
return(uh);
}
else
return(NULL);
/* NOTREACHED */
case IPPROTO_HOPOPTS:
case IPPROTO_DSTOPTS:
case IPPROTO_ROUTING:
hbh = (struct ip6_hbh *)bp;
if (TTEST(hbh->ip6h_len) == 0)
return(NULL);
nh = hbh->ip6h_nxt;
hlen = (hbh->ip6h_len + 1) << 3;
break;
case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
fragh = (struct ip6_frag *)bp;
if (TTEST(fragh->ip6f_offlg) == 0)
return(NULL);
/* fragments with non-zero offset are meaningless */
if ((fragh->ip6f_offlg & IP6F_OFF_MASK) != 0)
return(NULL);
nh = fragh->ip6f_nxt;
hlen = sizeof(struct ip6_frag);
break;
case IPPROTO_AH:
ah = (struct ah *)bp;
if (TTEST(ah->ah_len) == 0)
return(NULL);
nh = ah->ah_nxt;
hlen = (ah->ah_len + 2) << 2;
break;
default: /* unknown or undecodable header */
*prot = nh; /* meaningless, but set here anyway */
return(NULL);
}
}
return(NULL); /* should be notreached, though */
}
void
icmp6_opt_print(register const u_char *bp, int resid)
{
@ -370,6 +428,7 @@ icmp6_opt_print(register const u_char *bp, int resid)
register const struct nd_opt_prefix_info *opp;
register const struct icmp6_opts_redirect *opr;
register const struct nd_opt_mtu *opm;
register const struct nd_opt_advinterval *opa;
register const u_char *ep;
int opts_len;
#if 0
@ -389,7 +448,7 @@ icmp6_opt_print(register const u_char *bp, int resid)
oip = &dp->icmp6_ip6;
str = buf;
#endif
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
ECHECK(op->nd_opt_len);
@ -435,9 +494,14 @@ icmp6_opt_print(register const u_char *bp, int resid)
TCHECK(opp->nd_opt_pi_prefix);
printf("(prefix info: "); /*)*/
if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
printf("L");
printf("L");
if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
printf("A");
printf("A");
#ifndef ND_OPT_PI_FLAG_ROUTER
#define ND_OPT_PI_FLAG_ROUTER 0x20 /* 2292bis-02 */
#endif
if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
printf("R");
if (opp->nd_opt_pi_flags_reserved)
printf(" ");
printf("valid_ltime=");
@ -481,6 +545,20 @@ icmp6_opt_print(register const u_char *bp, int resid)
icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
resid - (op->nd_opt_len << 3));
break;
#ifndef ND_OPT_ADVINTERVAL
#define ND_OPT_ADVINTERVAL 7 /* 2292bis-02 */
#endif
case ND_OPT_ADVINTERVAL:
opa = (struct nd_opt_advinterval *)op;
TCHECK(opa->nd_opt_adv_interval);
printf("(advint: "); /*)*/
printf("advint=%u",
(u_int32_t)ntohl(opa->nd_opt_adv_interval));
/*(*/
printf(")");
icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
resid - (op->nd_opt_len << 3));
break;
default:
opts_len = op->nd_opt_len;
printf("(unknwon opt_type=%d, opt_len=%d)",
@ -504,7 +582,7 @@ mld6_print(register const u_char *bp)
register struct mld6_hdr *mp = (struct mld6_hdr *)bp;
register const u_char *ep;
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
if ((u_char *)mp + sizeof(*mp) > ep)
@ -686,7 +764,7 @@ icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
needcomma = 0;
ni6 = (struct icmp6_nodeinfo *)dp;
printf("icmp6: node information query");
printf("icmp6: node information reply");
printf(" ("); /*)*/
switch (ni6->ni_code) {
case ICMP6_NI_SUCCESS:
@ -759,10 +837,14 @@ icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
if (needcomma)
printf(", ");
printf("node addresses");
for (i = sizeof(*ni6);
i < siz;
i += sizeof(struct in6_addr)) {
i = sizeof(*ni6);
while (i < siz) {
if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
break;
printf(" %s", getname6(bp + i));
i += sizeof(struct in6_addr);
printf("(%d)", ntohl(*(int32_t *)(bp + i)));
i += sizeof(int32_t);
}
i = ni6->ni_flags;
if (!i)
@ -793,4 +875,142 @@ trunc:
fputs("[|icmp6]", stdout);
}
void
icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep)
{
struct icmp6_router_renum *rr6;
struct icmp6_hdr *dp;
size_t siz;
const char *cp;
struct rr_pco_match *match;
struct rr_pco_use *use;
char hbuf[NI_MAXHOST];
int n;
dp = (struct icmp6_hdr *)bp;
rr6 = (struct icmp6_router_renum *)bp;
siz = ep - bp;
cp = (const char *)(rr6 + 1);
TCHECK(rr6->rr_reserved);
switch (rr6->rr_code) {
case ICMP6_ROUTER_RENUMBERING_COMMAND:
printf("router renum: command");
break;
case ICMP6_ROUTER_RENUMBERING_RESULT:
printf("router renum: result");
break;
case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
printf("router renum: sequence number reset");
break;
default:
printf("router renum: code-#%d", rr6->rr_code);
break;
}
printf(", seq=%u", (u_int32_t)ntohl(rr6->rr_seqnum));
if (vflag) {
#define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
printf("["); /*]*/
if (rr6->rr_flags) {
printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
F(ICMP6_RR_FLAGS_REQRESULT, "R"),
F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
F(ICMP6_RR_FLAGS_SPECSITE, "S"),
F(ICMP6_RR_FLAGS_PREVDONE, "P"));
}
printf("seg=%u,", rr6->rr_segnum);
printf("maxdelay=%u", rr6->rr_maxdelay);
if (rr6->rr_reserved)
printf("rsvd=0x%x", (u_int16_t)ntohs(rr6->rr_reserved));
/*[*/
printf("]");
#undef F
}
if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
match = (struct rr_pco_match *)cp;
cp = (const char *)(match + 1);
TCHECK(match->rpm_prefix);
if (vflag)
printf("\n\t");
else
printf(" ");
printf("match("); /*)*/
switch (match->rpm_code) {
case RPM_PCO_ADD: printf("add"); break;
case RPM_PCO_CHANGE: printf("change"); break;
case RPM_PCO_SETGLOBAL: printf("setglobal"); break;
default: printf("#%u", match->rpm_code); break;
}
if (vflag) {
printf(",ord=%u", match->rpm_ordinal);
printf(",min=%u", match->rpm_minlen);
printf(",max=%u", match->rpm_maxlen);
}
if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf)))
printf(",%s/%u", hbuf, match->rpm_matchlen);
else
printf(",?/%u", match->rpm_matchlen);
/*(*/
printf(")");
n = match->rpm_len - 3;
if (n % 4)
goto trunc;
n /= 4;
while (n-- > 0) {
use = (struct rr_pco_use *)cp;
cp = (const char *)(use + 1);
TCHECK(use->rpu_prefix);
if (vflag)
printf("\n\t");
else
printf(" ");
printf("use("); /*)*/
if (use->rpu_flags) {
#define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
printf("%s%s,",
F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P"));
#undef F
}
if (vflag) {
printf("mask=0x%x,", use->rpu_ramask);
printf("raflags=0x%x,", use->rpu_raflags);
if (~use->rpu_vltime == 0)
printf("vltime=infty,");
else
printf("vltime=%u,",
(u_int32_t)ntohl(use->rpu_vltime));
if (~use->rpu_pltime == 0)
printf("pltime=infty,");
else
printf("pltime=%u,",
(u_int32_t)ntohl(use->rpu_pltime));
}
if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf,
sizeof(hbuf)))
printf("%s/%u/%u", hbuf, use->rpu_uselen,
use->rpu_keeplen);
else
printf("?/%u/%u", use->rpu_uselen,
use->rpu_keeplen);
/*(*/
printf(")");
}
}
return;
trunc:
fputs("[|icmp6]", stdout);
}
#endif /* INET6 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ip.c,v 1.11 2001/01/19 09:10:13 kleink Exp $ */
/* $NetBSD: print-ip.c,v 1.12 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-ip.c,v 1.66 97/05/28 12:51:43 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-ip.c,v 1.11 2001/01/19 09:10:13 kleink Exp $");
__RCSID("$NetBSD: print-ip.c,v 1.12 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -253,6 +253,62 @@ ip_printroute(const char *type, register const u_char *cp, u_int length)
printf("%s}", ptr == len? "#" : "");
}
static void
ip_printts(register const u_char *cp, u_int length)
{
register u_int ptr = cp[2] - 1;
register u_int len = 0;
int hoplen;
char *type;
printf(" TS{");
hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4;
if ((length - 4) & (hoplen-1))
printf("[bad length %d]", length);
if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1)
printf("[bad ptr %d]", cp[2]);
switch (cp[3]&0xF) {
case IPOPT_TS_TSONLY:
printf("TSONLY");
break;
case IPOPT_TS_TSANDADDR:
printf("TS+ADDR");
break;
/*
* prespecified should really be 3, but some ones might send 2
* instead, and the IPOPT_TS_PRESPEC constant can apparently
* have both values, so we have to hard-code it here.
*/
case 2:
printf("PRESPEC2.0");
break;
case 3: /* IPOPT_TS_PRESPEC */
printf("PRESPEC");
break;
default:
printf("[bad ts type %d]", cp[3]&0xF);
goto done;
}
type = " ";
for (len = 4; len < length; len += hoplen) {
if (ptr == len)
type = " ^ ";
printf("%s%d@%s", type, EXTRACT_32BITS(&cp[len+hoplen-4]),
hoplen!=8 ? "" : ipaddr_string(&cp[len]));
type = " ";
}
done:
printf("%s", ptr == len ? " ^ " : "");
if (cp[3]>>4)
printf(" [%d hops not recorded]} ", cp[3]>>4);
else
printf("}");
}
/*
* print IP options.
*/
@ -264,7 +320,15 @@ ip_optprint(register const u_char *cp, u_int length)
for (; length > 0; cp += len, length -= len) {
int tt = *cp;
len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1];
if (tt == IPOPT_NOP || tt == IPOPT_EOL)
len = 1;
else {
if (&cp[1] >= snapend) {
printf("[|ip]");
return;
}
len = cp[1];
}
if (len <= 0) {
printf("[|ip op len %d]", len);
return;
@ -286,15 +350,17 @@ ip_optprint(register const u_char *cp, u_int length)
break;
case IPOPT_TS:
printf(" TS{%d}", len);
ip_printts(cp, len);
break;
#ifndef IPOPT_SECURITY
#define IPOPT_SECURITY 130
#endif /* IPOPT_SECURITY */
case IPOPT_SECURITY:
printf(" SECURITY{%d}", len);
break;
case IPOPT_RR:
printf(" RR{%d}=", len);
ip_printroute("RR", cp, len);
break;
@ -412,6 +478,9 @@ ip_print(register const u_char *bp, register u_int length)
again:
switch (nh) {
#ifndef IPPROTO_AH
#define IPPROTO_AH 51
#endif
case IPPROTO_AH:
nh = *cp;
advance = ah_print(cp, (const u_char *)ip);
@ -419,6 +488,9 @@ again:
len -= advance;
goto again;
#ifndef IPPROTO_ESP
#define IPPROTO_ESP 50
#endif
case IPPROTO_ESP:
{
int enh;
@ -447,11 +519,11 @@ again:
}
case IPPROTO_TCP:
tcp_print(cp, len, (const u_char *)ip);
tcp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
break;
case IPPROTO_UDP:
udp_print(cp, len, (const u_char *)ip);
udp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
break;
case IPPROTO_ICMP:
@ -491,10 +563,6 @@ again:
igmp_print(cp, len, (const u_char *)ip);
break;
case IPPROTO_PIM:
pim_print(cp, len);
break;
case 4:
/* DVMRP multicast tunnel (ip-in-ip encapsulation) */
#if 0
@ -544,8 +612,8 @@ again:
if (! vflag) {
printf(" (gre encap)");
return;
}
break;
}
break;
#ifndef IPPROTO_MOBILE
#define IPPROTO_MOBILE 55
@ -562,10 +630,21 @@ again:
}
break;
#ifndef IPPROTO_PIM
#define IPPROTO_PIM 103
#endif
case IPPROTO_PIM:
pim_print(cp, len);
break;
#ifndef IPPROTO_VRRP
#define IPPROTO_VRRP 112
#define IPPROTO_VRRP 112
#endif
case IPPROTO_VRRP:
if (vflag)
(void)printf("vrrp %s > %s: ",
ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
vrrp_print(cp, len, (const u_char *)ip);
break;
@ -574,7 +653,7 @@ again:
(void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
#endif
(void)printf(" ip-proto-%d %d", ip->ip_p, len);
(void)printf(" ip-proto-%d %d", nh, len);
break;
}
}
@ -583,7 +662,7 @@ again:
* but the last stick a "+". For unfragmented datagrams, note
* the don't fragment flag.
*/
len = len0;
len = len0; /* get the original length */
if (off & 0x3fff) {
/*
* if this isn't the first frag, we're missing the
@ -592,9 +671,16 @@ again:
if (off & 0x1fff)
(void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
(void)printf(" (frag %d:%d@%d%s)", ntohs(ip->ip_id), len,
#ifndef IP_MF
#define IP_MF 0x2000
#endif /* IP_MF */
#ifndef IP_DF
#define IP_DF 0x4000
#endif /* IP_DF */
(void)printf(" (frag %d:%u@%d%s)", ntohs(ip->ip_id), len,
(off & 0x1fff) * 8,
(off & IP_MF)? "+" : "");
} else if (off & IP_DF)
(void)printf(" (DF)");

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ip6.c,v 1.5 2000/11/08 07:23:54 itojun Exp $ */
/* $NetBSD: print-ip6.c,v 1.6 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
@ -27,7 +27,7 @@ static const char rcsid[] =
"@(#) /master/usr.sbin/tcpdump/tcpdump/print-ip.c,v 2.1 1995/02/03 18:14:45 polk Exp (LBL)";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-ip6.c,v 1.5 2000/11/08 07:23:54 itojun Exp $");
__RCSID("$NetBSD: print-ip6.c,v 1.6 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -64,10 +64,11 @@ void
ip6_print(register const u_char *bp, register int length)
{
register const struct ip6_hdr *ip6;
register int hlen;
register int advance;
register int len;
register const u_char *cp;
int nh;
int fragmented = 0;
u_int flow;
ip6 = (const struct ip6_hdr *)bp;
@ -97,17 +98,17 @@ ip6_print(register const u_char *bp, register int length)
(void)printf("truncated-ip6 %d", length);
return;
}
hlen = sizeof(struct ip6_hdr);
advance = sizeof(struct ip6_hdr);
len = ntohs(ip6->ip6_plen);
if (length < len + hlen)
if (length < len + advance)
(void)printf("truncated-ip6 - %d bytes missing!",
len + hlen - length);
len + advance - length);
cp = (const u_char *)ip6;
nh = ip6->ip6_nxt;
while (cp < snapend) {
cp += hlen;
cp += advance;
if (cp == (u_char *)(ip6 + 1)
&& nh != IPPROTO_TCP && nh != IPPROTO_UDP) {
@ -117,42 +118,43 @@ ip6_print(register const u_char *bp, register int length)
switch (nh) {
case IPPROTO_HOPOPTS:
hlen = hbhopt_print(cp);
advance = hbhopt_print(cp);
nh = *cp;
break;
case IPPROTO_DSTOPTS:
hlen = dstopt_print(cp);
advance = dstopt_print(cp);
nh = *cp;
break;
case IPPROTO_FRAGMENT:
hlen = frag6_print(cp, (const u_char *)ip6);
if (snapend <= cp + hlen)
advance = frag6_print(cp, (const u_char *)ip6);
if (snapend <= cp + advance)
goto end;
nh = *cp;
fragmented = 1;
break;
case IPPROTO_ROUTING:
hlen = rt6_print(cp, (const u_char *)ip6);
advance = rt6_print(cp, (const u_char *)ip6);
nh = *cp;
break;
case IPPROTO_TCP:
tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
(const u_char *)ip6);
(const u_char *)ip6, fragmented);
goto end;
case IPPROTO_UDP:
udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
(const u_char *)ip6);
(const u_char *)ip6, fragmented);
goto end;
case IPPROTO_ICMPV6:
icmp6_print(cp, (const u_char *)ip6);
goto end;
case IPPROTO_AH:
hlen = ah_print(cp, (const u_char *)ip6);
advance = ah_print(cp, (const u_char *)ip6);
nh = *cp;
break;
case IPPROTO_ESP:
{
int enh;
cp += esp_print(cp, (const u_char *)ip6, &enh);
advance = esp_print(cp, (const u_char *)ip6, &enh);
if (enh < 0)
goto end;
nh = enh & 0xff;
@ -164,7 +166,7 @@ ip6_print(register const u_char *bp, register int length)
case IPPROTO_IPCOMP:
{
int enh;
cp += ipcomp_print(cp, (const u_char *)ip6, &enh);
advance = ipcomp_print(cp, (const u_char *)ip6, &enh);
if (enh < 0)
goto end;
nh = enh & 0xff;

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ip6opts.c,v 1.4 1999/12/10 05:45:08 itojun Exp $ */
/* $NetBSD: print-ip6opts.c,v 1.5 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -31,7 +31,7 @@
#ifndef lint
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-ip6opts.c,v 1.4 1999/12/10 05:45:08 itojun Exp $");
__RCSID("$NetBSD: print-ip6opts.c,v 1.5 2001/01/28 10:05:06 itojun Exp $");
#endif
#ifdef INET6
@ -48,6 +48,90 @@ __RCSID("$NetBSD: print-ip6opts.c,v 1.4 1999/12/10 05:45:08 itojun Exp $");
#include "interface.h"
#include "addrtoname.h"
/* items in rfc2292bis */
#ifndef IP6OPT_ROUTER_ALERT
#define IP6OPT_ROUTER_ALERT 0x05 /* (2292bis def, recommended) */
#endif
#ifndef IP6OPT_BINDING_UPDATE
#define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */
#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
#define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */
#define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
#endif
/* items outside of rfc2292bis */
#ifndef IP6OPT_MINLEN
#define IP6OPT_MINLEN 2
#endif
#ifndef IP6OPT_RTALERT_LEN
#define IP6OPT_RTALERT_LEN 4
#endif
#ifndef IP6OPT_JUMBO_LEN
#define IP6OPT_JUMBO_LEN 6
#endif
#define IP6OPT_HOMEADDR_MINLEN 18
#define IP6OPT_BU_MINLEN 10
#define IP6OPT_BA_MINLEN 13
#define IP6OPT_BR_MINLEN 2
#define IP6SOPT_ALTCOA 0x4
#define IP6SOPT_ALTCOA_MINLEN 18
#define IP6SOPT_UI 0x2
#define IP6SOPT_UI_MINLEN 4
static void ip6_sopt_print(const u_char *, int);
static void
ip6_sopt_print(const u_char *bp, int len)
{
int i;
int optlen;
for (i = 0; i < len; i += optlen) {
switch (bp[i]) {
case IP6OPT_PAD1:
printf(", pad1");
optlen = 1;
break;
case IP6OPT_PADN:
if (len - i < IP6OPT_MINLEN) {
printf(", padn: trunc");
goto trunc;
}
printf(", padn");
optlen = bp[i + 1] + 2;
break;
case IP6SOPT_ALTCOA:
if (len - i < IP6SOPT_ALTCOA_MINLEN) {
printf(", altcoa: trunc");
goto trunc;
}
printf(", alt-CoA: %s", ip6addr_string(&bp[i+2]));
optlen = bp[i + 1] + 2;
break;
case IP6SOPT_UI:
if (len - i < IP6SOPT_UI_MINLEN) {
printf(", ui: trunc");
goto trunc;
}
printf("(ui: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2]));
optlen = bp[i + 1] + 2;
break;
default:
if (len - i < IP6OPT_MINLEN) {
printf(", sopt_type %d: trunc)", bp[i]);
goto trunc;
}
printf(", sopt_type 0x%02x: len=%d", bp[i], bp[i + 1]);
optlen = bp[i + 1] + 2;
break;
}
}
return;
trunc:
printf("[trunc] ");
}
void
ip6_opt_print(const u_char *bp, int len)
{
@ -57,6 +141,7 @@ ip6_opt_print(const u_char *bp, int len)
for (i = 0; i < len; i += optlen) {
switch (bp[i]) {
case IP6OPT_PAD1:
printf("(pad1)");
optlen = 1;
break;
case IP6OPT_PADN:
@ -64,9 +149,10 @@ ip6_opt_print(const u_char *bp, int len)
printf("(padn: trunc)");
goto trunc;
}
printf("(padn)");
optlen = bp[i + 1] + 2;
break;
case IP6OPT_RTALERT:
case IP6OPT_ROUTER_ALERT:
if (len - i < IP6OPT_RTALERT_LEN) {
printf("(rtalert: trunc)");
goto trunc;
@ -75,7 +161,7 @@ ip6_opt_print(const u_char *bp, int len)
printf("(rtalert: invalid len %d)", bp[i + 1]);
goto trunc;
}
printf("(rtalert: 0x%04x) ", ntohs(*(u_short *)&bp[i + 2]));
printf("(rtalert: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2]));
optlen = IP6OPT_RTALERT_LEN;
break;
case IP6OPT_JUMBO:
@ -87,15 +173,103 @@ ip6_opt_print(const u_char *bp, int len)
printf("(jumbo: invalid len %d)", bp[i + 1]);
goto trunc;
}
printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int *)&bp[i + 2]));
printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int32_t *)&bp[i + 2]));
optlen = IP6OPT_JUMBO_LEN;
break;
case IP6OPT_HOME_ADDRESS:
if (len - i < IP6OPT_HOMEADDR_MINLEN) {
printf("(homeaddr: trunc)");
goto trunc;
}
if (bp[i + 1] < IP6OPT_HOMEADDR_MINLEN - 2) {
printf("(homeaddr: invalid len %d)", bp[i + 1]);
goto trunc;
}
printf("(homeaddr: %s", ip6addr_string(&bp[i + 2]));
if (bp[i + 1] > IP6OPT_HOMEADDR_MINLEN - 2) {
ip6_sopt_print(&bp[i + IP6OPT_HOMEADDR_MINLEN],
(optlen-IP6OPT_HOMEADDR_MINLEN));
}
printf(")");
optlen = bp[i + 1] + 2;
break;
case IP6OPT_BINDING_UPDATE:
if (len - i < IP6OPT_BU_MINLEN) {
printf("(bu: trunc)");
goto trunc;
}
if (bp[i + 1] < IP6OPT_BU_MINLEN - 2) {
printf("(bu: invalid len %d)", bp[i + 1]);
goto trunc;
}
printf("(bu: ");
if (bp[i + 2] & 0x80)
printf("A");
if (bp[i + 2] & 0x40)
printf("H");
if (bp[i + 2] & 0x20)
printf("R");
if (bp[i + 2] & 0x10)
printf("D");
if (bp[i + 2] & 0x0f)
printf("res");
printf(", prefixlen: %u", bp[i + 3]);
printf(", sequence: %u",
(u_int16_t)ntohs(*(u_int16_t *)&bp[i + 4]));
printf(", lifetime: %u",
(u_int32_t)ntohs(*(u_int32_t *)&bp[i + 8]));
optlen = bp[i + 1] + 2;
if (bp[i + 1] > IP6OPT_BU_MINLEN - 2) {
ip6_sopt_print(&bp[i + IP6OPT_BU_MINLEN],
(optlen - IP6OPT_BU_MINLEN));
}
printf(")");
break;
case IP6OPT_BINDING_ACK:
if (len - i < IP6OPT_BA_MINLEN) {
printf("(ba: trunc)");
goto trunc;
}
if (bp[i + 1] < IP6OPT_BA_MINLEN - 2) {
printf("(ba: invalid len %d)", bp[i + 1]);
goto trunc;
}
printf("(ba: ");
printf("status: %u", bp[i + 2]);
printf(", sequence: %u",
(u_int16_t)ntohs(*(u_int16_t *)&bp[i + 3]));
printf(", lifetime: %u",
(u_int32_t)ntohs(*(u_int32_t *)&bp[i + 7]));
printf(", refresh: %u",
(u_int32_t)ntohs(*(u_int32_t *)&bp[i + 11]));
if (bp[i + 1] > IP6OPT_BA_MINLEN - 2) {
ip6_sopt_print(&bp[i + IP6OPT_BA_MINLEN],
(optlen-IP6OPT_BA_MINLEN));
}
printf(")");
optlen = bp[i + 1] + 2;
break;
case IP6OPT_BINDING_REQ:
if (len - i < IP6OPT_BR_MINLEN) {
printf("(br: trunc)");
goto trunc;
}
printf("(br");
if (bp[i + 1] > IP6OPT_BR_MINLEN - 2) {
ip6_sopt_print(&bp[i + IP6OPT_BR_MINLEN],
(optlen-IP6OPT_BR_MINLEN));
}
printf(")");
optlen = bp[i + 1] + 2;
break;
default:
if (len - i < IP6OPT_MINLEN) {
printf("(type %d: trunc)", bp[i]);
goto trunc;
}
printf("(type 0x%02x: len=%d) ", bp[i], bp[i + 1]);
printf("(opt_type 0x%02x: len=%d) ", bp[i], bp[i + 1]);
optlen = bp[i + 1] + 2;
break;
}
@ -117,11 +291,11 @@ hbhopt_print(register const u_char *bp)
register const u_char *ep;
int hbhlen = 0;
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
TCHECK(dp->ip6h_len);
hbhlen = (int)((dp->ip6h_len + 1) << 3);
TCHECK2(dp, hbhlen);
TCHECK2(*dp, hbhlen);
printf("HBH ");
if (vflag)
ip6_opt_print((const u_char *)dp + sizeof(*dp), hbhlen - sizeof(*dp));
@ -140,11 +314,11 @@ dstopt_print(register const u_char *bp)
register const u_char *ep;
int dstoptlen = 0;
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
TCHECK(dp->ip6d_len);
dstoptlen = (int)((dp->ip6d_len + 1) << 3);
TCHECK2(dp, dstoptlen);
TCHECK2(*dp, dstoptlen);
printf("DSTOPT ");
if (vflag) {
ip6_opt_print((const u_char *)dp + sizeof(*dp),

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ipcomp.c,v 1.2 1999/09/04 03:36:41 itojun Exp $ */
/* $NetBSD: print-ipcomp.c,v 1.3 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
@ -27,7 +27,7 @@ static const char rcsid[] =
"@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-ipcomp.c,v 1.2 1999/09/04 03:36:41 itojun Exp $");
__RCSID("$NetBSD: print-ipcomp.c,v 1.3 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -37,33 +37,15 @@ __RCSID("$NetBSD: print-ipcomp.c,v 1.2 1999/09/04 03:36:41 itojun Exp $");
#include <sys/types.h>
#include <sys/socket.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/tcp.h>
#include <stdio.h>
#ifdef INET6
#include <netinet/ip6.h>
#endif
#ifdef HAVE_NETINET6_IPCOMP_H
#include <netinet6/ipcomp.h>
#else
struct ipcomp {
u_int8_t comp_nxt; /* Next Header */
u_int8_t comp_flags; /* Length of data, in 32bit */
u_int16_t comp_cpi; /* Compression parameter index */
};
#endif
#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)
#include <zlib.h>
@ -85,14 +67,14 @@ ipcomp_print(register const u_char *bp, register const u_char *bp2, int *nhdr)
ipcomp = (struct ipcomp *)bp;
cpi = (u_int16_t)ntohs(ipcomp->comp_cpi);
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
if ((u_char *)(ipcomp + 1) >= ep - sizeof(struct ipcomp)) {
fputs("[|IPCOMP]", stdout);
goto fail;
}
printf("IPComp(cpi=%u)", cpi);
printf("IPComp(cpi=0x%04x)", cpi);
#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)
if (1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-isakmp.c,v 1.7 2000/12/29 02:38:23 itojun Exp $ */
/* $NetBSD: print-isakmp.c,v 1.8 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -36,7 +36,7 @@ static const char rcsid[] =
"@(#) KAME Header: /cvsroot/kame/kame/kame/kame/tcpdump/print-isakmp.c,v 1.3 1999/12/01 01:41:25 itojun Exp";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-isakmp.c,v 1.7 2000/12/29 02:38:23 itojun Exp $");
__RCSID("$NetBSD: print-isakmp.c,v 1.8 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -706,12 +706,8 @@ isakmp_id_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase,
{
int i;
printf(" len=%d ", len);
for (i = 0; i < len; i++) {
if (isprint(data[i]))
printf("%c", data[i]);
else
printf("\\%03o", data[i]);
}
for (i = 0; i < len; i++)
safeputchar(data[i]);
len = 0;
break;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-mobile.c,v 1.3 1999/07/26 06:11:57 itojun Exp $ */
/* $NetBSD: print-mobile.c,v 1.4 2001/01/28 10:05:06 itojun Exp $ */
/*
* (c) 1998 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: print-mobile.c,v 1.3 1999/07/26 06:11:57 itojun Exp $");
__RCSID("$NetBSD: print-mobile.c,v 1.4 2001/01/28 10:05:06 itojun Exp $");
#endif
#include <sys/param.h>
@ -124,7 +124,7 @@ static u_int16_t mob_in_cksum(u_short *p, int len)
if (len & 1) {
union {
u_int16_t w;
u_int32_t c[2];
u_int8_t c[2];
} u;
u.c[0] = *(u_char *)p;
u.c[1] = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-nfs.c,v 1.14 2001/01/05 03:21:53 lukem Exp $ */
/* $NetBSD: print-nfs.c,v 1.15 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-nfs.c,v 1.65 97/08/17 13:24:22 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-nfs.c,v 1.14 2001/01/05 03:21:53 lukem Exp $");
__RCSID("$NetBSD: print-nfs.c,v 1.15 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -66,6 +66,10 @@ struct rtentry;
#include "nfs.h"
#include "nfsfh.h"
#ifdef __NetBSD__
#define nfs_type nfstype
#endif
static void nfs_printfh(const u_int32_t *, const u_int);
static void xid_map_enter(const struct rpc_msg *, const u_char *);
static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
@ -108,6 +112,55 @@ u_int32_t nfsv3_procid[NFS_NPROCS] = {
NFSPROC_NOOP
};
/*
* NFS V2 and V3 status values.
*
* Some of these come from the RFCs for NFS V2 and V3, with the message
* strings taken from the FreeBSD C library "errlst.c".
*
* Others are errors that are not in the RFC but that I suspect some
* NFS servers could return; the values are FreeBSD errno values, as
* the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
* was primarily BSD-derived.
*/
static struct tok status2str[] = {
{ 1, "Operation not permitted" }, /* EPERM */
{ 2, "No such file or directory" }, /* ENOENT */
{ 5, "Input/output error" }, /* EIO */
{ 6, "Device not configured" }, /* ENXIO */
{ 11, "Resource deadlock avoided" }, /* EDEADLK */
{ 12, "Cannot allocate memory" }, /* ENOMEM */
{ 13, "Permission denied" }, /* EACCES */
{ 17, "File exists" }, /* EEXIST */
{ 18, "Cross-device link" }, /* EXDEV */
{ 19, "Operation not supported by device" }, /* ENODEV */
{ 20, "Not a directory" }, /* ENOTDIR */
{ 21, "Is a directory" }, /* EISDIR */
{ 22, "Invalid argument" }, /* EINVAL */
{ 26, "Text file busy" }, /* ETXTBSY */
{ 27, "File too large" }, /* EFBIG */
{ 28, "No space left on device" }, /* ENOSPC */
{ 30, "Read-only file system" }, /* EROFS */
{ 31, "Too many links" }, /* EMLINK */
{ 45, "Operation not supported" }, /* EOPNOTSUPP */
{ 62, "Too many levels of symbolic links" }, /* ELOOP */
{ 63, "File name too long" }, /* ENAMETOOLONG */
{ 66, "Directory not empty" }, /* ENOTEMPTY */
{ 69, "Disc quota exceeded" }, /* EDQUOT */
{ 70, "Stale NFS file handle" }, /* ESTALE */
{ 71, "Too many levels of remote in path" }, /* EREMOTE */
{ 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
{ 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
{ 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
{ 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
{ 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
{ 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
{ 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
{ 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
{ 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
{ 0, NULL }
};
static struct tok nfsv3_writemodes[] = {
{ 0, "unstable" },
{ 1, "datasync" },
@ -413,7 +466,7 @@ nfsreq_print(register const u_char *bp, u_int length,
{
register const struct rpc_msg *rp;
register const u_int32_t *dp;
nfstype type;
nfs_type type;
int v3;
u_int32_t proc;
struct nfsv3_sattr sa3;
@ -567,7 +620,7 @@ nfsreq_print(register const u_char *bp, u_int length,
if ((dp = parsereq(rp, length)) != 0 &&
(dp = parsefhn(dp, v3)) != 0) {
TCHECK(*dp);
type = (nfstype)ntohl(*dp++);
type = (nfs_type)ntohl(*dp++);
if ((dp = parse_sattr3(dp, &sa3)) == 0)
break;
printf(" %s", tok2str(type2str, "unk-ft %d", type));
@ -979,7 +1032,8 @@ parsestatus(const u_int32_t *dp, int *er)
*er = errnum;
if (errnum != 0) {
if (!qflag)
printf(" ERROR: %s", pcap_strerror(errnum));
printf(" ERROR: %s",
tok2str(status2str, "unk %d", errnum));
nfserr = 1;
return (NULL);
}
@ -1118,7 +1172,7 @@ parsestatfs(const u_int32_t *dp, int v3)
return (0);
}
TCHECK2(dp[0], (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
TCHECK2(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
sfsp = (const struct nfs_statfs *)dp;
@ -1196,7 +1250,7 @@ parse_pre_op_attr(const u_int32_t *dp, int verbose)
if (!ntohl(dp[0]))
return (dp + 1);
dp++;
TCHECK2(dp[0], 24);
TCHECK2(dp, 24);
if (verbose > 1) {
return parse_wcc_attr(dp);
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-null.c,v 1.8 1999/07/26 06:26:58 itojun Exp $ */
/* $NetBSD: print-null.c,v 1.9 2001/01/28 10:05:06 itojun Exp $ */
/*
* Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-null.c,v 1.24 97/05/28 12:52:47 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-null.c,v 1.8 1999/07/26 06:26:58 itojun Exp $");
__RCSID("$NetBSD: print-null.c,v 1.9 2001/01/28 10:05:06 itojun Exp $");
#endif
#endif
@ -131,14 +131,19 @@ null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
if (eflag)
null_print(p, ip, length);
#ifndef INET6
ip_print((const u_char *)ip, length);
#else
if (ip->ip_v == IPVERSION)
switch (ip->ip_v) {
case 4:
ip_print((const u_char *)ip, length);
else if (ip->ip_v == 6)
break;
#ifdef INET6
case 6:
ip6_print((const u_char *)ip, length);
#endif /*INET6*/
break;
#endif /* INET6 */
default:
printf("ip v%d", ip->ip_v);
break;
}
if (xflag)
default_print((const u_char *)ip, caplen - NULL_HDRLEN);

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-ospf6.c,v 1.4 1999/09/04 03:36:42 itojun Exp $ */
/* $NetBSD: print-ospf6.c,v 1.5 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
@ -25,7 +25,7 @@
#ifndef lint
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-ospf6.c,v 1.4 1999/09/04 03:36:42 itojun Exp $");
__RCSID("$NetBSD: print-ospf6.c,v 1.5 2001/01/28 10:05:07 itojun Exp $");
#endif
#include <sys/param.h>
@ -69,6 +69,13 @@ static const struct bits ospf6_rla_flag_bits[] = {
{ 0, NULL }
};
static const struct bits ospf6_asla_flag_bits[] = {
{ ASLA_FLAG_EXTERNAL, "E" },
{ ASLA_FLAG_FWDADDR, "F" },
{ ASLA_FLAG_ROUTETAG, "T" },
{ 0, NULL }
};
static struct tok type2str[] = {
{ OSPF_TYPE_UMD, "umd" },
{ OSPF_TYPE_HELLO, "hello" },
@ -239,6 +246,8 @@ ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp)
lsapp->lsa_p_len);
if (lsapp->lsa_p_opt)
printf("(opt=%x)", lsapp->lsa_p_opt);
if (lsapp->lsa_p_mbz)
printf("(mbz=%x)", ntohs(lsapp->lsa_p_mbz)); /* XXX */
return sizeof(*lsapp) - 4 + k * 4;
trunc:
@ -252,7 +261,7 @@ trunc:
static int
ospf6_print_lsa(register const struct lsa *lsap)
{
register const u_char *ls_end;
register const u_char *ls_end, *ls_opt;
register const struct rlalink *rlp;
#if 0
register const struct tos_metric *tosp;
@ -268,6 +277,7 @@ ospf6_print_lsa(register const struct lsa *lsap)
register const u_int32_t *lp;
#endif
register int j, k;
u_int32_t flags32;
if (ospf6_print_lshdr(&lsap->ls_hdr))
return (1);
@ -340,12 +350,51 @@ ospf6_print_lsa(register const struct lsa *lsap)
lsapp = lsap->lsa_un.un_inter_ap.inter_ap_prefix;
while (lsapp + sizeof(lsapp) <= (struct lsa_prefix *)ls_end) {
k = ospf6_print_lsaprefix(lsapp);
if (k < 0)
if (k)
goto trunc;
lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k);
}
break;
case LS_SCOPE_AS | LS_TYPE_ASE:
TCHECK(lsap->lsa_un.un_asla.asla_metric);
flags32 = ntohl(lsap->lsa_un.un_asla.asla_metric);
ospf6_print_bits(ospf6_asla_flag_bits, flags32);
printf(" metric %u",
ntohl(lsap->lsa_un.un_asla.asla_metric) &
ASLA_MASK_METRIC);
lsapp = lsap->lsa_un.un_asla.asla_prefix;
k = ospf6_print_lsaprefix(lsapp);
if (k < 0)
goto trunc;
if ((ls_opt = (u_char *)(((u_char *)lsapp) + k)) < ls_end) {
struct in6_addr *fwdaddr6;
if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
fwdaddr6 = (struct in6_addr *)ls_opt;
TCHECK(*fwdaddr6);
printf(" forward %s",
ip6addr_string(fwdaddr6));
ls_opt += sizeof(struct in6_addr);
}
if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
TCHECK(*(u_int32_t *)ls_opt);
printf(" tag %s",
ipaddr_string((u_int32_t *)ls_opt));
ls_opt += sizeof(u_int32_t);
}
if (lsapp->lsa_p_mbz) {
TCHECK(*(u_int32_t *)ls_opt);
printf(" RefLSID: %s",
ipaddr_string((u_int32_t *)ls_opt));
ls_opt += sizeof(u_int32_t);
}
}
break;
#if 0
case LS_TYPE_SUM_ABR:
TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
@ -362,36 +411,6 @@ ospf6_print_lsa(register const struct lsa *lsap)
}
break;
case LS_TYPE_ASE:
TCHECK(lsap->lsa_un.un_nla.nla_mask);
printf(" mask %s",
ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
almp = lsap->lsa_un.un_asla.asla_metric;
while ((u_char *)almp < ls_end) {
register u_int32_t ul;
TCHECK(almp->asla_tosmetric);
ul = ntohl(almp->asla_tosmetric);
printf(" type %d tos %d metric %d",
(ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
(ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS,
(ul & ASLA_MASK_METRIC));
TCHECK(almp->asla_forward);
if (almp->asla_forward.s_addr) {
printf(" forward %s",
ipaddr_string(&almp->asla_forward));
}
TCHECK(almp->asla_tag);
if (almp->asla_tag.s_addr) {
printf(" tag %s",
ipaddr_string(&almp->asla_tag));
}
++almp;
}
break;
case LS_TYPE_GROUP:
/* Multicast extensions as of 23 July 1991 */
mcp = lsap->lsa_un.un_mcla;
@ -430,7 +449,7 @@ ospf6_print_lsa(register const struct lsa *lsap)
lsapp = llsap->llsa_prefix;
for (j = 0; j < ntohl(llsap->llsa_nprefix); j++) {
k = ospf6_print_lsaprefix(lsapp);
if (k < 0)
if (k)
goto trunc;
lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k);
}
@ -453,7 +472,7 @@ ospf6_print_lsa(register const struct lsa *lsap)
j < ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
j++) {
k = ospf6_print_lsaprefix(lsapp);
if (k < 0)
if (k)
goto trunc;
lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k);
}
@ -622,7 +641,7 @@ ospf6_print(register const u_char *bp, register u_int length)
/* value. If it's not valid, say so and return */
TCHECK(op->ospf6_type);
cp = tok2str(type2str, "type%d", op->ospf6_type);
printf(" OSPFv%d-%s %d:", op->ospf6_version, cp, length);
printf("OSPFv%d-%s %d:", op->ospf6_version, cp, length);
if (*cp == 't')
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-rip.c,v 1.6 1997/10/03 19:55:38 christos Exp $ */
/* $NetBSD: print-rip.c,v 1.7 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-rip.c,v 1.36 96/11/29 01:22:50 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-rip.c,v 1.6 1997/10/03 19:55:38 christos Exp $");
__RCSID("$NetBSD: print-rip.c,v 1.7 2001/01/28 10:05:07 itojun Exp $");
#endif
#endif
@ -43,6 +43,8 @@ __RCSID("$NetBSD: print-rip.c,v 1.6 1997/10/03 19:55:38 christos Exp $");
#include <netinet/udp_var.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "interface.h"
#include "addrtoname.h"
@ -60,6 +62,8 @@ struct rip {
#define RIPCMD_POLL 5 /* want info from everybody */
#define RIPCMD_POLLENTRY 6 /* poll for entry */
#define RIP_AUTHLEN 16
struct rip_netinfo {
u_short rip_family;
u_short rip_tag;
@ -70,23 +74,83 @@ struct rip_netinfo {
};
static void
rip_entry_print(register int vers, register const struct rip_netinfo *ni)
rip_printblk(const u_char *cp, const u_char *ep)
{
register u_char *cp, *ep;
for (; cp < ep; cp += 2)
printf(" %04x", EXTRACT_16BITS(cp));
return;
}
if (EXTRACT_16BITS(&ni->rip_family) != AF_INET) {
static void
rip_entry_print_v1(register int vers, register const struct rip_netinfo *ni)
{
register u_short family;
printf(" [family %d:", EXTRACT_16BITS(&ni->rip_family));
cp = (u_char *)&ni->rip_tag;
ep = (u_char *)&ni->rip_metric + sizeof(ni->rip_metric);
for (; cp < ep; cp += 2)
printf(" %04x", EXTRACT_16BITS(cp));
/* RFC 1058 */
family = EXTRACT_16BITS(&ni->rip_family);
if (family != AF_INET) {
printf(" [family %d:", family);
rip_printblk((u_char *)&ni->rip_tag,
(u_char *)&ni->rip_metric +
sizeof(ni->rip_metric));
printf("]");
} else if (vers < 2) {
/* RFC 1058 */
printf(" %s", ipaddr_string(&ni->rip_dest));
} else {
/* RFC 1723 */
return;
}
if (ni->rip_tag || ni->rip_dest_mask || ni->rip_router) {
/* MBZ fields not zero */
printf(" [");
rip_printblk((u_char *)&ni->rip_family,
(u_char *)&ni->rip_metric +
sizeof(ni->rip_metric));
printf("]");
return;
}
printf(" {%s}(%d)", ipaddr_string(&ni->rip_dest),
EXTRACT_32BITS(&ni->rip_metric));
}
static void
rip_entry_print_v2(register int vers, register const struct rip_netinfo *ni)
{
register u_char *p;
register u_short family;
u_char buf[RIP_AUTHLEN];
/* RFC 1723 */
family = EXTRACT_16BITS(&ni->rip_family);
if (family == 0xFFFF) {
if (EXTRACT_16BITS(&ni->rip_tag) == 2) {
memcpy(buf, &ni->rip_dest, sizeof(buf));
buf[sizeof(buf)-1] = '\0';
for (p = buf; *p; p++) {
if (!isprint(*p))
break;
}
if (!*p) {
printf(" [password %s]", buf);
} else {
printf(" [password: ");
rip_printblk((u_char *)&ni->rip_dest,
(u_char *)&ni->rip_metric +
sizeof(ni->rip_metric));
printf("]");
}
} else {
printf(" [auth %d:",
EXTRACT_16BITS(&ni->rip_tag));
rip_printblk((u_char *)&ni->rip_dest,
(u_char *)&ni->rip_metric +
sizeof(ni->rip_metric));
printf("]");
}
} else if (family != AF_INET) {
printf(" [family %d:", family);
rip_printblk((u_char *)&ni->rip_tag,
(u_char *)&ni->rip_metric +
sizeof(ni->rip_metric));
printf("]");
return;
} else { /* AF_INET */
printf(" {%s", ipaddr_string(&ni->rip_dest));
if (ni->rip_dest_mask)
printf("/%s", ipaddr_string(&ni->rip_dest_mask));
@ -94,9 +158,8 @@ rip_entry_print(register int vers, register const struct rip_netinfo *ni)
printf("->%s", ipaddr_string(&ni->rip_router));
if (ni->rip_tag)
printf(" tag %04x", EXTRACT_16BITS(&ni->rip_tag));
printf("}");
printf("}(%d)", EXTRACT_32BITS(&ni->rip_metric));
}
printf("(%d)", EXTRACT_32BITS(&ni->rip_metric));
}
void
@ -107,60 +170,74 @@ rip_print(const u_char *dat, u_int length)
register int i, j, trunc;
i = min(length, snapend - dat) - sizeof(*rp);
if (i < 0)
if (i < 0) {
printf(" [|rip]");
return;
}
rp = (struct rip *)dat;
switch (rp->rip_cmd) {
case RIPCMD_REQUEST:
printf(" rip-req %d", length);
break;
case RIPCMD_RESPONSE:
j = length / sizeof(*ni);
if (j * sizeof(*ni) != length - 4)
printf(" rip-resp %d[%d]:", j, length);
else
printf(" rip-resp %d:", j);
trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
ni = (struct rip_netinfo *)(rp + 1);
for (; (i -= sizeof(*ni)) >= 0; ++ni)
rip_entry_print(rp->rip_vers, ni);
if (trunc)
printf("[|rip]");
break;
case RIPCMD_TRACEON:
printf(" rip-traceon %d: \"", length);
(void)fn_print((const u_char *)(rp + 1), snapend);
fputs("\"\n", stdout);
break;
case RIPCMD_TRACEOFF:
printf(" rip-traceoff %d", length);
break;
case RIPCMD_POLL:
printf(" rip-poll %d", length);
break;
case RIPCMD_POLLENTRY:
printf(" rip-pollentry %d", length);
break;
default:
printf(" rip-#%d %d", rp->rip_cmd, length);
break;
}
switch (rp->rip_vers) {
case 1:
case 2:
case 0:
/*
* RFC 1058.
*
* XXX - RFC 1058 says
*
* 0 Datagrams whose version number is zero are to be ignored.
* These are from a previous version of the protocol, whose
* packet format was machine-specific.
*
* so perhaps we should just dump the first few words of
* the packet, in hex.
*/
printf(" RIPv0: ");
ni = (struct rip_netinfo *)(rp + 1);
rip_printblk((u_char *)&ni->rip_family,
(u_char *)&ni->rip_metric +
sizeof(ni->rip_metric));
break;
default:
printf(" [vers %d]", rp->rip_vers);
break;
}
switch (rp->rip_cmd) {
case RIPCMD_REQUEST:
printf(" RIPv%d-req %d", rp->rip_vers, length);
break;
case RIPCMD_RESPONSE:
j = length / sizeof(*ni);
if (j * sizeof(*ni) != length - 4)
printf(" RIPv%d-resp [items %d] [%d]:",
rp->rip_vers, j, length);
else
printf(" RIPv%d-resp [items %d]:",
rp->rip_vers, j);
trunc = (i / sizeof(*ni)) != j;
ni = (struct rip_netinfo *)(rp + 1);
for (; (i -= sizeof(*ni)) >= 0; ++ni) {
if (rp->rip_vers == 1)
rip_entry_print_v1(rp->rip_vers, ni);
else
rip_entry_print_v2(rp->rip_vers, ni);
}
if (trunc)
printf("[|rip]");
break;
case RIPCMD_TRACEON:
printf(" RIPv%d-traceon %d: \"", rp->rip_vers, length);
(void)fn_print((const u_char *)(rp + 1), snapend);
fputs("\"\n", stdout);
break;
case RIPCMD_TRACEOFF:
printf(" RIPv%d-traceoff %d", rp->rip_vers, length);
break;
case RIPCMD_POLL:
printf(" RIPv%d-poll %d", rp->rip_vers, length);
break;
case RIPCMD_POLLENTRY:
printf(" RIPv%d-pollentry %d", rp->rip_vers, length);
break;
default:
printf(" RIPv%d-#%d %d", rp->rip_vers, rp->rip_cmd,
length);
break;
}
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-rt6.c,v 1.5 2000/04/24 13:02:30 itojun Exp $ */
/* $NetBSD: print-rt6.c,v 1.6 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
@ -27,7 +27,7 @@ static const char rcsid[] =
"@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)";
#else
#include <sys/cdefs.h>
__RCSID("$NetBSD: print-rt6.c,v 1.5 2000/04/24 13:02:30 itojun Exp $");
__RCSID("$NetBSD: print-rt6.c,v 1.6 2001/01/28 10:05:07 itojun Exp $");
#endif
#endif
@ -65,12 +65,13 @@ rt6_print(register const u_char *bp, register const u_char *bp2)
register const struct ip6_hdr *ip;
register const u_char *ep;
int i, len;
register const struct in6_addr *addr;
dp = (struct ip6_rthdr *)bp;
ip = (struct ip6_hdr *)bp2;
len = dp->ip6r_len;
/* 'ep' points to the end of avaible data. */
/* 'ep' points to the end of available data. */
ep = snapend;
#if 0
@ -81,36 +82,36 @@ rt6_print(register const u_char *bp, register const u_char *bp2)
TCHECK(dp->ip6r_segleft);
printf("srcrt (len=%d, ", dp->ip6r_len);
printf("type=%d, ", dp->ip6r_type);
printf("segleft=%d, ", dp->ip6r_segleft);
printf("srcrt (len=%d", dp->ip6r_len); /*)*/
printf(", type=%d", dp->ip6r_type);
printf(", segleft=%d", dp->ip6r_segleft);
switch (dp->ip6r_type) {
#ifndef IPV6_RTHDR_TYPE_0
#define IPV6_RTHDR_TYPE_0 0
#endif
case IPV6_RTHDR_TYPE_0:
dp0 = (struct ip6_rthdr0 *)dp;
TCHECK(dp0->ip6r0_reserved);
if (dp0->ip6r0_reserved || vflag) {
printf("rsv=0x%0x, ",
(u_int32_t)ntohl(dp0->ip6r0_reserved));
printf(", rsv=0x%0x",
(u_int32_t)ntohl(dp0->ip6r0_reserved));
}
if (len % 2 == 1)
goto trunc;
len >>= 1;
addr = &dp0->ip6r0_addr[0];
for (i = 0; i < len; i++) {
struct in6_addr *addr;
addr = ((struct in6_addr *)(dp0 + 1)) + i;
if ((u_char *)addr > ep - sizeof(*addr))
if ((u_char *)(addr + 1) > ep)
goto trunc;
printf("[%d]%s", i, ip6addr_string((u_char *)addr));
if (i != len - 1)
printf(", ");
printf(", [%d]%s", i, ip6addr_string(addr));
addr++;
}
printf(")");
/*(*/
printf(") ");
return((dp0->ip6r0_len + 1) << 3);
break;
default:

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-tcp.c,v 1.19 2000/08/01 17:39:46 itojun Exp $ */
/* $NetBSD: print-tcp.c,v 1.20 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-tcp.c,v 1.55 97/06/15 13:20:28 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-tcp.c,v 1.19 2000/08/01 17:39:46 itojun Exp $");
__RCSID("$NetBSD: print-tcp.c,v 1.20 2001/01/28 10:05:07 itojun Exp $");
#endif
#endif
@ -149,7 +149,7 @@ static int tcp_cksum(register const struct ip *ip,
sum += *sp++;
if (tlen & 1) {
sum += htons( (*(const char *)sp) << 8);
sum += htons( (*(const u_int8_t *)sp) << 8);
}
while (sum > 0xffff)
@ -197,7 +197,7 @@ static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp,
sum += *sp++;
if (tlen & 1)
sum += htons((*(const char *)sp) << 8);
sum += htons((*(const u_int8_t *)sp) << 8);
while (sum > 0xffff)
sum = (sum & 0xffff) + (sum >> 16);
@ -207,10 +207,9 @@ static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp,
}
#endif
void
tcp_print(register const u_char *bp, register u_int length,
register const u_char *bp2)
register const u_char *bp2, int fragmented)
{
register const struct tcphdr *tp;
register const struct ip *ip;
@ -232,9 +231,10 @@ tcp_print(register const u_char *bp, register u_int length,
ip6 = NULL;
#endif /*INET6*/
ch = '\0';
TCHECK(*tp);
if (length < sizeof(*tp)) {
(void)printf("truncated-tcp %d", length);
if (!TTEST(tp->th_dport)) {
(void)printf("%s > %s: [|tcp]",
ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
return;
}
@ -329,7 +329,7 @@ tcp_print(register const u_char *bp, register u_int length,
* both directions).
*/
#ifdef INET6
bzero(&tha, sizeof(tha));
memset(&tha, 0, sizeof(tha));
rev = 0;
if (ip6) {
if (sport > dport) {
@ -390,7 +390,7 @@ tcp_print(register const u_char *bp, register u_int length,
sizeof(th->addr)))
break;
if (!th->nxt || flags & TH_SYN) {
if (!th->nxt || (flags & TH_SYN)) {
/* didn't find it or new conversation */
if (th->nxt == NULL) {
th->nxt = (struct tcp_seq_hash *)
@ -416,7 +416,7 @@ tcp_print(register const u_char *bp, register u_int length,
return;
}
if (ip->ip_v == 4 && vflag) {
if (ip->ip_v == 4 && vflag && !fragmented) {
int sum;
if (TTEST2(tp->th_sport, length)) {
sum = tcp_cksum(ip, tp, length);
@ -427,7 +427,7 @@ tcp_print(register const u_char *bp, register u_int length,
}
}
#ifdef INET6
if (ip->ip_v == 6 && ip6->ip6_plen && vflag) {
if (ip->ip_v == 6 && ip6->ip6_plen && vflag && !fragmented) {
int sum;
if (TTEST2(tp->th_sport, length)) {
sum = tcp6_cksum(ip6, tp, length);
@ -440,9 +440,8 @@ tcp_print(register const u_char *bp, register u_int length,
#endif
length -= hlen;
if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST))
(void)printf(" %lu:%lu(%d)", (long) seq, (long) (seq + length),
length);
if (vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST))
(void)printf(" %u:%u(%d)", seq, seq + length, length);
if (flags & TH_ACK)
(void)printf(" ack %u", ack);

View File

@ -1,4 +1,4 @@
/* $NetBSD: print-udp.c,v 1.15 2000/08/01 17:39:46 itojun Exp $ */
/* $NetBSD: print-udp.c,v 1.16 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-udp.c,v 1.60 97/07/27 21:58:48 leres Exp (LBL)";
#else
__RCSID("$NetBSD: print-udp.c,v 1.15 2000/08/01 17:39:46 itojun Exp $");
__RCSID("$NetBSD: print-udp.c,v 1.16 2001/01/28 10:05:07 itojun Exp $");
#endif
#endif
@ -71,14 +71,14 @@ __RCSID("$NetBSD: print-udp.c,v 1.15 2000/08/01 17:39:46 itojun Exp $");
#include "bootp.h"
struct rtcphdr {
u_short rh_flags; /* T:2 P:1 CNT:5 PT:8 */
u_short rh_len; /* length of message (in words) */
u_int rh_ssrc; /* synchronization src id */
u_int16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */
u_int16_t rh_len; /* length of message (in words) */
u_int32_t rh_ssrc; /* synchronization src id */
};
typedef struct {
u_int upper; /* more significant 32 bits */
u_int lower; /* less significant 32 bits */
u_int32_t upper; /* more significant 32 bits */
u_int32_t lower; /* less significant 32 bits */
} ntp64;
/*
@ -86,9 +86,9 @@ typedef struct {
*/
struct rtcp_sr {
ntp64 sr_ntp; /* 64-bit ntp timestamp */
u_int sr_ts; /* reference media timestamp */
u_int sr_np; /* no. packets sent */
u_int sr_nb; /* no. bytes sent */
u_int32_t sr_ts; /* reference media timestamp */
u_int32_t sr_np; /* no. packets sent */
u_int32_t sr_nb; /* no. bytes sent */
};
/*
@ -96,12 +96,12 @@ struct rtcp_sr {
* Time stamps are middle 32-bits of ntp timestamp.
*/
struct rtcp_rr {
u_int rr_srcid; /* sender being reported */
u_int rr_nl; /* no. packets lost */
u_int rr_ls; /* extended last seq number received */
u_int rr_dv; /* jitter (delay variance) */
u_int rr_lsr; /* orig. ts from last rr from this src */
u_int rr_dlsr; /* time from recpt of last rr to xmit time */
u_int32_t rr_srcid; /* sender being reported */
u_int32_t rr_nl; /* no. packets lost */
u_int32_t rr_ls; /* extended last seq number received */
u_int32_t rr_dv; /* jitter (delay variance) */
u_int32_t rr_lsr; /* orig. ts from last rr from this src */
u_int32_t rr_dlsr; /* time from recpt of last rr to xmit time */
};
/*XXX*/
@ -123,7 +123,7 @@ static void
vat_print(const void *hdr, u_int len, register const struct udphdr *up)
{
/* vat/vt audio */
u_int ts = *(u_short *)hdr;
u_int ts = *(u_int16_t *)hdr;
if ((ts & 0xf060) != 0) {
/* probably vt */
(void)printf(" udp/vt %u %d / %d",
@ -131,8 +131,8 @@ vat_print(const void *hdr, u_int len, register const struct udphdr *up)
ts & 0x3ff, ts >> 10);
} else {
/* probably vat */
u_int i0 = ntohl(((u_int *)hdr)[0]);
u_int i1 = ntohl(((u_int *)hdr)[1]);
u_int32_t i0 = (u_int32_t)ntohl(((u_int *)hdr)[0]);
u_int32_t i1 = (u_int32_t)ntohl(((u_int *)hdr)[1]);
printf(" udp/vat %u c%d %u%s",
(u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up) - 8),
i0 & 0xffff,
@ -151,8 +151,8 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
/* rtp v1 or v2 */
u_int *ip = (u_int *)hdr;
u_int hasopt, hasext, contype, hasmarker;
u_int i0 = ntohl(((u_int *)hdr)[0]);
u_int i1 = ntohl(((u_int *)hdr)[1]);
u_int32_t i0 = (u_int32_t)ntohl(((u_int *)hdr)[0]);
u_int32_t i1 = (u_int32_t)ntohl(((u_int *)hdr)[1]);
u_int dlen = ntohs(up->uh_ulen) - sizeof(*up) - 8;
const char * ptype;
@ -186,7 +186,7 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up)
i0 & 0xffff,
i1);
if (vflag) {
printf(" %u", i1);
printf(" %u", (u_int32_t)ntohl(((u_int *)hdr)[2]));
if (hasopt) {
u_int i2, optlen;
do {
@ -223,7 +223,7 @@ rtcp_print(const u_char *hdr, const u_char *ep)
struct rtcp_sr *sr;
struct rtcphdr *rh = (struct rtcphdr *)hdr;
u_int len;
u_short flags;
u_int16_t flags;
int cnt;
double ts, dts;
if ((u_char *)(rh + 1) > ep) {
@ -240,7 +240,7 @@ rtcp_print(const u_char *hdr, const u_char *ep)
if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
printf(" [%d]", len);
if (vflag)
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
if ((u_char *)(sr + 1) > ep) {
printf(" [|rtcp]");
return (ep);
@ -258,18 +258,18 @@ rtcp_print(const u_char *hdr, const u_char *ep)
printf(" [%d]", len);
rr = (struct rtcp_rr *)(rh + 1);
if (vflag)
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
break;
case RTCP_PT_SDES:
printf(" sdes %d", len);
if (vflag)
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
cnt = 0;
break;
case RTCP_PT_BYE:
printf(" bye %d", len);
if (vflag)
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc));
cnt = 0;
break;
default:
@ -331,7 +331,7 @@ static int udp_cksum(register const struct ip *ip,
sum += *sp++;
if (tlen & 1) {
sum += htons( (*(const char *)sp) << 8);
sum += htons( (*(const u_int8_t *)sp) << 8);
}
while (sum > 0xffff)
@ -379,7 +379,7 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
sum += *sp++;
if (tlen & 1)
sum += htons((*(const char *)sp) << 8);
sum += htons((*(const u_int8_t *)sp) << 8);
while (sum > 0xffff)
sum = (sum & 0xffff) + (sum >> 16);
@ -404,12 +404,13 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
#ifdef INET6
#define RIPNG_PORT 521 /*XXX*/
#define DHCP6_PORT1 546 /*XXX*/
#define DHCP6_PORT2 547 /*XXX*/
#define DHCP6_SERV_PORT 546 /*XXX*/
#define DHCP6_CLI_PORT 547 /*XXX*/
#endif
void
udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
udp_print(register const u_char *bp, u_int length,
register const u_char *bp2, int fragmented)
{
register const struct udphdr *up;
register const struct ip *ip;
@ -432,11 +433,14 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
#endif /*INET6*/
cp = (u_char *)(up + 1);
if (cp > snapend) {
printf("[|udp]");
(void)printf("%s > %s: [|udp]",
ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst));
return;
}
if (length < sizeof(struct udphdr)) {
(void)printf(" truncated-udp %d", length);
(void)printf("%s > %s: truncated-udp %d",
ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst),
length);
return;
}
length -= sizeof(struct udphdr);
@ -444,6 +448,13 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
sport = ntohs(up->uh_sport);
dport = ntohs(up->uh_dport);
ulen = ntohs(up->uh_ulen);
if (ulen < 8) {
(void)printf("%s > %s: truncated-udplength %d",
ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst),
ulen);
return;
}
if (packettype) {
register struct rpc_msg *rp;
enum msg_type direction;
@ -567,7 +578,7 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
}
#endif
if (ip->ip_v == 4 && vflag) {
if (ip->ip_v == 4 && vflag && !fragmented) {
int sum = up->uh_sum;
if (sum == 0) {
(void)printf(" [no cksum]");
@ -580,7 +591,7 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
}
}
#ifdef INET6
if (ip->ip_v == 6 && ip6->ip6_plen && vflag) {
if (ip->ip_v == 6 && ip6->ip6_plen && vflag && !fragmented) {
int sum = up->uh_sum;
/* for IPv6, UDP checksum is mandatory */
if (TTEST2(cp[0], length)) {
@ -617,9 +628,10 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
#ifdef INET6
else if (ISPORT(RIPNG_PORT))
ripng_print((const u_char *)(up + 1), length);
else if (ISPORT(DHCP6_PORT1) || ISPORT(DHCP6_PORT2))
else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT)) {
dhcp6_print((const u_char *)(up + 1), length,
sport, dport);
}
#endif /*INET6*/
/*
* Kludge in test for whiteboard packets.

View File

@ -1,7 +1,7 @@
/* $NetBSD: route6d.h,v 1.2 1999/07/04 02:57:51 itojun Exp $ */
/* $NetBSD: route6d.h,v 1.3 2001/01/28 10:05:07 itojun Exp $ */
/*
* KAME Header: /cvsroot/hydrangea-freebsd/kit/src/tcpdump/Attic/route6d.h,v 1.1.2.1 1998/05/10 15:38:08 itojun Exp
* Header: /tcpdump/master/tcpdump/route6d.h,v 1.2 2000/04/28 11:14:49 itojun Exp
*/
#define RIP6_VERSION 1
@ -10,16 +10,16 @@
#define RIP6_RESPONSE 2
struct netinfo6 {
struct in6_addr rip6_dest;
u_short rip6_tag;
u_char rip6_plen;
u_char rip6_metric;
struct in6_addr rip6_dest;
u_int16_t rip6_tag;
u_int8_t rip6_plen;
u_int8_t rip6_metric;
};
struct rip6 {
u_char rip6_cmd;
u_char rip6_vers;
u_char rip6_res1[2];
u_int8_t rip6_cmd;
u_int8_t rip6_vers;
u_int8_t rip6_res1[2];
union {
struct netinfo6 ru6_nets[1];
char ru6_tracefile[1];

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcpdump.c,v 1.13 1999/10/05 20:37:22 is Exp $ */
/* $NetBSD: tcpdump.c,v 1.14 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -29,7 +29,7 @@ static const char rcsid[] =
#else
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\
The Regents of the University of California. All rights reserved.\n");
__RCSID("$NetBSD: tcpdump.c,v 1.13 1999/10/05 20:37:22 is Exp $");
__RCSID("$NetBSD: tcpdump.c,v 1.14 2001/01/28 10:05:07 itojun Exp $");
#endif
#endif
@ -265,6 +265,16 @@ main(int argc, char **argv)
case 'w':
WFileName = optarg;
break;
case 'x':
++xflag;
break;
case 'X':
++xflag;
++Xflag;
break;
#ifdef YYDEBUG
case 'Y':
{
@ -274,14 +284,6 @@ main(int argc, char **argv)
}
break;
#endif
case 'x':
++xflag;
break;
case 'X':
++Xflag;
break;
default:
usage();
/* NOTREACHED */

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.8 2000/10/31 12:17:07 he Exp $ */
/* $NetBSD: util.c,v 1.9 2001/01/28 10:05:07 itojun Exp $ */
/*
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: util.c,v 1.58 97/05/09 14:52:17 leres Exp (LBL)";
#else
__RCSID("$NetBSD: util.c,v 1.8 2000/10/31 12:17:07 he Exp $");
__RCSID("$NetBSD: util.c,v 1.9 2001/01/28 10:05:07 itojun Exp $");
#endif
#endif
@ -145,6 +145,33 @@ ts_print(register const struct timeval *tvp)
}
}
/*
* Print a relative number of seconds (e.g. hold time, prune timer)
* in the form 5m1s. This does no truncation, so 32230861 seconds
* is represented as 1y1w1d1h1m1s.
*/
void
relts_print(int secs)
{
static char *lengths[] = {"y", "w", "d", "h", "m", "s"};
static int seconds[] = {31536000, 604800, 86400, 3600, 60, 1};
char **l = lengths;
int *s = seconds;
if (secs <= 0) {
(void)printf("0s");
return;
}
while (secs > 0) {
if (secs >= *s) {
(void)printf("%d%s", secs / *s, *l);
secs -= (secs / *s) * *s;
}
s++;
l++;
}
}
/*
* Convert a token value to a string; use "fmt" if not found.
*/