C99 designated initializers guarantee zero-init of unspecified members.

Take advantage of that feature in ndhc.c when initializing the state
and config structures.

Fix some seriously stupid typos in the commit before the previous one.
This commit is contained in:
Nicholas J. Kain 2011-06-30 22:02:28 -04:00
parent 1f514cbb50
commit f704abe50f
2 changed files with 3 additions and 19 deletions

View File

@ -63,19 +63,7 @@ struct client_state_t cs = {
.dhcpState = DS_SELECTING, .dhcpState = DS_SELECTING,
.arpPrevState = DS_SELECTING, .arpPrevState = DS_SELECTING,
.ifsPrevState = IFS_NONE, .ifsPrevState = IFS_NONE,
.listenMode = 0,
.packetNum = 0,
.xid = 0,
.timeout = 0,
.init = 1, .init = 1,
.oldTimeout = 0,
.leaseStartTime = 0,
.requestedIP = 0,
.serverAddr = 0,
.routerAddr = 0,
.lease = 0,
.renewTime = 0,
.rebindTime = 0,
.epollFd = -1, .epollFd = -1,
.signalFd = -1, .signalFd = -1,
.listenFd = -1, .listenFd = -1,
@ -86,14 +74,9 @@ struct client_state_t cs = {
struct client_config_t client_config = { struct client_config_t client_config = {
/* Default options. */ /* Default options. */
.abort_if_no_lease = 0,
.foreground = 0,
.quit_after_lease = 0,
.background_if_no_lease = 0,
.interface = "eth0", .interface = "eth0",
.clientid = NULL, .clientid = NULL,
.hostname = NULL, .hostname = NULL,
.ifindex = 0,
.arp = "\0\0\0\0\0\0", .arp = "\0\0\0\0\0\0",
}; };

View File

@ -447,11 +447,12 @@ static void change_listen_mode(struct client_state_t *cs, int new_mode)
close(cs->listenFd); close(cs->listenFd);
cs->listenFd = -1; cs->listenFd = -1;
} }
if (new_mode != (LM_RAW || LM_COOKED)) { if (new_mode == LM_NONE) {
log_line("Stopped listening for DHCP packets."); log_line("Stopped listening for DHCP packets.");
return; return;
} }
cs->listenFd = LM_RAW ? create_raw_listen_socket(client_config.ifindex) : cs->listenFd = new_mode == LM_RAW ?
create_raw_listen_socket(client_config.ifindex) :
create_udp_listen_socket(INADDR_ANY, DHCP_CLIENT_PORT, create_udp_listen_socket(INADDR_ANY, DHCP_CLIENT_PORT,
client_config.interface); client_config.interface);
if (cs->listenFd < 0) { if (cs->listenFd < 0) {