]> The Tcpdump Group git mirrors - libpcap/commitdiff
Squelch more signed vs. unsigned comparison warnings.
authorGuy Harris <[email protected]>
Mon, 25 Jul 2016 23:24:02 +0000 (16:24 -0700)
committerGuy Harris <[email protected]>
Mon, 25 Jul 2016 23:24:02 +0000 (16:24 -0700)
pcap-can-linux.c
pcap-dbus.c
pcap-linux.c
pcap-netfilter-linux.c
pcap-usb-linux.c

index b3a0e414cf35b30bb83a1902fc7c83e05ccff2ad..5715f973f9b1fb94393de473cb6326297e3d6fd1 100644 (file)
@@ -225,6 +225,7 @@ can_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
        u_char *pktd;
        struct iovec iv;
        struct can_frame* cf;
+       int len;
 
        pktd = (u_char *)handle->buffer + CAN_CONTROL_SIZE;
        iv.iov_base = pktd;
@@ -238,20 +239,21 @@ can_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
 
        do
        {
-               pkth.caplen = recvmsg(handle->fd, &msg, 0);
+               len = recvmsg(handle->fd, &msg, 0);
                if (handle->break_loop)
                {
                        handle->break_loop = 0;
                        return -2;
                }
-       } while ((pkth.caplen == -1) && (errno == EINTR));
+       } while ((len == -1) && (errno == EINTR));
 
-       if (pkth.caplen == -1)
+       if (len == -1)
        {
                pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't receive packet %d:%s",
                        errno, strerror(errno));
                return -1;
        }
+       pkth.caplen = (bpf_u_int32)len;
 
        /* adjust capture len according to frame len */
        cf = (struct can_frame*)(void *)pktd;
index c5b80dee95fa2f4855f6f7b21a714ba5d4167e59..8e92093da11070a88c078353061fc8cebad4e15d 100644 (file)
@@ -163,7 +163,7 @@ dbus_activate(pcap_t *handle)
        const char *dev = handle->opt.device;
 
        DBusError error = DBUS_ERROR_INIT;
-       int i;
+       u_int i;
 
        if (strcmp(dev, "dbus-system") == 0) {
                if (!(handlep->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) {
index 8aea72cb076da8c18bd9d7cb07c5e9004e467840..bf84af450de12da11a03ead0920e253abd309c3f 100644 (file)
@@ -1862,7 +1862,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
 #endif
                                continue;
 
-                       len = packet_len > iov.iov_len ? iov.iov_len : packet_len;
+                       len = (u_int)packet_len > iov.iov_len ? iov.iov_len : packet_len;
                        if (len < (unsigned int) handlep->vlan_offset)
                                break;
 
@@ -4066,8 +4066,8 @@ create_ring(pcap_t *handle, int *status)
                                        *status = PCAP_ERROR;
                                        return -1;
                                }
-                               if (frame_size > mtu + 18)
-                                       frame_size = mtu + 18;
+                               if (frame_size > (unsigned int)mtu + 18)
+                                       frame_size = (unsigned int)mtu + 18;
                        }
                }
 
