]> The Tcpdump Group git mirrors - libpcap/commitdiff
Check for, and squelch, signed vs. unsigned comparison errors.
authorGuy Harris <[email protected]>
Mon, 25 Jul 2016 23:05:27 +0000 (16:05 -0700)
committerGuy Harris <[email protected]>
Mon, 25 Jul 2016 23:05:27 +0000 (16:05 -0700)
Use -Wsign-compare if the compiler supports it.

If we're comparing an unsigned value with a signed value, and we've
already determined that the signed value is >= 0, just cast it to an
unsigned type.

Use 0xffffffffU instead of -1 as the "unknown"/"unset"/etc. value for
unsigned variables and fields.

Assign the result of str2tok() to an int, not a u_int, as it can return
-1.

Declare some variables and fields unsigned if they don't need to be
signed.  Make sure some arguments passed into "set" functions are
non-negative (and otherwise not invalid).

In the BPF optimizer, cast the "constant" fields of a struct block to an
unsigned type - the actual constant field of a BPF instruction is
unsigned.

Also, cast away one warning from MSVC.

aclocal.m4
bpf/net/bpf_filter.c
configure
gencode.c
grammar.y
optimize.c
pcap-bpf.c
pcap-int.h
pcap.c
sf-pcap-ng.c
sf-pcap.c

index fd5b751b06e78ff8c700b054bc4b878ab8e159c3..cfbedcc27146d511aefed2a77a466afb23d3845d 100644 (file)
@@ -926,6 +926,7 @@ AC_DEFUN(AC_LBL_DEVEL,
            if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
                    AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR()
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
+                   AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wdeclaration-after-statement)
index c6660877d0330eb401248662fbf38545c5087097..1ce22f4c694ed956b151ff9509539dc022e3aa7f 100644 (file)
@@ -734,7 +734,7 @@ bpf_validate(f, len)
 #if defined(KERNEL) || defined(_KERNEL)
                                if (from + p->k < from || from + p->k >= len)
 #else
-                               if (from + p->k >= len)
+                               if (from + p->k >= (u_int)len)
 #endif
                                        return 0;
                                break;
@@ -742,7 +742,7 @@ bpf_validate(f, len)
                        case BPF_JGT:
                        case BPF_JGE:
                        case BPF_JSET:
-                               if (from + p->jt >= len || from + p->jf >= len)
+                               if (from + p->jt >= (u_int)len || from + p->jf >= (u_int)len)
                                        return 0;
                                break;
                        default:
index 98fa0e6ba484807905f0d287a3774ccd73c02cb9..5df76e94ca125bf60f92e1073097457063bdeb97 100755 (executable)
--- a/configure
+++ b/configure
@@ -7793,6 +7793,49 @@ fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wsign-compare option" >&5
+$as_echo_n "checking whether the compiler supports the -Wsign-compare option... " >&6; }
+       save_CFLAGS="$CFLAGS"
+       if expr "x-Wsign-compare" : "x-W.*" >/dev/null
+       then
+           CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wsign-compare"
+       elif expr "x-Wsign-compare" : "x-f.*" >/dev/null
+       then
+           CFLAGS="$CFLAGS -Werror -Wsign-compare"
+       elif expr "x-Wsign-compare" : "x-m.*" >/dev/null
+       then
+           CFLAGS="$CFLAGS -Werror -Wsign-compare"
+       else
+           CFLAGS="$CFLAGS -Wsign-compare"
+       fi
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+return 0
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+               CFLAGS="$save_CFLAGS"
+               V_CCOPT="$V_CCOPT -Wsign-compare"
+
+else
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+               CFLAGS="$save_CFLAGS"
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+
        { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wmissing-prototypes option" >&5
 $as_echo_n "checking whether the compiler supports the -Wmissing-prototypes option... " >&6; }
        save_CFLAGS="$CFLAGS"
index 0cf2bfa6ae68866b661c8f8ddedb24a0215ee617..a4cd20473080db76958ac33df9e289bbcebfda83 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -193,6 +193,11 @@ struct addrinfo {
        (cs)->is_geneve = 0; \
 }
 
