Fix up some const and unsigned issues.
Make static some routines unused outside the file in which they're
defined.
-/* @(#) $Header: /tcpdump/master/tcpdump/ip6.h,v 1.5 2002-12-11 07:13:53 guy Exp $ (LBL) */
+/* @(#) $Header: /tcpdump/master/tcpdump/ip6.h,v 1.6 2002-12-11 22:29:21 guy Exp $ (LBL) */
/* $NetBSD: ip6.h,v 1.9 2000/07/13 05:34:21 itojun Exp $ */
/* $KAME: ip6.h,v 1.9 2000/07/02 21:01:32 itojun Exp $ */
u_int32_t ip6f_ident; /* identification */
};
-/* network endian */
-#define IP6F_OFF_MASK ((u_int16_t)htons(0xfff8)) /* mask out offset from _offlg */
-#define IP6F_RESERVED_MASK ((u_int16_t)htons(0x0006)) /* reserved bits in ip6f_offlg */
-#define IP6F_MORE_FRAG ((u_int16_t)htons(0x0001)) /* more-fragments flag */
+#define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */
+#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
+#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
#endif /* not _NETINET_IP6_H_ */
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.23 2002-12-11 07:13:59 guy Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.24 2002-12-11 22:29:21 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
/* type-dependent data follows */
};
-static char *
+static const char *
dhcp6opt_name(int type)
{
static char genstr[sizeof("opt_65535") + 1]; /* XXX thread unsafe */
}
}
-static char *
+static const char *
dhcp6stcode(int code)
{
static char genstr[sizeof("code255") + 1]; /* XXX thread unsafe */
{
struct dhcp6opt *dh6o;
u_char *tp;
- int i, opttype;
+ size_t i;
+ u_int16_t opttype;
size_t optlen;
u_int16_t val16;
u_int32_t val32;
if (cp == ep)
return;
while (cp < ep) {
- if (ep - cp < sizeof(*dh6o))
+ if (ep < cp + sizeof(*dh6o))
goto trunc;
dh6o = (struct dhcp6opt *)cp;
optlen = EXTRACT_16BITS(&dh6o->dh6opt_len);
- if (ep - cp < sizeof(*dh6o) + optlen)
+ if (ep < cp + sizeof(*dh6o) + optlen)
goto trunc;
opttype = EXTRACT_16BITS(&dh6o->dh6opt_type);
printf(" (%s", dhcp6opt_name(opttype));
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.15 2002-12-11 07:14:00 guy Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.16 2002-12-11 22:29:21 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
if (vflag) {
printf("frag (0x%08x:%d|%ld)",
EXTRACT_32BITS(&dp->ip6f_ident),
- EXTRACT_16BITS(&dp->ip6f_offlg & IP6F_OFF_MASK),
+ EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK,
sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen) -
(long)(bp - bp2) - sizeof(struct ip6_frag));
} else {
printf("frag (%d|%ld)",
- EXTRACT_16BITS(&dp->ip6f_offlg & IP6F_OFF_MASK),
+ EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK,
sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen) -
(long)(bp - bp2) - sizeof(struct ip6_frag));
}
#if 1
/* it is meaningless to decode non-first fragment */
- if (EXTRACT_16BITS(&dp->ip6f_offlg & IP6F_OFF_MASK) != 0)
+ if ((EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK) != 0)
return 65535;
else
#endif
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.66 2002-12-11 07:14:01 guy Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.67 2002-12-11 22:29:21 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
static const char *get_rtpref(u_int);
static const char *get_lifetime(u_int32_t);
static void print_lladdr(const u_char *, size_t);
-void icmp6_opt_print(const u_char *, int);
-void mld6_print(const u_char *);
-static struct udphdr *get_upperlayer(u_char *, int *);
+static void icmp6_opt_print(const u_char *, int);
+static void mld6_print(const u_char *);
+static struct udphdr *get_upperlayer(u_char *, u_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 *);
+static void icmp6_nodeinfo_print(u_int, const u_char *, const u_char *);
+static void icmp6_rrenum_print(u_int, const u_char *, const u_char *);
#ifndef abs
#define abs(a) ((0 < (a)) ? (a) : -(a))
int dport;
const u_char *ep;
char buf[256];
- int icmp6len, prot;
+ u_int icmp6len, prot;
dp = (struct icmp6_hdr *)bp;
ip = (struct ip6_hdr *)bp2;
}
static struct udphdr *
-get_upperlayer(u_char *bp, int *prot)
+get_upperlayer(u_char *bp, u_int *prot)
{
const u_char *ep;
struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
struct ip6_hbh *hbh;
struct ip6_frag *fragh;
struct ah *ah;
- int nh, hlen;
+ u_int nh;
+ int hlen;
/* 'ep' points to the end of available data. */
ep = snapend;
- if (TTEST(ip6->ip6_nxt) == 0)
+ if (!TTEST(ip6->ip6_nxt))
return NULL;
nh = ip6->ip6_nxt;
case IPPROTO_DSTOPTS:
case IPPROTO_ROUTING:
hbh = (struct ip6_hbh *)bp;
- if (TTEST(hbh->ip6h_len) == 0)
+ if (!TTEST(hbh->ip6h_len))
return(NULL);
nh = hbh->ip6h_nxt;
hlen = (hbh->ip6h_len + 1) << 3;
case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
fragh = (struct ip6_frag *)bp;
- if (TTEST(fragh->ip6f_offlg) == 0)
+ if (!TTEST(fragh->ip6f_offlg))
return(NULL);
/* fragments with non-zero offset are meaningless */
- if ((fragh->ip6f_offlg & IP6F_OFF_MASK) != 0)
+ if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
return(NULL);
nh = fragh->ip6f_nxt;
hlen = sizeof(struct ip6_frag);
case IPPROTO_AH:
ah = (struct ah *)bp;
- if (TTEST(ah->ah_len) == 0)
+ if (!TTEST(ah->ah_len))
return(NULL);
nh = ah->ah_nxt;
hlen = (ah->ah_len + 2) << 2;
return(NULL); /* should be notreached, though */
}
-void
+static void
icmp6_opt_print(const u_char *bp, int resid)
{
const struct nd_opt_hdr *op;
#undef ECHECK
}
-void
+static void
mld6_print(const u_char *bp)
{
struct mld6_hdr *mp = (struct mld6_hdr *)bp;
printf("\"");
}
-void
-icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
+static void
+icmp6_nodeinfo_print(u_int icmp6len, const u_char *bp, const u_char *ep)
{
struct icmp6_nodeinfo *ni6;
struct icmp6_hdr *dp;
const u_char *cp;
- int siz, i;
+ size_t siz, i;
int needcomma;
+ if (ep < bp)
+ return;
dp = (struct icmp6_hdr *)bp;
ni6 = (struct icmp6_nodeinfo *)bp;
siz = ep - bp;
fputs("[|icmp6]", stdout);
}
-void
-icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep)
+static void
+icmp6_rrenum_print(u_int icmp6len, const u_char *bp, const u_char *ep)
{
struct icmp6_router_renum *rr6;
struct icmp6_hdr *dp;
char hbuf[NI_MAXHOST];
int n;
+ if (ep < bp)
+ return;
dp = (struct icmp6_hdr *)bp;
rr6 = (struct icmp6_router_renum *)bp;
siz = ep - bp;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.10 2002-12-11 07:14:06 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.11 2002-12-11 22:29:22 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h"
#include "ospf6.h"
register const rtrid_t *ls_stateid,
register const rtrid_t *ls_router, register const char *fmt)
{
- char *scope;
+ const char *scope;
switch (ls_type & LS_SCOPE_MASK) {
case LS_SCOPE_LINKLOCAL:
static int
ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp)
{
- int k;
+ u_int k;
struct in6_addr prefix;
TCHECK(*lsapp);
#if 0
register const u_int32_t *lp;
#endif
- register int j, k;
+ register u_int j;
+ register int k;
u_int32_t flags32;
if (ospf6_print_lshdr(&lsap->ls_hdr))
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.14 2002-12-11 07:14:08 guy Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.15 2002-12-11 22:29:22 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
{
register const struct rip6 *rp = (struct rip6 *)dat;
register const struct netinfo6 *ni;
- register int amt = snapend - dat;
- register int i = min(length, amt) -
- (sizeof(struct rip6) - sizeof(struct netinfo6));
+ register u_int amt;
+ register u_int i;
int j;
int trunc;
- if (i < 0)
+ if (snapend < dat)
return;
+ amt = snapend - dat;
+ i = min(length, amt);
+ if (i < (sizeof(struct rip6) - sizeof(struct netinfo6)))
+ return;
+ i -= (sizeof(struct rip6) - sizeof(struct netinfo6));
switch (rp->rip6_cmd) {
else
printf(" ripng-req %d:", j);
trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
- for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
+ for (ni = rp->rip6_nets; i >= sizeof(*ni);
+ i -= sizeof(*ni), ++ni) {
if (vflag > 1)
printf("\n\t");
else
else
printf(" ripng-resp %d:", j);
trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
- for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
+ for (ni = rp->rip6_nets; i >= sizeof(*ni);
+ i -= sizeof(*ni), ++ni) {
if (vflag > 1)
printf("\n\t");
else