]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix up some errors from the previous checkin.
authorguy <guy>
Wed, 11 Dec 2002 22:29:21 +0000 (22:29 +0000)
committerguy <guy>
Wed, 11 Dec 2002 22:29:21 +0000 (22:29 +0000)
Fix up some const and unsigned issues.

Make static some routines unused outside the file in which they're
defined.

ip6.h
print-dhcp6.c
print-frag6.c
print-icmp6.c
print-ospf6.c
print-ripng.c

diff --git a/ip6.h b/ip6.h
index 78b17a352f3a20158c55a44937041c7705458341..8e73b9479da649f3090d860e8d43399bdf552504 100644 (file)
--- 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 @@ struct ip6_frag {
        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_ */
index 9c045264611550c24f27139e68dd074bb120fbf3..b23b78871f936c8f4ebfd419bafc628e2edb340d 100644 (file)
@@ -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 @@ struct dhcp6opt {
        /* 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 @@ dhcp6opt_name(int type)
        }
 }
 
-static char *
+static const char *
 dhcp6stcode(int code)
 {
        static char genstr[sizeof("code255") + 1]; /* XXX thread unsafe */
@@ -201,7 +201,8 @@ dhcp6opt_print(u_char *cp, u_char *ep)
 {
        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 @@ dhcp6opt_print(u_char *cp, u_char *ep)
        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));
index c3cbe2f5f51fe0399f521bf47c7f531d46577853..267ad6501280d035c60d499bbfca97c588e8a32c 100644 (file)
@@ -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 @@ frag6_print(register const u_char *bp, register const u_char *bp2)
        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
index 7daaa9064cb39f6437cfe2e1119d2f1955ac7ca4..45a3bddafd0222acb29c07b2d6058ae3e2edbc5b 100644 (file)
@@ -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 rcsid[] =
 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 @@ icmp6_print(const u_char *bp, const u_char *bp2)
        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 @@ trunc:
 }
 
 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 @@ get_upperlayer(u_char *bp, int *prot)
        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 @@ get_upperlayer(u_char *bp, int *prot)
                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 @@ get_upperlayer(u_char *bp, int *prot)
 
                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 @@ get_upperlayer(u_char *bp, int *prot)
 
                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 @@ get_upperlayer(u_char *bp, int *prot)
        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 @@ icmp6_opt_print(const u_char *bp, int resid)
 #undef ECHECK
 }
 
-void
+static void
 mld6_print(const u_char *bp)
 {
        struct mld6_hdr *mp = (struct mld6_hdr *)bp;
@@ -684,15 +685,17 @@ dnsname_print(const u_char *cp, const u_char *ep)
        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 @@ trunc:
        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 @@ icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep)
        char hbuf[NI_MAXHOST];
        int n;
 
+       if (ep < bp)
+               return;
        dp = (struct icmp6_hdr *)bp;
        rr6 = (struct icmp6_router_renum *)bp;
        siz = ep - bp;
index fb61c3d7f529362e29c7af3c5598e296c47ce77f..4618579be59e09f005393667758eb13971965583 100644 (file)
@@ -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 @@ static const char rcsid[] =
 
 #include "interface.h"
 #include "addrtoname.h"
+#include "extract.h"
 
 #include "ospf6.h"
 
@@ -131,7 +132,7 @@ ospf6_print_ls_type(register u_int ls_type,
     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 @@ trunc:
 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 @@ ospf6_print_lsa(register const struct lsa *lsap)
 #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))
index 128b31a6323c7cd0dba25607c22cac24b08bee20..b1f7ec273d90dac17c6134cc36f3fa5f59d855af 100644 (file)
@@ -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 @@ ripng_print(const u_char *dat, unsigned int length)
 {
        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 @@ ripng_print(const u_char *dat, unsigned int length)
                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 @@ ripng_print(const u_char *dat, unsigned int length)
                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