From f704abe50fb1ea9363fc9a18bee79cab0a1af301 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Thu, 30 Jun 2011 22:02:28 -0400 Subject: [PATCH] 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. --- ndhc/ndhc.c | 17 ----------------- ndhc/packet.c | 5 +++-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index be013df..da32ea1 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -63,19 +63,7 @@ struct client_state_t cs = { .dhcpState = DS_SELECTING, .arpPrevState = DS_SELECTING, .ifsPrevState = IFS_NONE, - .listenMode = 0, - .packetNum = 0, - .xid = 0, - .timeout = 0, .init = 1, - .oldTimeout = 0, - .leaseStartTime = 0, - .requestedIP = 0, - .serverAddr = 0, - .routerAddr = 0, - .lease = 0, - .renewTime = 0, - .rebindTime = 0, .epollFd = -1, .signalFd = -1, .listenFd = -1, @@ -86,14 +74,9 @@ struct client_state_t cs = { struct client_config_t client_config = { /* Default options. */ - .abort_if_no_lease = 0, - .foreground = 0, - .quit_after_lease = 0, - .background_if_no_lease = 0, .interface = "eth0", .clientid = NULL, .hostname = NULL, - .ifindex = 0, .arp = "\0\0\0\0\0\0", }; diff --git a/ndhc/packet.c b/ndhc/packet.c index 77fe7c3..0093d5e 100644 --- a/ndhc/packet.c +++ b/ndhc/packet.c @@ -447,11 +447,12 @@ static void change_listen_mode(struct client_state_t *cs, int new_mode) close(cs->listenFd); cs->listenFd = -1; } - if (new_mode != (LM_RAW || LM_COOKED)) { + if (new_mode == LM_NONE) { log_line("Stopped listening for DHCP packets."); 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, client_config.interface); if (cs->listenFd < 0) {