{
DEBUG("entering %s listen mode",
new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none");
+
+ listen_mode = new_mode;
if (sockfd >= 0) {
close(sockfd);
sockfd = -1;
}
- listen_mode = new_mode;
+ if (new_mode == LISTEN_KERNEL)
+ sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
+ else if (new_mode != LISTEN_NONE)
+ sockfd = udhcp_raw_socket(client_config.ifindex);
+ /* else LISTEN_NONE: sockfd stay closed */
}
/* on NOMMU reexec (i.e., background) early */
if (!(opt & OPT_f)) {
bb_daemonize_or_rexec(0 /* flags */, argv);
- logmode = 0;
+ logmode = LOGMODE_NONE;
}
#endif
if (opt & OPT_S) {
- openlog(applet_name, LOG_PID, LOG_LOCAL0);
+ openlog(applet_name, LOG_PID, LOG_DAEMON);
logmode |= LOGMODE_SYSLOG;
}
* "continue" statements in code below jump to the top of the loop.
*/
for (;;) {
- unsigned timestamp_before_wait;
+ /* silence "uninitialized!" warning */
+ unsigned timestamp_before_wait = timestamp_before_wait;
+
+ //bb_error_msg("sockfd:%d, listen_mode:%d", sockfd, listen_mode);
+
+ /* Was opening raw or udp socket here
+ * if (listen_mode != LISTEN_NONE && sockfd < 0),
+ * but on fast network renew responses return faster
+ * than we open sockets. Thus this code is moved
+ * to change_listen_mode(). Thus we open listen socket
+ * BEFORE we send renew request (see "case BOUND:"). */
- if (listen_mode != LISTEN_NONE && sockfd < 0) {
- if (listen_mode == LISTEN_KERNEL)
- sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
- else
- sockfd = udhcp_raw_socket(client_config.ifindex);
- }
max_fd = udhcp_sp_fd_set(&rfds, sockfd);
tv.tv_sec = timeout - already_waited_sec;
* try to find DHCP server using broadcast */
if (timeout > 0) {
/* send a request packet */
- send_renew(xid, 0 /* INADDR_ANY*/, requested_ip); /* broadcast */
+ send_renew(xid, 0 /*INADDR_ANY*/, requested_ip); /* broadcast */
timeout >>= 1;
continue;
}