Fix up some errors from the previous checkin.

Fix up some const and unsigned issues.

Make static some routines unused outside the file in which they're
defined.
diff --git a/ip6.h b/ip6.h
index 78b17a3..8e73b94 100644
--- a/ip6.h
+++ b/ip6.h
@@ -1,4 +1,4 @@
-/* @(#) $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 $	*/
 
@@ -187,9 +187,8 @@
 	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_ */
diff --git a/print-dhcp6.c b/print-dhcp6.c
index 9c04526..b23b788 100644
--- a/print-dhcp6.c
+++ b/print-dhcp6.c
@@ -32,7 +32,7 @@
 
 #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
@@ -130,7 +130,7 @@
 	/* type-dependent data follows */
 };
 
-static char *
+static const char *
 dhcp6opt_name(int type)
 {
 	static char genstr[sizeof("opt_65535") + 1]; /* XXX thread unsafe */
@@ -163,7 +163,7 @@
 	}
 }
 
-static char *
+static const char *
 dhcp6stcode(int code)
 {
 	static char genstr[sizeof("code255") + 1]; /* XXX thread unsafe */
@@ -201,7 +201,8 @@
 {
 	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;
@@ -210,11 +211,11 @@
 	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));
diff --git a/print-frag6.c b/print-frag6.c
index c3cbe2f..267ad65 100644
--- a/print-frag6.c
+++ b/print-frag6.c
@@ -21,7 +21,7 @@
 
 #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
@@ -58,19 +58,19 @@
 	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
diff --git a/print-icmp6.c b/print-icmp6.c
index 7daaa90..45a3bdd 100644
--- a/print-icmp6.c
+++ b/print-icmp6.c
@@ -21,7 +21,7 @@
 
 #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
@@ -48,12 +48,12 @@
 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))
@@ -111,7 +111,7 @@
 	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;
@@ -399,7 +399,7 @@
 }
 
 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;
@@ -407,12 +407,13 @@
 	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;
@@ -437,7 +438,7 @@
 		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;
@@ -445,10 +446,10 @@
 
 		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);
@@ -456,7 +457,7 @@
 
 		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;
@@ -471,7 +472,7 @@
 	return(NULL);		/* should be notreached, though */
 }
 
-void
+static void
 icmp6_opt_print(const u_char *bp, int resid)
 {
 	const struct nd_opt_hdr *op;
@@ -632,7 +633,7 @@
 #undef ECHECK
 }
 
-void
+static void
 mld6_print(const u_char *bp)
 {
 	struct mld6_hdr *mp = (struct mld6_hdr *)bp;
@@ -684,15 +685,17 @@
 	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;
@@ -931,8 +934,8 @@
 	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;
@@ -943,6 +946,8 @@
 	char hbuf[NI_MAXHOST];
 	int n;
 
+	if (ep < bp)
+		return;
 	dp = (struct icmp6_hdr *)bp;
 	rr6 = (struct icmp6_router_renum *)bp;
 	siz = ep - bp;
diff --git a/print-ospf6.c b/print-ospf6.c
index fb61c3d..4618579 100644
--- a/print-ospf6.c
+++ b/print-ospf6.c
@@ -23,7 +23,7 @@
 
 #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
@@ -37,6 +37,7 @@
 
 #include "interface.h"
 #include "addrtoname.h"
+#include "extract.h"
 
 #include "ospf6.h"
 
@@ -131,7 +132,7 @@
     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:
@@ -229,7 +230,7 @@
 static int
 ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp)
 {
-	int k;
+	u_int k;
 	struct in6_addr prefix;
 
 	TCHECK(*lsapp);
@@ -274,7 +275,8 @@
 #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))
diff --git a/print-ripng.c b/print-ripng.c
index 128b31a..b1f7ec2 100644
--- a/print-ripng.c
+++ b/print-ripng.c
@@ -21,7 +21,7 @@
 
 #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
@@ -71,14 +71,18 @@
 {
 	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) {
 
@@ -95,7 +99,8 @@
 		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
@@ -110,7 +115,8 @@
 		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