diff options
Diffstat (limited to 'networking/udhcp/d6_dhcpc.c')
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 64339c9b5..067d35115 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -935,9 +935,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) int timeout; /* must be signed */ unsigned already_waited_sec; unsigned opt; - int max_fd; int retval; - fd_set rfds; setup_common_bufsiz(); @@ -1063,7 +1061,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) * "continue" statements in code below jump to the top of the loop. */ for (;;) { - struct timeval tv; + int tv; + struct pollfd pfds[2]; struct d6_packet packet; uint8_t *packet_end; /* silence "uninitialized!" warning */ @@ -1078,16 +1077,15 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) * to change_listen_mode(). Thus we open listen socket * BEFORE we send renew request (see "case BOUND:"). */ - max_fd = udhcp_sp_fd_set(&rfds, sockfd); + udhcp_sp_fd_set(pfds, sockfd); - tv.tv_sec = timeout - already_waited_sec; - tv.tv_usec = 0; + tv = timeout - already_waited_sec; retval = 0; /* If we already timed out, fall through with retval = 0, else... */ - if ((int)tv.tv_sec > 0) { - log1("waiting on select %u seconds", (int)tv.tv_sec); + if (tv > 0) { + log1("waiting on select %u seconds", tv); timestamp_before_wait = (unsigned)monotonic_sec(); - retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); + retval = poll(pfds, 2, tv * 1000); if (retval < 0) { /* EINTR? A signal was caught, don't panic */ if (errno == EINTR) { @@ -1222,8 +1220,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) /* select() didn't timeout, something happened */ /* Is it a signal? */ - /* note: udhcp_sp_read checks FD_ISSET before reading */ - switch (udhcp_sp_read(&rfds)) { + /* note: udhcp_sp_read checks poll result before reading */ + switch (udhcp_sp_read(pfds)) { case SIGUSR1: client_config.first_secs = 0; /* make secs field count from 0 */ already_waited_sec = 0; @@ -1258,7 +1256,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) } /* Is it a packet? */ - if (listen_mode == LISTEN_NONE || !FD_ISSET(sockfd, &rfds)) + if (listen_mode == LISTEN_NONE || !pfds[1].revents) continue; /* no */ { @@ -1460,8 +1458,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) if (lease_seconds < 0x10) lease_seconds = 0x10; /// TODO: check for 0 lease time? - if (lease_seconds >= 0x10000000) - lease_seconds = 0x0fffffff; + if (lease_seconds > 0x7fffffff / 1000) + lease_seconds = 0x7fffffff / 1000; /* enter bound state */ timeout = lease_seconds / 2; bb_error_msg("lease obtained, lease time %u", |