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)) {
}
if (handle_dhcp(state, &dhcp, options) == 0)
return 0;
+ if (state->options & DHCPCD_FORKED)
+ return -1;
}
free(dhcp);
struct sockaddr_storage ss;
} su;
struct sock_fprog pf;
+ int flags;
if ((s = socket(PF_PACKET, SOCK_DGRAM, htons(protocol))) == -1)
return -1;
}
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)
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;