@@ -4743,7 +4743,7 @@ static int pcap_handle_packet_mmap(
         * Trim the snapshot length to be no longer than the
         * specified snapshot length.
         */
-       if (pcaphdr.caplen > handle->snapshot)
+       if (pcaphdr.caplen > (bpf_u_int32)handle->snapshot)
                pcaphdr.caplen = handle->snapshot;
 
        /* pass the packet to the user */
@@ -6016,7 +6016,7 @@ static const struct {
 static void
 iface_set_all_ts_types(pcap_t *handle)
 {
-       int i;
+       u_int i;
 
        handle->tstamp_type_count = NUM_SOF_TIMESTAMPING_TYPES;
        handle->tstamp_type_list = malloc(NUM_SOF_TIMESTAMPING_TYPES * sizeof(u_int));
@@ -6035,7 +6035,7 @@ iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf)
        struct ifreq ifr;
        struct ethtool_ts_info info;
        int num_ts_types;
-       int i, j;
+       u_int i, j;
 
        /*
         * This doesn't apply to the "any" device; you can't say "turn on
@@ -6450,8 +6450,8 @@ activate_old(pcap_t *handle)
                if (mtu == -1)
                        return PCAP_ERROR;
                handle->bufsize = MAX_LINKHEADER_SIZE + mtu;
-               if (handle->bufsize < handle->snapshot)
-                       handle->bufsize = handle->snapshot;
+               if (handle->bufsize < (u_int)handle->snapshot)
+                       handle->bufsize = (u_int)handle->snapshot;
        } else {
                /*
                 * This is a 2.2[.x] or later kernel.
@@ -6459,7 +6459,7 @@ activate_old(pcap_t *handle)
                 * We can safely pass "recvfrom()" a byte count
                 * based on the snapshot length.
                 */
-               handle->bufsize = handle->snapshot;
+               handle->bufsize = (u_int)handle->snapshot;
        }
 
        /*
index b1579141168aca8f568dd0d4b9d9df8cae73d5b6..684442016398591ca4125fb0b18656a516487dd3 100644 (file)
@@ -109,12 +109,12 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
        }
 
        buf = (unsigned char *)handle->buffer;
-       while (len >= NLMSG_SPACE(0)) {
+       while ((u_int)len >= NLMSG_SPACE(0)) {
                const struct nlmsghdr *nlh = (const struct nlmsghdr *) buf;
                u_int32_t msg_len;
                nftype_t type = OTHER;
 
-               if (nlh->nlmsg_len < sizeof(struct nlmsghdr) || len < nlh->nlmsg_len) {
+               if (nlh->nlmsg_len < sizeof(struct nlmsghdr) || (u_int)len < nlh->nlmsg_len) {
                        pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Message truncated: (got: %d) (nlmsg_len: %u)", len, nlh->nlmsg_len);
                        return -1;
                }
@@ -205,8 +205,8 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
                }
 
                msg_len = NLMSG_ALIGN(nlh->nlmsg_len);
-               if (msg_len > len)
-                       msg_len = len;
+               if (msg_len > (u_int)len)
+                       msg_len = (u_int)len;
 
                len -= msg_len;
                buf += msg_len;
@@ -310,7 +310,7 @@ netfilter_send_config_msg(const pcap_t *handle, u_int16_t msg_type, int ack, u_i
                if (snl.nl_pid != 0 || seq_id != nlh->nlmsg_seq)        /* if not from kernel or wrong sequence skip */
                        continue;
 
-               while (len >= NLMSG_SPACE(0) && NLMSG_OK(nlh, len)) {
+               while ((u_int)len >= NLMSG_SPACE(0) && NLMSG_OK(nlh, len)) {
                        if (nlh->nlmsg_type == NLMSG_ERROR || (nlh->nlmsg_type == NLMSG_DONE && nlh->nlmsg_flags & NLM_F_MULTI)) {
                                if (nlh->nlmsg_len < NLMSG_ALIGN(sizeof(struct nlmsgerr))) {
                                        errno = EBADMSG;
index c1e83ae7d8adb7b90639b2f115e870acb839fc7c..8d06a96cbb5fc700937b7e25d9a0e706b5e3d59d 100644 (file)
@@ -676,7 +676,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
         * a partial information.
         * At least until linux 2.6.17 there is no way to set usbmon intenal buffer
         * length and default value is 130. */
-       while ((string[0] != 0) && (string[1] != 0) && (pkth.caplen < handle->snapshot))
+       while ((string[0] != 0) && (string[1] != 0) && (pkth.caplen < (bpf_u_int32)handle->snapshot))
        {
                rawdata[0] = ascii_to_int(string[0]) * 16 + ascii_to_int(string[1]);
                rawdata++;
@@ -689,8 +689,8 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
 
 got:
        uhdr->data_len = data_len;
-       if (pkth.caplen > handle->snapshot)
-               pkth.caplen = handle->snapshot;
+       if (pkth.caplen > (bpf_u_int32)handle->snapshot)
+               pkth.caplen = (bpf_u_int32)handle->snapshot;
 
        if (handle->fcode.bf_insns == NULL ||
            bpf_filter(handle->fcode.bf_insns, handle->buffer,
@@ -825,7 +825,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_cha
        struct mon_bin_get info;
        int ret;
        struct pcap_pkthdr pkth;
-       int clen = handle->snapshot - sizeof(pcap_usb_header);
+       u_int clen = handle->snapshot - sizeof(pcap_usb_header);
 
        /* the usb header is going to be part of 'packet' data*/
        info.hdr = (pcap_usb_header*) handle->buffer;