+/*
+ * Offset "not set" value.
+ */
+#define OFFSET_NOT_SET 0xffffffffU
+
 /*
  * Absolute offsets, which are offsets from the beginning of the raw
  * packet data, are, in the general case, the sum of a variable value
@@ -335,8 +340,8 @@ struct _compiler_state {
         *
         * For Linux cooked sockets, it's the offset of the type field.
         *
-        * off_linktype.constant_part is set to -1 for no encapsulation,
-        * in which case, IP is assumed.
+        * off_linktype.constant_part is set to OFFSET_NOT_SET for no
+        * encapsulation, in which case, IP is assumed.
         */
        bpf_abs_offset off_linktype;
 
@@ -1107,7 +1112,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                 * SLIP doesn't have a link level type.  The 16 byte
                 * header is hacked into our SLIP driver.
                 */
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                cstate->off_linkpl.constant_part = 16;
                cstate->off_nl = 0;
                cstate->off_nl_nosnap = 0;      /* no 802.2 LLC */
@@ -1115,7 +1120,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
 
        case DLT_SLIP_BSDOS:
                /* XXX this may be the same as the DLT_PPP_BSDOS case */
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                /* XXX end */
                cstate->off_linkpl.constant_part = 24;
                cstate->off_nl = 0;
@@ -1301,7 +1306,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
        case DLT_RAW:
        case DLT_IPV4:
        case DLT_IPV6:
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                cstate->off_linkpl.constant_part = 0;
                cstate->off_nl = 0;
                cstate->off_nl_nosnap = 0;      /* no 802.2 LLC */
@@ -1320,7 +1325,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                 * but really it just indicates whether there is a "short" or
                 * "long" DDP packet following.
                 */
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                cstate->off_linkpl.constant_part = 0;
                cstate->off_nl = 0;
                cstate->off_nl_nosnap = 0;      /* no 802.2 LLC */
@@ -1348,7 +1353,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                 * XXX - we should set this to handle SNAP-encapsulated
                 * frames (NLPID of 0x80).
                 */
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                cstate->off_linkpl.constant_part = 0;
                cstate->off_nl = 0;
                cstate->off_nl_nosnap = 0;      /* no 802.2 LLC */
@@ -1360,7 +1365,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                  * so lets start with offset 4 for now and increments later on (FIXME);
                  */
        case DLT_MFR:
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                cstate->off_linkpl.constant_part = 0;
                cstate->off_nl = 4;
                cstate->off_nl_nosnap = 0;      /* XXX - for now -> no 802.2 LLC */
@@ -1441,7 +1446,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
 
        case DLT_JUNIPER_ES:
                cstate->off_linktype.constant_part = 6;
-               cstate->off_linkpl.constant_part = -1;  /* not really a network layer but raw IP addresses */
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;      /* not really a network layer but raw IP addresses */
                cstate->off_nl = -1;            /* not really a network layer but raw IP addresses */
                cstate->off_nl_nosnap = -1;     /* no 802.2 LLC */
                break;
@@ -1454,36 +1459,36 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                break;
 
        case DLT_BACNET_MS_TP:
-               cstate->off_linktype.constant_part = -1;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
 
        case DLT_JUNIPER_SERVICES:
                cstate->off_linktype.constant_part = 12;
-               cstate->off_linkpl.constant_part = -1;  /* L3 proto location dep. on cookie type */
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;      /* L3 proto location dep. on cookie type */
                cstate->off_nl = -1;            /* L3 proto location dep. on cookie type */
                cstate->off_nl_nosnap = -1;     /* no 802.2 LLC */
                break;
 
        case DLT_JUNIPER_VP:
                cstate->off_linktype.constant_part = 18;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
 
        case DLT_JUNIPER_ST:
                cstate->off_linktype.constant_part = 18;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
 
        case DLT_JUNIPER_ISM:
                cstate->off_linktype.constant_part = 8;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
@@ -1493,7 +1498,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
        case DLT_JUNIPER_FIBRECHANNEL:
        case DLT_JUNIPER_ATM_CEMIC:
                cstate->off_linktype.constant_part = 8;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
@@ -1505,8 +1510,8 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                cstate->off_opc = 4;
                cstate->off_dpc = 4;
                cstate->off_sls = 7;
-               cstate->off_linktype.constant_part = -1;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
@@ -1518,8 +1523,8 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                cstate->off_opc = 8;
                cstate->off_dpc = 8;
                cstate->off_sls = 11;
