Mercurial > hg > dhcpcd
changeset 2280:8983a3277ea5 draft
Drain the correct UDP socket.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 03 Feb 2014 17:30:03 +0000 |
| parents | 83ca8e0b70bd |
| children | 49803c1e4b68 |
| files | dhcp.c |
| diffstat | 1 files changed, 14 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/dhcp.c Mon Feb 03 17:29:36 2014 +0000 +++ b/dhcp.c Mon Feb 03 17:30:03 2014 +0000 @@ -2590,15 +2590,21 @@ static void dhcp_handleudp(void *arg) { + int fd; const struct interface *ifp; const struct dhcp_state *state; uint8_t buffer[sizeof(struct dhcp_message)]; - ifp = arg; - state = D_CSTATE(ifp); + if (arg) { + ifp = arg; + state = D_CSTATE(ifp); + fd = state->udp_fd; + } else + fd = udp_fd; + /* Just read what's in the UDP fd and discard it as we always read * from the raw fd */ - read(state->udp_fd, buffer, sizeof(buffer)); + read(fd, buffer, sizeof(buffer)); } static int @@ -2708,11 +2714,6 @@ const struct if_options *ifo; size_t len; - /* Listen on *.*.*.*:bootpc so that the kernel never sends an - * ICMP port unreachable message back to the DHCP server */ - if (udp_fd == -1 && dhcp_openudp(NULL) != -1) - eloop_event_add(udp_fd, dhcp_handleudp, NULL); - state = D_STATE(ifp); if (state == NULL) { ifp->if_data[IF_DATA_DHCP] = calloc(1, sizeof(*state)); @@ -2795,6 +2796,11 @@ if (!(ifo->options & DHCPCD_IPV4)) return; + /* Listen on *.*.*.*:bootpc so that the kernel never sends an + * ICMP port unreachable message back to the DHCP server */ + if (udp_fd == -1 && dhcp_openudp(NULL) != -1) + eloop_event_add(udp_fd, dhcp_handleudp, NULL); + if (dhcp_init(ifp) == -1) { syslog(LOG_ERR, "%s: dhcp_init: %m", ifp->name); return;
