]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix casting with htons()
authorRoy Marples <roy@marples.name>
Sat, 28 Mar 2015 09:44:22 +0000 (09:44 +0000)
committerRoy Marples <roy@marples.name>
Sat, 28 Mar 2015 09:44:22 +0000 (09:44 +0000)
arp.c
if-bsd.c
if.h

diff --git a/arp.c b/arp.c
index 9a41497e23aa6fff1b60869709bc1cd8571f8691..8abeb6073b09c1bd5f790889ce0ef65b6b6c5fab 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -54,7 +54,7 @@
        (sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
 
 static ssize_t
-arp_send(const struct interface *ifp, int op, in_addr_t sip, in_addr_t tip)
+arp_request(const struct interface *ifp, in_addr_t sip, in_addr_t tip)
 {
        uint8_t arp_buffer[ARP_LEN];
        struct arphdr ar;
@@ -65,7 +65,7 @@ arp_send(const struct interface *ifp, int op, in_addr_t sip, in_addr_t tip)
        ar.ar_pro = htons(ETHERTYPE_IP);
        ar.ar_hln = ifp->hwlen;
        ar.ar_pln = sizeof(sip);
-       ar.ar_op = htons(op);
+       ar.ar_op = htons(ARPOP_REQUEST);
 
        p = arp_buffer;
        len = 0;
@@ -223,8 +223,7 @@ arp_announce1(void *arg)
                    "%s: ARP announcing %s (%d of %d)",
                    ifp->name, inet_ntoa(astate->addr),
                    astate->claims, ANNOUNCE_NUM);
-       if (arp_send(ifp, ARPOP_REQUEST,
-               astate->addr.s_addr, astate->addr.s_addr) == -1)
+       if (arp_request(ifp, astate->addr.s_addr, astate->addr.s_addr) == -1)
                logger(ifp->ctx, LOG_ERR, "send_arp: %m");
        eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
            astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
@@ -271,7 +270,7 @@ arp_probe1(void *arg)
            ifp->name, inet_ntoa(astate->addr),
            astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM,
            timespec_to_double(&tv));
-       if (arp_send(ifp, ARPOP_REQUEST, 0, astate->addr.s_addr) == -1)
+       if (arp_request(ifp, 0, astate->addr.s_addr) == -1)
                logger(ifp->ctx, LOG_ERR, "send_arp: %m");
 }
 
index e078e34ee9ac33e6d322fdbe66bcb4588a9edc95..3cac3cd9f5c5ead26746aebaa20fe787049da24e 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -375,7 +375,7 @@ eexit:
 }
 
 ssize_t
-if_sendrawpacket(const struct interface *ifp, int protocol,
+if_sendrawpacket(const struct interface *ifp, uint16_t protocol,
     const void *data, size_t len)
 {
        struct iovec iov[2];
@@ -401,7 +401,7 @@ if_sendrawpacket(const struct interface *ifp, int protocol,
 /* BPF requires that we read the entire buffer.
  * So we pass the buffer in the API so we can loop on >1 packet. */
 ssize_t
-if_readrawpacket(struct interface *ifp, int protocol,
+if_readrawpacket(struct interface *ifp, uint16_t protocol,
     void *data, size_t len, int *flags)
 {
        int fd;
@@ -725,7 +725,7 @@ ifa_scope(struct sockaddr_in6 *sin, unsigned int ifindex)
        /* KAME based systems want to store the scope inside the sin6_addr
         * for link local addreses */
        if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
-               uint16_t scope = htons(ifindex);
+               uint16_t scope = htons((uint16_t)ifindex);
                memcpy(&sin->sin6_addr.s6_addr[2], &scope,
                    sizeof(scope));
        }
diff --git a/if.h b/if.h
index b35bc340d14a893e98eb7cceb97fc9fc288e7b60..f7b1eab93609241a31b7f66c3f095715ddaef9de 100644 (file)
--- a/if.h
+++ b/if.h
@@ -114,8 +114,8 @@ int if_managelink(struct dhcpcd_ctx *);
 extern const char *if_pfname;
 int if_openrawsocket(struct interface *, int);
 ssize_t if_sendrawpacket(const struct interface *,
-    int, const void *, size_t);
-ssize_t if_readrawpacket(struct interface *, int, void *, size_t, int *);
+    uint16_t, const void *, size_t);
+ssize_t if_readrawpacket(struct interface *, uint16_t, void *, size_t, int *);
 
 int if_address(const struct interface *,
     const struct in_addr *, const struct in_addr *,