diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-03 15:47:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-03 15:47:50 +0000 |
commit | 42b3dea9bfb8ac595c71089ee23012f44dd43eb2 (patch) | |
tree | b7b86d06a574d2af72bc79536d399905b5619959 /networking/udhcp/dhcpc.c | |
parent | 54e19da86d5496ec5f5787b85a2b6342be1d63d4 (diff) | |
download | busybox-w32-42b3dea9bfb8ac595c71089ee23012f44dd43eb2.tar.gz busybox-w32-42b3dea9bfb8ac595c71089ee23012f44dd43eb2.tar.bz2 busybox-w32-42b3dea9bfb8ac595c71089ee23012f44dd43eb2.zip |
udhcp: many small fixes:
* arpping(): smaller and even probably fixed
* lots of variables/params converted: ulong -> uint32_t
* uptime() nuked in favor of monotonic_sec()
* udhcp_get_packet(): only one "bad vendor", simplify
function old new delta
reservedIp 36 35 -1
udhcpc_main 2462 2460 -2
addStaticLease 64 62 -2
static.broken_vendors 16 - -16
uptime 19 - -19
udhcpd_main 1273 1238 -35
udhcp_get_packet 223 184 -39
.rodata 144162 144106 -56
arpping 690 609 -81
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-251) Total: -251 bytes
text data bss dec hex filename
734241 3028 14400 751669 b7835 busybox_old
734005 3028 14400 751433 b7749 busybox_unstripped
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 50ac31e61..6909e8489 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -22,8 +22,8 @@ | |||
22 | * in the code. Manpage says that struct in_addr has a member of type long (!) | 22 | * in the code. Manpage says that struct in_addr has a member of type long (!) |
23 | * which holds IPv4 address, and the struct is passed by value (!!) | 23 | * which holds IPv4 address, and the struct is passed by value (!!) |
24 | */ | 24 | */ |
25 | static unsigned long timeout; | 25 | static unsigned timeout; |
26 | static unsigned long requested_ip; /* = 0 */ | 26 | static uint32_t requested_ip; /* = 0 */ |
27 | static uint32_t server_addr; | 27 | static uint32_t server_addr; |
28 | static int packet_num; /* = 0 */ | 28 | static int packet_num; /* = 0 */ |
29 | static int sockfd = -1; | 29 | static int sockfd = -1; |
@@ -84,13 +84,13 @@ static void perform_renew(void) | |||
84 | /* perform a release */ | 84 | /* perform a release */ |
85 | static void perform_release(void) | 85 | static void perform_release(void) |
86 | { | 86 | { |
87 | char buffer[16]; | 87 | char buffer[sizeof("255.255.255.255")]; |
88 | struct in_addr temp_addr; | 88 | struct in_addr temp_addr; |
89 | 89 | ||
90 | /* send release packet */ | 90 | /* send release packet */ |
91 | if (state == BOUND || state == RENEWING || state == REBINDING) { | 91 | if (state == BOUND || state == RENEWING || state == REBINDING) { |
92 | temp_addr.s_addr = server_addr; | 92 | temp_addr.s_addr = server_addr; |
93 | sprintf(buffer, "%s", inet_ntoa(temp_addr)); | 93 | strcpy(buffer, inet_ntoa(temp_addr)); |
94 | temp_addr.s_addr = requested_ip; | 94 | temp_addr.s_addr = requested_ip; |
95 | bb_info_msg("Unicasting a release of %s to %s", | 95 | bb_info_msg("Unicasting a release of %s to %s", |
96 | inet_ntoa(temp_addr), buffer); | 96 | inet_ntoa(temp_addr), buffer); |
@@ -101,7 +101,7 @@ static void perform_release(void) | |||
101 | 101 | ||
102 | change_mode(LISTEN_NONE); | 102 | change_mode(LISTEN_NONE); |
103 | state = RELEASED; | 103 | state = RELEASED; |
104 | timeout = 0x7fffffff; | 104 | timeout = INT_MAX; |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
@@ -115,12 +115,13 @@ static void client_background(void) | |||
115 | * will work on NOMMU too */ | 115 | * will work on NOMMU too */ |
116 | #else | 116 | #else |
117 | bb_daemonize(0); | 117 | bb_daemonize(0); |
118 | logmode &= ~LOGMODE_STDIO; | ||
118 | /* rewrite pidfile, as our pid is different now */ | 119 | /* rewrite pidfile, as our pid is different now */ |
119 | if (client_config.pidfile) | 120 | if (client_config.pidfile) |
120 | write_pidfile(client_config.pidfile); | 121 | write_pidfile(client_config.pidfile); |
121 | logmode &= ~LOGMODE_STDIO; | ||
122 | #endif | 122 | #endif |
123 | client_config.foreground = 1; /* Do not fork again. */ | 123 | /* Do not fork again. */ |
124 | client_config.foreground = 1; | ||
124 | client_config.background_if_no_lease = 0; | 125 | client_config.background_if_no_lease = 0; |
125 | } | 126 | } |
126 | 127 | ||
@@ -143,9 +144,11 @@ int udhcpc_main(int argc, char **argv) | |||
143 | { | 144 | { |
144 | uint8_t *temp, *message; | 145 | uint8_t *temp, *message; |
145 | char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_t; | 146 | char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_t; |
146 | unsigned long t1 = 0, t2 = 0, xid = 0; | 147 | uint32_t xid = 0; |
147 | unsigned long start = 0, lease = 0; | 148 | uint32_t lease = 0; /* can be given as 32-bit quantity */ |
148 | long now; | 149 | unsigned t1 = 0, t2 = 0; |
150 | unsigned start = 0; | ||
151 | unsigned now; | ||
149 | unsigned opt; | 152 | unsigned opt; |
150 | int max_fd; | 153 | int max_fd; |
151 | int sig; | 154 | int sig; |
@@ -292,7 +295,7 @@ int udhcpc_main(int argc, char **argv) | |||
292 | change_mode(LISTEN_RAW); | 295 | change_mode(LISTEN_RAW); |
293 | 296 | ||
294 | for (;;) { | 297 | for (;;) { |
295 | tv.tv_sec = timeout - uptime(); | 298 | tv.tv_sec = timeout - monotonic_sec(); |
296 | tv.tv_usec = 0; | 299 | tv.tv_usec = 0; |
297 | 300 | ||
298 | if (listen_mode != LISTEN_NONE && sockfd < 0) { | 301 | if (listen_mode != LISTEN_NONE && sockfd < 0) { |
@@ -308,7 +311,7 @@ int udhcpc_main(int argc, char **argv) | |||
308 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); | 311 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); |
309 | } else retval = 0; /* If we already timed out, fall through */ | 312 | } else retval = 0; /* If we already timed out, fall through */ |
310 | 313 | ||
311 | now = uptime(); | 314 | now = monotonic_sec(); |
312 | if (retval == 0) { | 315 | if (retval == 0) { |
313 | /* timeout dropped to zero */ | 316 | /* timeout dropped to zero */ |
314 | switch (state) { | 317 | switch (state) { |
@@ -398,7 +401,7 @@ int udhcpc_main(int argc, char **argv) | |||
398 | break; | 401 | break; |
399 | case RELEASED: | 402 | case RELEASED: |
400 | /* yah, I know, *you* say it would never happen */ | 403 | /* yah, I know, *you* say it would never happen */ |
401 | timeout = 0x7fffffff; | 404 | timeout = INT_MAX; |
402 | break; | 405 | break; |
403 | } | 406 | } |
404 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { | 407 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { |
@@ -415,8 +418,8 @@ int udhcpc_main(int argc, char **argv) | |||
415 | if (len < 0) continue; | 418 | if (len < 0) continue; |
416 | 419 | ||
417 | if (packet.xid != xid) { | 420 | if (packet.xid != xid) { |
418 | DEBUG("Ignoring XID %lx (our xid is %lx)", | 421 | DEBUG("Ignoring XID %x (our xid is %x)", |
419 | (unsigned long) packet.xid, xid); | 422 | (unsigned)packet.xid, (unsigned)xid); |
420 | continue; | 423 | continue; |
421 | } | 424 | } |
422 | 425 | ||
@@ -471,10 +474,10 @@ int udhcpc_main(int argc, char **argv) | |||
471 | t1 = lease / 2; | 474 | t1 = lease / 2; |
472 | 475 | ||
473 | /* little fixed point for n * .875 */ | 476 | /* little fixed point for n * .875 */ |
474 | t2 = (lease * 0x7) >> 3; | 477 | t2 = (lease * 7) >> 3; |
475 | temp_addr.s_addr = packet.yiaddr; | 478 | temp_addr.s_addr = packet.yiaddr; |
476 | bb_info_msg("Lease of %s obtained, lease time %ld", | 479 | bb_info_msg("Lease of %s obtained, lease time %u", |
477 | inet_ntoa(temp_addr), lease); | 480 | inet_ntoa(temp_addr), (unsigned)lease); |
478 | start = now; | 481 | start = now; |
479 | timeout = t1 + start; | 482 | timeout = t1 + start; |
480 | requested_ip = packet.yiaddr; | 483 | requested_ip = packet.yiaddr; |