]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix more -Wconversion issues.
authorRoy Marples <roy@marples.name>
Thu, 2 Apr 2015 18:27:22 +0000 (18:27 +0000)
committerRoy Marples <roy@marples.name>
Thu, 2 Apr 2015 18:27:22 +0000 (18:27 +0000)
dhcp.c
dhcp6.c
if-bsd.c
if-linux.c
if.h
ipv6.h

diff --git a/dhcp.c b/dhcp.c
index 93812bc1ff9e1b06f17d619f8d1f6f9f723cd5e0..a72dc79d59c714784b85c7690f1f58b6cc7d3861 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1498,18 +1498,18 @@ checksum(const void *data, unsigned int len)
        uint32_t sum = 0;
 
        while (len > 1) {
-               sum += (uint32_t)addr[0] * 256 + (uint32_t)addr[1];
+               sum += (uint32_t)(addr[0] * 256 + addr[1]);
                addr += 2;
                len -= 2;
        }
 
        if (len == 1)
-               sum += (uint32_t)*addr * 256;
+               sum += (uint32_t)(*addr * 256);
 
        sum = (sum >> 16) + (sum & 0xffff);
        sum += (sum >> 16);
 
-       return (uint16_t)~htons(sum);
+       return (uint16_t)~htons((uint16_t)sum);
 }
 
 static struct udp_dhcp_packet *
