]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Use non blocking sockets so read errors with EAGAIN.
authorRoy Marples <roy@marples.name>
Thu, 15 May 2008 14:16:47 +0000 (14:16 +0000)
committerRoy Marples <roy@marples.name>
Thu, 15 May 2008 14:16:47 +0000 (14:16 +0000)
client.c
socket.c

index af58bd9651fc2564943ebc240bed7c3962c0fcf0..7208675c0e54c52044c153aa20a65072280df26d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1191,7 +1191,6 @@ handle_packet(struct if_state *state, const struct options *options)
        for(;;) {
                memset(dhcp, 0, sizeof(*dhcp));
                bytes = get_packet(iface, dhcp, sizeof(*dhcp));
-               printf ("bb %d\n", bytes);
                if (bytes == -1 || bytes == 0)
                        break;
                if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
@@ -1216,6 +1215,8 @@ handle_packet(struct if_state *state, const struct options *options)
                }
                if (handle_dhcp(state, &dhcp, options) == 0)
                        return 0;
+               if (state->options & DHCPCD_FORKED)
+                       return -1;
        }
 
        free(dhcp);
index a41d46ab8f0f76da96e94ba0feddcf43c56f9662..0e0b2cf7cc7a3d358a701bdc797abdcc8d4505be 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -96,6 +96,7 @@ open_socket(struct interface *iface, int protocol)
                struct sockaddr_storage ss;
        } su;
        struct sock_fprog pf;
+       int flags;
 
        if ((s = socket(PF_PACKET, SOCK_DGRAM, htons(protocol))) == -1)
                return -1;
@@ -119,7 +120,9 @@ open_socket(struct interface *iface, int protocol)
        }
        if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) != 0)
                goto eexit;
-
+       if ((flags = fcntl(s, F_GETFL, 0)) == -1
+           || fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
+               goto eexit;
        if (bind(s, &su.sa, sizeof(su)) == -1)
                goto eexit;
        if (close_on_exec(s) == -1)
@@ -174,20 +177,10 @@ get_packet(struct interface *iface, void *data, ssize_t len)
        ssize_t bytes;
        const uint8_t *p;
 
-       if (iface->buffer_pos > iface->buffer_len) {
-               iface->buffer_len = iface->buffer_pos = 0;
-               return 0;
-       }
-
        bytes = read(iface->fd, iface->buffer, iface->buffer_size);
-
        if (bytes == -1)
                return errno == EAGAIN ? 0 : -1;
 
-       /* So our loops to us work correctly */
-       iface->buffer_len = bytes;
-       iface->buffer_pos = iface->buffer_len + 1;
-
        /* If it's an ARP reply, then just send it back */
        if (iface->socket_protocol == ETHERTYPE_ARP)
                return bytes;