-               cstate->off_linktype.constant_part = -1;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
@@ -1531,14 +1536,14 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                cstate->off_opc = 24;
                cstate->off_dpc = 24;
                cstate->off_sls = 27;
-               cstate->off_linktype.constant_part = -1;
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;
                cstate->off_nl_nosnap = -1;
                break;
 
        case DLT_PFSYNC:
-               cstate->off_linktype.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;
                cstate->off_linkpl.constant_part = 4;
                cstate->off_nl = 0;
                cstate->off_nl_nosnap = 0;
@@ -1548,8 +1553,8 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                /*
                 * Currently, only raw "link[N:M]" filtering is supported.
                 */
-               cstate->off_linktype.constant_part = -1;        /* variable, min 15, max 71 steps of 7 */
-               cstate->off_linkpl.constant_part = -1;
+               cstate->off_linktype.constant_part = OFFSET_NOT_SET;    /* variable, min 15, max 71 steps of 7 */
+               cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                cstate->off_nl = -1;            /* variable, min 16, max 71 steps of 7 */
                cstate->off_nl_nosnap = -1;     /* no 802.2 LLC */
                break;
@@ -1584,8 +1589,8 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
                 */
                if (cstate->linktype >= DLT_MATCHING_MIN &&
                    cstate->linktype <= DLT_MATCHING_MAX) {
-                       cstate->off_linktype.constant_part = -1;
-                       cstate->off_linkpl.constant_part = -1;
+                       cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+                       cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
                        cstate->off_nl = -1;
                        cstate->off_nl_nosnap = -1;
                } else {
@@ -3428,9 +3433,9 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * Does this link-layer header type have a field
                 * indicating the type of the next protocol?  If
                 * so, off_linktype.constant_part will be the offset of that
-                * field in the packet; if not, it will be -1.
+                * field in the packet; if not, it will be OFFSET_NOT_SET.
                 */
-               if (cstate->off_linktype.constant_part != (u_int)-1) {
+               if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) {
                        /*
                         * Yes; assume it's an Ethernet type.  (If
                         * it's not, it needs to be handled specially
@@ -6248,7 +6253,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
                        if (alist == NULL || *alist == NULL)
                                bpf_error(cstate, "unknown host '%s'", name);
                        tproto = proto;
-                       if (cstate->off_linktype.constant_part == (u_int)-1 &&
+                       if (cstate->off_linktype.constant_part == OFFSET_NOT_SET &&
                            tproto == Q_DEFAULT)
                                tproto = Q_IP;
                        b = gen_host(cstate, **alist++, 0xffffffff, tproto, dir, q.addr);
@@ -6267,7 +6272,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
                        cstate->ai = res;
                        b = tmp = NULL;
                        tproto = tproto6 = proto;
-                       if (cstate->off_linktype.constant_part == -1 &&
+                       if (cstate->off_linktype.constant_part == OFFSET_NOT_SET &&
                            tproto == Q_DEFAULT) {
                                tproto = Q_IP;
                                tproto6 = Q_IPV6;
index a1460f524480708e79349770fdca5ca5596e15ca..8e1d40a7ceeedd98bd2b500c87890fb0d5bf6bbe 100644 (file)
--- a/grammar.y
+++ b/grammar.y
@@ -620,7 +620,7 @@ pllc:       LLC                     { $$ = gen_llc(cstate); }
                                  else if (pcap_strcasecmp($2, "u") == 0)
                                        $$ = gen_llc_u(cstate);
                                  else {
-                                       u_int subtype;
+                                       int subtype;
 
                                        subtype = str2tok($2, llc_s_subtypes);
                                        if (subtype != -1)
index d0a906838680e89eed546aa01206334828b4c2d6..baa9427c63076e74823500681912411e0585793f 100644 (file)
@@ -885,7 +885,7 @@ opt_peep(opt_state_t *opt_state, struct block *b)
        if (b->s.code == (BPF_JMP|BPF_K|BPF_JSET)) {
                if (b->s.k == 0)
                        JT(b) = JF(b);
-               if (b->s.k == 0xffffffff)
+               if ((u_int)b->s.k == 0xffffffffU)
                        JF(b) = JT(b);
        }
        /*
@@ -913,11 +913,11 @@ opt_peep(opt_state_t *opt_state, struct block *b)
                        break;
 
                case BPF_JGT:
-                       v = (unsigned)v > b->s.k;
+                       v = (unsigned)v > (unsigned)b->s.k;
                        break;
 
                case BPF_JGE:
-                       v = (unsigned)v >= b->s.k;
+                       v = (unsigned)v >= (unsigned)b->s.k;
                        break;
 
                case BPF_JSET:
@@ -2046,7 +2046,7 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state,
        dst = conv_state->ftail -= (slen + 1 + p->longjt + p->longjf);
                /* inflate length by any extra jumps */
 
-       p->offset = dst - conv_state->fstart;
+       p->offset = (int)(dst - conv_state->fstart);
 
        /* generate offset[] for convenience  */
        if (slen) {
index b7fe0856959e485a4d446f15f3ff34507e43c360..17732056a477c9c95b5fb2ab0ddf6e0d5d16ef27 100644 (file)
@@ -2123,7 +2123,7 @@ pcap_activate_bpf(pcap_t *p)
                                         * the default mode, attempt to
                                         * select the new mode.
                                         */
-                                       if (new_dlt != v) {
+                                       if ((u_int)new_dlt != v) {
                                                if (ioctl(p->fd, BIOCSDLT,
                                                    &new_dlt) != -1) {
                                                        /*
@@ -2765,7 +2765,7 @@ static int
 find_802_11(struct bpf_dltlist *bdlp)
 {
        int new_dlt;
-       int i;
+       u_int i;
 
        /*
         * Scan the list of DLT_ values, looking for 802.11 values,
index 1d72adbd297856f9bdbcd6727ce3a0f1cc1ada2c..2726b91c51692ba6ee7cd8dafedecfc2394ff4b0 100644 (file)
@@ -110,7 +110,7 @@ extern "C" {
 struct pcap_opt {
        char    *device;
        int     timeout;        /* timeout for buffering */
-       int     buffer_size;
+       u_int   buffer_size;
        int     promisc;
        int     rfmon;          /* monitor mode */
        int     immediate;      /* immediate mode - deliver packets as soon as they arrive */
@@ -169,7 +169,7 @@ struct pcap {
        /*
         * Read buffer.
         */
-       int bufsize;
+       u_int bufsize;
        void *buffer;
        u_char *bp;
        int cc;
diff --git a/pcap.c b/pcap.c
index 38078a8cdc9d83d26e6d74bc08a0b03d800e1f17..5e202a54459265f298fc9c4c57b19d3ef74508c6 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -587,9 +587,9 @@ pcap_create_common(char *ebuf, size_t size)
        initialize_ops(p);
 
        /* put in some defaults*/
-       pcap_set_snaplen(p, MAXIMUM_SNAPLEN);   /* max packet size */
-       p->opt.timeout = 0;                     /* no timeout specified */
-       p->opt.buffer_size = 0;                 /* use the platform's default */
+       p->snapshot = MAXIMUM_SNAPLEN;  /* max packet size */
+       p->opt.timeout = 0;             /* no timeout specified */
+       p->opt.buffer_size = 0;         /* use the platform's default */
        p->opt.promisc = 0;
        p->opt.rfmon = 0;
        p->opt.immediate = 0;
@@ -620,6 +620,16 @@ pcap_set_snaplen(pcap_t *p, int snaplen)
 {
        if (pcap_check_activated(p))
                return (PCAP_ERROR_ACTIVATED);
+
+       /*
+        * Turn invalid values, or excessively large values, into
+        * the maximum allowed value.
+        *
+        * If some application really *needs* a bigger snapshot
+        * length, we should just increase MAXIMUM_SNAPLEN.
+        */
+       if (snaplen <= 0 || snaplen > MAXIMUM_SNAPLEN)
+               snaplen = MAXIMUM_SNAPLEN;
        p->snapshot = snaplen;
        return (0);
 }
@@ -659,6 +669,13 @@ pcap_set_tstamp_type(pcap_t *p, int tstamp_type)
        if (pcap_check_activated(p))
                return (PCAP_ERROR_ACTIVATED);
 
+       /*
+        * The argument should have been u_int, but that's too late
+        * to change now - it's an API.
+        */
+       if (tstamp_type < 0)
+               return (PCAP_WARNING_TSTAMP_TYPE_NOTSUP);
+
        /*
         * If p->tstamp_type_count is 0, we only support PCAP_TSTAMP_HOST;
         * the default time stamp type is PCAP_TSTAMP_HOST.
@@ -673,7 +690,7 @@ pcap_set_tstamp_type(pcap_t *p, int tstamp_type)
                 * Check whether we claim to support this type of time stamp.
                 */
                for (i = 0; i < p->tstamp_type_count; i++) {
-                       if (p->tstamp_type_list[i] == tstamp_type) {
+                       if (p->tstamp_type_list[i] == (u_int)tstamp_type) {
                                /*
                                 * Yes.
                                 */
@@ -703,6 +720,12 @@ pcap_set_buffer_size(pcap_t *p, int buffer_size)
 {
        if (pcap_check_activated(p))
                return (PCAP_ERROR_ACTIVATED);
+       if (buffer_size <= 0) {
+               /*
+                * Silently ignore invalid values.
+                */
+               return (0);
+       }
        p->opt.buffer_size = buffer_size;
        return (0);
 }
@@ -715,6 +738,13 @@ pcap_set_tstamp_precision(pcap_t *p, int tstamp_precision)
        if (pcap_check_activated(p))
                return (PCAP_ERROR_ACTIVATED);
 
+       /*
+        * The argument should have been u_int, but that's too late
+        * to change now - it's an API.
+        */
+       if (tstamp_precision < 0)
+               return (PCAP_ERROR_TSTAMP_PRECISION_NOTSUP);
+
        /*
         * If p->tstamp_precision_count is 0, we only support setting
         * the time stamp precision to microsecond precision; every
@@ -733,7 +763,7 @@ pcap_set_tstamp_precision(pcap_t *p, int tstamp_precision)
                 * time stamp.
                 */
                for (i = 0; i < p->tstamp_precision_count; i++) {
-                       if (p->tstamp_precision_list[i] == tstamp_precision) {
+                       if (p->tstamp_precision_list[i] == (u_int)tstamp_precision) {
                                /*
                                 * Yes.
                                 */
@@ -973,6 +1003,9 @@ pcap_set_datalink(pcap_t *p, int dlt)
        int i;
        const char *dlt_name;
 
+       if (dlt < 0)
+               goto unsupported;
+
        if (p->dlt_count == 0 || p->set_datalink_op == NULL) {
                /*
                 * We couldn't fetch the list of DLTs, or we don't
@@ -990,7 +1023,7 @@ pcap_set_datalink(pcap_t *p, int dlt)
                return (0);
        }
        for (i = 0; i < p->dlt_count; i++)
-               if (p->dlt_list[i] == dlt)
+               if (p->dlt_list[i] == (u_int)dlt)
                        break;
        if (i >= p->dlt_count)
                goto unsupported;
index ea44da916d2da1195bf36c4f3b2ecc7de5de7883..c9b282acb951db5575bfa4e5b31067036faa8420 100644 (file)
@@ -1107,7 +1107,7 @@ pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data)
                         * and the packet length.
                         */
                        hdr->caplen = hdr->len;
-                       if (hdr->caplen > p->snapshot)
+                       if (hdr->caplen > (bpf_u_int32)p->snapshot)
                                hdr->caplen = p->snapshot;
                        t = 0;  /* no time stamps */
                        goto found;
@@ -1173,7 +1173,7 @@ pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data)
                                    idbp->linktype);
                                return (-1);
                        }
-                       if (p->snapshot != idbp->snaplen) {
+                       if ((bpf_u_int32)p->snapshot != idbp->snaplen) {
                                pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                                    "an interface has a snapshot length %u different from the type of the first interface",
                                    idbp->snaplen);
index 55c9a5795266ccf2486fb76af0a600844da01c8d..061964d19a5ee5702e4e990e97a5b16c034dd8d3 100644 (file)
--- a/sf-pcap.c
+++ b/sf-pcap.c
@@ -876,13 +876,13 @@ pcap_dump_open_append(pcap_t *p, const char *fname)
                        fclose(f);
                        return (NULL);
                }
-               if (linktype != ph.linktype) {
+               if ((bpf_u_int32)linktype != ph.linktype) {
                        pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                            "%s: different linktype, cannot append to file", fname);
                        fclose(f);
                        return (NULL);
                }
-               if (p->snapshot != ph.snaplen) {
+               if ((bpf_u_int32)p->snapshot != ph.snaplen) {
                        pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                            "%s: different snaplen, cannot append to file", fname);
                        fclose(f);