@@ -1546,7 +1546,7 @@ dhcp_makeudppacket(size_t *sz, const uint8_t *data, size_t length,
 
        udp->uh_sport = htons(DHCP_CLIENT_PORT);
        udp->uh_dport = htons(DHCP_SERVER_PORT);
-       udp->uh_ulen = htons(sizeof(*udp) + length);
+       udp->uh_ulen = htons((uint16_t)(sizeof(*udp) + length));
        ip->ip_len = udp->uh_ulen;
        udp->uh_sum = checksum(udpp, sizeof(*udpp));
 
diff --git a/dhcp6.c b/dhcp6.c
index 24b808cb48a9b07bce3d041b3b57da223b718017..b588be7816e70ec2249c0d683f629acc6e61a107 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -188,7 +188,7 @@ dhcp6_makevendor(struct dhcp6_option *o, const struct interface *ifp)
 
        if (o) {
                o->code = htons(D6_OPTION_VENDOR_CLASS);
-               o->len = htons(len);
+               o->len = htons((uint16_t)len);
                p = D6_OPTION_DATA(o);
                u32 = htonl(ifo->vivco_en ? ifo->vivco_en : DHCPCD_IANA_PEN);
                memcpy(p, &u32, sizeof(u32));
@@ -216,7 +216,7 @@ dhcp6_makevendor(struct dhcp6_option *o, const struct interface *ifp)
 }
 
 static const struct dhcp6_option *
-dhcp6_findoption(unsigned int code, const uint8_t *d, size_t len)
+dhcp6_findoption(uint16_t code, const uint8_t *d, size_t len)
 {
        const struct dhcp6_option *o;
        size_t ol;
@@ -280,7 +280,7 @@ dhcp6_getoption(struct dhcpcd_ctx *ctx,
 }
 
 static const struct dhcp6_option *
-dhcp6_getmoption(unsigned int code, const struct dhcp6_message *m, size_t len)
+dhcp6_getmoption(uint16_t code, const struct dhcp6_message *m, size_t len)
 {
 
        if (len < sizeof(*m)) {
@@ -310,7 +310,7 @@ dhcp6_updateelapsed(struct interface *ifp, struct dhcp6_message *m, size_t len)
        up = uptime() - state->start_uptime;
        if (up < 0 || up > (time_t)UINT16_MAX)
                up = (time_t)UINT16_MAX;
-       u16 = htons(up);
+       u16 = htons((uint16_t)up);
        memcpy(D6_OPTION_DATA(o), &u16, sizeof(u16));
        return 0;
 }
@@ -2721,7 +2721,7 @@ dhcp6_handledata(void *arg)
            i++, opt++)
        {
                if (has_option_mask(ifo->requiremask6, opt->option) &&
-                   dhcp6_getmoption(opt->option, r, len) == NULL)
+                   dhcp6_getmoption((uint16_t)opt->option, r, len) == NULL)
                {
                        logger(ifp->ctx, LOG_WARNING,
                            "%s: reject DHCPv6 (no option %s) from %s",
@@ -2729,7 +2729,7 @@ dhcp6_handledata(void *arg)
                        return;
                }
                if (has_option_mask(ifo->rejectmask6, opt->option) &&
-                   dhcp6_getmoption(opt->option, r, len))
+                   dhcp6_getmoption((uint16_t)opt->option, r, len))
                {
                        logger(ifp->ctx, LOG_WARNING,
                            "%s: reject DHCPv6 (option %s) from %s",
index 3cac3cd9f5c5ead26746aebaa20fe787049da24e..a20c2cb9ebd7c6f420998beb3921f506368d5b0f 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -291,7 +291,7 @@ if_findsdl(struct dhcpcd_ctx *ctx, struct sockaddr_dl *sdl)
 const char *if_pfname = "Berkley Packet Filter";
 
 int
-if_openrawsocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, uint16_t protocol)
 {
        struct dhcp_state *state;
        int fd = -1;
index 6da9a56743603f7658b65025196e91b56fd82f81..4e449be3d195438607929abdcf9945084bd383ec 100644 (file)
@@ -869,7 +869,7 @@ static int
 add_attr_l(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
     const void *data, unsigned short alen)
 {
-       unsigned short len = RTA_LENGTH(alen);
+       unsigned short len = (unsigned short)RTA_LENGTH(alen);
        struct rtattr *rta;
 
        if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
@@ -918,7 +918,7 @@ nla_next(struct nlattr *nla, size_t *rem)
 }
 
 #define NLA_TYPE(nla) ((nla)->nla_type & NLA_TYPE_MASK)
-#define NLA_LEN(nla) ((nla)->nla_len - NLA_HDRLEN)
+#define NLA_LEN(nla) (unsigned int)((nla)->nla_len - NLA_HDRLEN)
 #define NLA_OK(nla, rem) \
        ((rem) >= sizeof(struct nlattr) && \
        (nla)->nla_len >= sizeof(struct nlattr) && \
@@ -1118,7 +1118,7 @@ struct nlmr
 const char *if_pfname = "Packet Socket";
 
 int
-if_openrawsocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, uint16_t protocol)
 {
        int s;
        union sockunion {
diff --git a/if.h b/if.h
index f7b1eab93609241a31b7f66c3f095715ddaef9de..084b3abb6fffa7557743065bbb06dbedae92942f 100644 (file)
--- a/if.h
+++ b/if.h
@@ -112,7 +112,7 @@ int if_managelink(struct dhcpcd_ctx *);
 
 #ifdef INET
 extern const char *if_pfname;
-int if_openrawsocket(struct interface *, int);
+int if_openrawsocket(struct interface *, uint16_t);
 ssize_t if_sendrawpacket(const struct interface *,
     uint16_t, const void *, size_t);
 ssize_t if_readrawpacket(struct interface *, uint16_t, void *, size_t, int *);
diff --git a/ipv6.h b/ipv6.h
index a22e19926856eac9a88a51fc2c4b787730db1ef0..db2d886dfb31c179e9225e6f9f422c0e4860a27f 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -197,7 +197,7 @@ struct ipv6_state {
 
 
 /* ipi6.ifiindex differes between OS's so have a cast function */
-#ifdef __linux__
+#ifdef __GLIBC__
 #define CAST_IPI6_IFINDEX(idx) (int)(idx)
 #else
 #define CAST_IPI6_IFINDEX(idx) (idx)