]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Pull ARP replies correctly.
authorRoy Marples <roy@marples.name>
Mon, 26 May 2008 09:58:36 +0000 (09:58 +0000)
committerRoy Marples <roy@marples.name>
Mon, 26 May 2008 09:58:36 +0000 (09:58 +0000)
client.c
lpf.c
net.c

index 85a7ba00e7f48f46bce4680e4185af1996b19609..07bed64c37485ebb5fcf02bf03781534431fdd32 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1266,7 +1266,6 @@ dhcp_run(const struct options *options, int *pidfd)
                goto eexit;
 
        fds[POLLFD_SIGNAL].fd = signal_fd();
-
        for (;;) {
                retval = wait_for_packet(fds, state, options);
 
diff --git a/lpf.c b/lpf.c
index 4491e0be6f31857ebf27009891a01914d4e8d46b..87e6460a441907f7310319ff79996e3805c73d8d 100644 (file)
--- a/lpf.c
+++ b/lpf.c
@@ -163,13 +163,13 @@ get_packet(struct interface *iface, void *data, ssize_t len)
                return errno == EAGAIN ? 0 : -1;
 
        /* If it's an ARP reply, then just send it back */
-       if (iface->socket_protocol == ETHERTYPE_ARP)
-               return bytes;
-
-       if (valid_udp_packet(iface->buffer) != 0)
-               return -1;
-
-       bytes = get_udp_data(&p, iface->buffer);
+       if (iface->socket_protocol == ETHERTYPE_ARP) {
+               p = iface->buffer;
+       } else {
+               if (valid_udp_packet(iface->buffer) != 0)
+                       return -1;
+               bytes = get_udp_data(&p, iface->buffer);
+       }
        if (bytes > len)
                bytes = len;
        memcpy(data, p, bytes);
diff --git a/net.c b/net.c
index 87feebef80cae88dffee126b921833f0691e1b16..34e1889ce3aac2b5b369634f342e1e2d9dbd6f27 100644 (file)
--- a/net.c
+++ b/net.c
@@ -732,7 +732,6 @@ arp_claim(struct interface *iface, struct in_addr address)
                        if (get_time(&stopat) != 0)
                                break;
                        stopat.tv_usec += timeout;
-
                        continue;
                }
 
@@ -746,29 +745,32 @@ arp_claim(struct interface *iface, struct in_addr address)
 
                if (!(fds[1].revents & POLLIN))
                        continue;
-
                for(;;) {
                        memset(&arp_reply, 0, sizeof(arp_reply));
-                       bytes = get_packet(iface, &arp_reply, sizeof(arp_reply));
+                       bytes = get_packet(iface,
+                                          &arp_reply, sizeof(arp_reply));
                        if (bytes == -1 || bytes == 0)
                                break;
 
-                       memcpy(&reply, arp_reply, sizeof(reply));
+                       memcpy(&reply, &arp_reply, sizeof(reply));
                        /* Only these types are recognised */
                        if (reply.ar_op != htons(ARPOP_REPLY))
                                continue;
-
                        /* Protocol must be IP. */
                        if (reply.ar_pro != htons(ETHERTYPE_IP))
                                continue;
                        if (reply.ar_pln != sizeof(reply_ipv4))
                                continue;
-                       if ((size_t)bytes < sizeof(reply) + 2 * (4 + reply.ar_hln) ||
+                       if ((size_t)bytes < sizeof(reply) + 2 *
+                           (4 + reply.ar_hln) ||
                            reply.ar_hln > 8)
                                continue;
 
-                       memcpy(&reply_mac, arp_reply + sizeof(reply), reply.ar_hln);
-                       memcpy(&reply_ipv4, arp_reply + sizeof(reply) + reply.ar_hln, reply.ar_hln);
+                       memcpy(&reply_mac,
+                              arp_reply + sizeof(reply), reply.ar_hln);
+                       memcpy(&reply_ipv4,
+                              arp_reply + sizeof(reply) + reply.ar_hln,
+                              reply.ar_hln);
 
                        /* Ensure the ARP reply is for the our address */
                        if (reply_ipv4.s_addr != address.s_addr)
@@ -777,12 +779,14 @@ arp_claim(struct interface *iface, struct in_addr address)
                        /* Some systems send a reply back from our hwaddress,
                         * which is wierd */
                        if (reply.ar_hln == iface->hwlen &&
-                           memcmp(&reply_mac, iface->hwaddr, iface->hwlen) == 0)
+                           memcmp(&reply_mac, iface->hwaddr,
+                                  iface->hwlen) == 0)
                                continue;
 
                        logger(LOG_ERR, "ARPOP_REPLY received from %s (%s)",
                               inet_ntoa(reply_ipv4),
-                              hwaddr_ntoa((unsigned char *)&reply_mac, (size_t)reply.ar_hln));
+                              hwaddr_ntoa((unsigned char *)&reply_mac,
+                                          (size_t)reply.ar_hln));
                        retval = -1;
                        goto eexit;
                }