aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 5b2612e56..eb1f1db8d 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -32,6 +32,11 @@
32#include "signalpipe.h" 32#include "signalpipe.h"
33 33
34static int state; 34static int state;
35/* Something is definitely wrong here. IPv4 addresses
36 * in variables of type long?? BTW, we use inet_ntoa()
37 * in the code. Manpage says that struct in_addr has a member of type long (!)
38 * which holds IPv4 address, and the struct is passed by value (!!)
39 */
35static unsigned long requested_ip; /* = 0 */ 40static unsigned long requested_ip; /* = 0 */
36static unsigned long server_addr; 41static unsigned long server_addr;
37static unsigned long timeout; 42static unsigned long timeout;
@@ -267,7 +272,7 @@ int udhcpc_main(int argc, char *argv[])
267 } 272 }
268 273
269 /* Start the log, sanitize fd's, and write a pid file */ 274 /* Start the log, sanitize fd's, and write a pid file */
270 udhcp_start_log_and_pid("udhcpc", client_config.pidfile); 275 udhcp_start_log_and_pid(client_config.pidfile);
271 276
272 if (read_interface(client_config.interface, &client_config.ifindex, 277 if (read_interface(client_config.interface, &client_config.ifindex,
273 NULL, client_config.arp) < 0) 278 NULL, client_config.arp) < 0)
@@ -446,8 +451,9 @@ int udhcpc_main(int argc, char *argv[])
446 case INIT_SELECTING: 451 case INIT_SELECTING:
447 /* Must be a DHCPOFFER to one of our xid's */ 452 /* Must be a DHCPOFFER to one of our xid's */
448 if (*message == DHCPOFFER) { 453 if (*message == DHCPOFFER) {
449 if ((temp = get_option(&packet, DHCP_SERVER_ID))) { 454 temp = get_option(&packet, DHCP_SERVER_ID);
450 memcpy(&server_addr, temp, 4); 455 if (temp) {
456 server_addr = *(uint32_t*)temp;
451 xid = packet.xid; 457 xid = packet.xid;
452 requested_ip = packet.yiaddr; 458 requested_ip = packet.yiaddr;
453 459
@@ -465,12 +471,12 @@ int udhcpc_main(int argc, char *argv[])
465 case RENEWING: 471 case RENEWING:
466 case REBINDING: 472 case REBINDING:
467 if (*message == DHCPACK) { 473 if (*message == DHCPACK) {
468 if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) { 474 temp = get_option(&packet, DHCP_LEASE_TIME);
475 if (!temp) {
469 bb_error_msg("No lease time with ACK, using 1 hour lease"); 476 bb_error_msg("No lease time with ACK, using 1 hour lease");
470 lease = 60 * 60; 477 lease = 60 * 60;
471 } else { 478 } else {
472 memcpy(&lease, temp, 4); 479 lease = ntohl(*(uint32_t*)temp);
473 lease = ntohl(lease);
474 } 480 }
475 481
476 /* enter bound state */ 482 /* enter bound state */