diff options
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/pidfile.c | 4 | ||||
-rw-r--r-- | networking/udhcp/common.c | 21 | ||||
-rw-r--r-- | networking/udhcp/common.h | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 69 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 13 | ||||
-rw-r--r-- | networking/udhcp/dhcprelay.c | 17 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 11 |
8 files changed, 69 insertions, 72 deletions
diff --git a/include/libbb.h b/include/libbb.h index 1cbcb41e4..13bd2d688 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -619,8 +619,8 @@ llist_t *llist_rev(llist_t *list); | |||
619 | * llist_t *llist_add_to(llist_t *old_head, void *data) | 619 | * llist_t *llist_add_to(llist_t *old_head, void *data) |
620 | * etc does not result in smaller code... */ | 620 | * etc does not result in smaller code... */ |
621 | 621 | ||
622 | /* start_stop_daemon and (udhcpc with ifupdown) are special - they want to | 622 | /* start_stop_daemon and udhcpc are special - they want |
623 | * create pidfiles regardless of FEATURE_PIDFILE. */ | 623 | * to create pidfiles regardless of FEATURE_PIDFILE */ |
624 | #if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE) | 624 | #if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE) |
625 | int write_pidfile(const char *path); | 625 | int write_pidfile(const char *path); |
626 | #define remove_pidfile(f) ((void)unlink(f)) | 626 | #define remove_pidfile(f) ((void)unlink(f)) |
diff --git a/libbb/pidfile.c b/libbb/pidfile.c index 50af91f4e..64e67c322 100644 --- a/libbb/pidfile.c +++ b/libbb/pidfile.c | |||
@@ -17,13 +17,15 @@ int write_pidfile(const char *path) | |||
17 | char *end; | 17 | char *end; |
18 | char buf[sizeof(int)*3 + 2]; | 18 | char buf[sizeof(int)*3 + 2]; |
19 | 19 | ||
20 | if (!path) | ||
21 | return 1; | ||
20 | /* we will overwrite stale pidfile */ | 22 | /* we will overwrite stale pidfile */ |
21 | pid_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666); | 23 | pid_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
22 | if (pid_fd < 0) | 24 | if (pid_fd < 0) |
23 | return 0; | 25 | return 0; |
24 | /* few bytes larger, but doesn't use stdio */ | 26 | /* few bytes larger, but doesn't use stdio */ |
25 | end = utoa_to_buf(getpid(), buf, sizeof(buf)); | 27 | end = utoa_to_buf(getpid(), buf, sizeof(buf)); |
26 | end[0] = '\n'; | 28 | *end = '\n'; |
27 | full_write(pid_fd, buf, end - buf + 1); | 29 | full_write(pid_fd, buf, end - buf + 1); |
28 | close(pid_fd); | 30 | close(pid_fd); |
29 | return 1; | 31 | return 1; |
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 108ab2e95..59c015575 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -1,30 +1,9 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* common.c | 2 | /* common.c |
3 | * | 3 | * |
4 | * Functions for debugging and logging as well as some other | ||
5 | * simple helper functions. | ||
6 | * | ||
7 | * Russ Dill <Russ.Dill@asu.edu> 2001-2003 | ||
8 | * Rewritten by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003 | ||
9 | * | ||
10 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 4 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
11 | */ | 5 | */ |
12 | 6 | ||
13 | #include "common.h" | 7 | #include "common.h" |
14 | 8 | ||
15 | const uint8_t MAC_BCAST_ADDR[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 9 | const uint8_t MAC_BCAST_ADDR[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
16 | |||
17 | void udhcp_make_pidfile(const char *pidfile) | ||
18 | { | ||
19 | /* Make sure fd 0,1,2 are open */ | ||
20 | bb_sanitize_stdio(); | ||
21 | |||
22 | /* Equivalent of doing a fflush after every \n */ | ||
23 | setlinebuf(stdout); | ||
24 | |||
25 | /* Create pidfile */ | ||
26 | if (pidfile && !write_pidfile(pidfile)) | ||
27 | bb_perror_msg("cannot create pidfile %s", pidfile); | ||
28 | |||
29 | bb_info_msg("%s (v%s) started", applet_name, BB_VER); | ||
30 | } | ||
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 588750462..bc21176a5 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -60,8 +60,6 @@ int udhcp_kernel_packet(struct dhcpMessage *payload, | |||
60 | 60 | ||
61 | /**/ | 61 | /**/ |
62 | 62 | ||
63 | void udhcp_make_pidfile(const char *pidfile); | ||
64 | |||
65 | void udhcp_run_script(struct dhcpMessage *packet, const char *name); | 63 | void udhcp_run_script(struct dhcpMessage *packet, const char *name); |
66 | 64 | ||
67 | // Still need to clean these up... | 65 | // Still need to clean these up... |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 4bb90c2da..efe208814 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -109,7 +109,7 @@ static void perform_release(void) | |||
109 | 109 | ||
110 | static void client_background(void) | 110 | static void client_background(void) |
111 | { | 111 | { |
112 | #ifdef __uClinux__ | 112 | #if !BB_MMU |
113 | bb_error_msg("cannot background in uclinux (yet)"); | 113 | bb_error_msg("cannot background in uclinux (yet)"); |
114 | /* ... mainly because udhcpc calls client_background() | 114 | /* ... mainly because udhcpc calls client_background() |
115 | * in _the _middle _of _udhcpc _run_, not at the start! | 115 | * in _the _middle _of _udhcpc _run_, not at the start! |
@@ -119,8 +119,7 @@ static void client_background(void) | |||
119 | bb_daemonize(0); | 119 | bb_daemonize(0); |
120 | logmode &= ~LOGMODE_STDIO; | 120 | logmode &= ~LOGMODE_STDIO; |
121 | /* rewrite pidfile, as our pid is different now */ | 121 | /* rewrite pidfile, as our pid is different now */ |
122 | if (client_config.pidfile) | 122 | write_pidfile(client_config.pidfile); |
123 | write_pidfile(client_config.pidfile); | ||
124 | #endif | 123 | #endif |
125 | /* Do not fork again. */ | 124 | /* Do not fork again. */ |
126 | client_config.foreground = 1; | 125 | client_config.foreground = 1; |
@@ -148,19 +147,17 @@ int udhcpc_main(int argc, char **argv) | |||
148 | char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_t; | 147 | char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_t; |
149 | uint32_t xid = 0; | 148 | uint32_t xid = 0; |
150 | uint32_t lease = 0; /* can be given as 32-bit quantity */ | 149 | uint32_t lease = 0; /* can be given as 32-bit quantity */ |
151 | unsigned t1 = 0, t2 = 0; | 150 | unsigned t1 = 0, t2 = 0; /* what a wonderful names */ |
152 | unsigned start = 0; | 151 | unsigned start = 0; |
153 | unsigned now; | 152 | unsigned now; |
154 | unsigned opt; | 153 | unsigned opt; |
155 | int max_fd; | 154 | int max_fd; |
156 | int sig; | ||
157 | int retval; | 155 | int retval; |
158 | int len; | 156 | int len; |
159 | int no_clientid = 0; | ||
160 | fd_set rfds; | ||
161 | struct timeval tv; | 157 | struct timeval tv; |
162 | struct dhcpMessage packet; | ||
163 | struct in_addr temp_addr; | 158 | struct in_addr temp_addr; |
159 | struct dhcpMessage packet; | ||
160 | fd_set rfds; | ||
164 | 161 | ||
165 | enum { | 162 | enum { |
166 | OPT_c = 1 << 0, | 163 | OPT_c = 1 << 0, |
@@ -224,8 +221,7 @@ int udhcpc_main(int argc, char **argv) | |||
224 | 221 | ||
225 | if (opt & OPT_c) | 222 | if (opt & OPT_c) |
226 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0); | 223 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0); |
227 | if (opt & OPT_C) | 224 | //if (opt & OPT_C) |
228 | no_clientid = 1; | ||
229 | if (opt & OPT_V) | 225 | if (opt & OPT_V) |
230 | client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0); | 226 | client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0); |
231 | if (opt & OPT_f) | 227 | if (opt & OPT_f) |
@@ -262,7 +258,7 @@ int udhcpc_main(int argc, char **argv) | |||
262 | if (opt & OPT_t) | 258 | if (opt & OPT_t) |
263 | client_config.retries = xatoi_u(str_t); | 259 | client_config.retries = xatoi_u(str_t); |
264 | if (opt & OPT_v) { | 260 | if (opt & OPT_v) { |
265 | printf("version %s\n\n", BB_VER); | 261 | printf("version %s\n", BB_VER); |
266 | return 0; | 262 | return 0; |
267 | } | 263 | } |
268 | 264 | ||
@@ -272,14 +268,23 @@ int udhcpc_main(int argc, char **argv) | |||
272 | } | 268 | } |
273 | 269 | ||
274 | if (read_interface(client_config.interface, &client_config.ifindex, | 270 | if (read_interface(client_config.interface, &client_config.ifindex, |
275 | NULL, client_config.arp) < 0) | 271 | NULL, client_config.arp)) |
276 | return 1; | 272 | return 1; |
277 | 273 | ||
278 | /* Sanitize fd's and write pidfile */ | 274 | /* Make sure fd 0,1,2 are open */ |
279 | udhcp_make_pidfile(client_config.pidfile); | 275 | bb_sanitize_stdio(); |
276 | /* Equivalent of doing a fflush after every \n */ | ||
277 | setlinebuf(stdout); | ||
278 | |||
279 | /* Create pidfile */ | ||
280 | write_pidfile(client_config.pidfile); | ||
281 | /* if (!..) bb_perror_msg("cannot create pidfile %s", pidfile); */ | ||
282 | |||
283 | /* Goes to stdout and possibly syslog */ | ||
284 | bb_info_msg("%s (v%s) started", applet_name, BB_VER); | ||
280 | 285 | ||
281 | /* if not set, and not suppressed, setup the default client ID */ | 286 | /* if not set, and not suppressed, setup the default client ID */ |
282 | if (!client_config.clientid && !no_clientid) { | 287 | if (!client_config.clientid && !(opt & OPT_C)) { |
283 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); | 288 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); |
284 | client_config.clientid[OPT_DATA] = 1; | 289 | client_config.clientid[OPT_DATA] = 1; |
285 | memcpy(client_config.clientid + OPT_DATA+1, client_config.arp, 6); | 290 | memcpy(client_config.clientid + OPT_DATA+1, client_config.arp, 6); |
@@ -294,9 +299,12 @@ int udhcpc_main(int argc, char **argv) | |||
294 | state = INIT_SELECTING; | 299 | state = INIT_SELECTING; |
295 | udhcp_run_script(NULL, "deconfig"); | 300 | udhcp_run_script(NULL, "deconfig"); |
296 | change_mode(LISTEN_RAW); | 301 | change_mode(LISTEN_RAW); |
302 | tv.tv_sec = 0; | ||
303 | goto jump_in; | ||
297 | 304 | ||
298 | for (;;) { | 305 | for (;;) { |
299 | tv.tv_sec = timeout - monotonic_sec(); | 306 | tv.tv_sec = timeout - monotonic_sec(); |
307 | jump_in: | ||
300 | tv.tv_usec = 0; | 308 | tv.tv_usec = 0; |
301 | 309 | ||
302 | if (listen_mode != LISTEN_NONE && sockfd < 0) { | 310 | if (listen_mode != LISTEN_NONE && sockfd < 0) { |
@@ -307,13 +315,20 @@ int udhcpc_main(int argc, char **argv) | |||
307 | } | 315 | } |
308 | max_fd = udhcp_sp_fd_set(&rfds, sockfd); | 316 | max_fd = udhcp_sp_fd_set(&rfds, sockfd); |
309 | 317 | ||
318 | retval = 0; /* If we already timed out, fall through, else... */ | ||
310 | if (tv.tv_sec > 0) { | 319 | if (tv.tv_sec > 0) { |
311 | DEBUG("Waiting on select..."); | 320 | DEBUG("Waiting on select..."); |
312 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); | 321 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); |
313 | } else retval = 0; /* If we already timed out, fall through */ | 322 | } |
314 | 323 | ||
315 | now = monotonic_sec(); | 324 | now = monotonic_sec(); |
316 | if (retval == 0) { | 325 | if (retval < 0) { |
326 | /* EINTR? signal was caught, don't panic */ | ||
327 | if (errno != EINTR) { | ||
328 | /* Else: an error occured, panic! */ | ||
329 | bb_perror_msg_and_die("select"); | ||
330 | } | ||
331 | } else if (retval == 0) { | ||
317 | /* timeout dropped to zero */ | 332 | /* timeout dropped to zero */ |
318 | switch (state) { | 333 | switch (state) { |
319 | case INIT_SELECTING: | 334 | case INIT_SELECTING: |
@@ -377,9 +392,8 @@ int udhcpc_main(int argc, char **argv) | |||
377 | } else { | 392 | } else { |
378 | /* send a request packet */ | 393 | /* send a request packet */ |
379 | send_renew(xid, server_addr, requested_ip); /* unicast */ | 394 | send_renew(xid, server_addr, requested_ip); /* unicast */ |
380 | |||
381 | t1 = (t2 - t1) / 2 + t1; | 395 | t1 = (t2 - t1) / 2 + t1; |
382 | timeout = t1 + start; | 396 | timeout = start + t1; |
383 | } | 397 | } |
384 | break; | 398 | break; |
385 | case REBINDING: | 399 | case REBINDING: |
@@ -395,9 +409,8 @@ int udhcpc_main(int argc, char **argv) | |||
395 | } else { | 409 | } else { |
396 | /* send a request packet */ | 410 | /* send a request packet */ |
397 | send_renew(xid, 0, requested_ip); /* broadcast */ | 411 | send_renew(xid, 0, requested_ip); /* broadcast */ |
398 | |||
399 | t2 = (lease - t2) / 2 + t2; | 412 | t2 = (lease - t2) / 2 + t2; |
400 | timeout = t2 + start; | 413 | timeout = start + t2; |
401 | } | 414 | } |
402 | break; | 415 | break; |
403 | case RELEASED: | 416 | case RELEASED: |
@@ -405,7 +418,7 @@ int udhcpc_main(int argc, char **argv) | |||
405 | timeout = INT_MAX; | 418 | timeout = INT_MAX; |
406 | break; | 419 | break; |
407 | } | 420 | } |
408 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { | 421 | } else if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { |
409 | /* a packet is ready, read it */ | 422 | /* a packet is ready, read it */ |
410 | 423 | ||
411 | if (listen_mode == LISTEN_KERNEL) | 424 | if (listen_mode == LISTEN_KERNEL) |
@@ -480,7 +493,7 @@ int udhcpc_main(int argc, char **argv) | |||
480 | bb_info_msg("Lease of %s obtained, lease time %u", | 493 | bb_info_msg("Lease of %s obtained, lease time %u", |
481 | inet_ntoa(temp_addr), (unsigned)lease); | 494 | inet_ntoa(temp_addr), (unsigned)lease); |
482 | start = now; | 495 | start = now; |
483 | timeout = t1 + start; | 496 | timeout = start + t1; |
484 | requested_ip = packet.yiaddr; | 497 | requested_ip = packet.yiaddr; |
485 | udhcp_run_script(&packet, | 498 | udhcp_run_script(&packet, |
486 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); | 499 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); |
@@ -511,8 +524,9 @@ int udhcpc_main(int argc, char **argv) | |||
511 | break; | 524 | break; |
512 | /* case BOUND, RELEASED: - ignore all packets */ | 525 | /* case BOUND, RELEASED: - ignore all packets */ |
513 | } | 526 | } |
514 | } else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) { | 527 | } else { |
515 | switch (sig) { | 528 | int signo = udhcp_sp_read(&rfds); |
529 | switch (signo) { | ||
516 | case SIGUSR1: | 530 | case SIGUSR1: |
517 | perform_renew(); | 531 | perform_renew(); |
518 | break; | 532 | break; |
@@ -525,11 +539,6 @@ int udhcpc_main(int argc, char **argv) | |||
525 | perform_release(); | 539 | perform_release(); |
526 | goto ret0; | 540 | goto ret0; |
527 | } | 541 | } |
528 | } else if (retval == -1 && errno == EINTR) { | ||
529 | /* a signal was caught */ | ||
530 | } else { | ||
531 | /* An error occured */ | ||
532 | bb_perror_msg("select"); | ||
533 | } | 542 | } |
534 | } /* for (;;) */ | 543 | } /* for (;;) */ |
535 | ret0: | 544 | ret0: |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 8cac68195..89f57bfe8 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -51,7 +51,16 @@ int udhcpd_main(int argc, char **argv) | |||
51 | * otherwise NOMMU machines will parse config twice */ | 51 | * otherwise NOMMU machines will parse config twice */ |
52 | read_config(argv[1] ? argv[1] : DHCPD_CONF_FILE); | 52 | read_config(argv[1] ? argv[1] : DHCPD_CONF_FILE); |
53 | 53 | ||
54 | udhcp_make_pidfile(server_config.pidfile); | 54 | /* Make sure fd 0,1,2 are open */ |
55 | bb_sanitize_stdio(); | ||
56 | /* Equivalent of doing a fflush after every \n */ | ||
57 | setlinebuf(stdout); | ||
58 | |||
59 | /* Create pidfile */ | ||
60 | write_pidfile(server_config.pidfile); | ||
61 | /* if (!..) bb_perror_msg("cannot create pidfile %s", pidfile); */ | ||
62 | |||
63 | bb_info_msg("%s (v%s) started", applet_name, BB_VER); | ||
55 | 64 | ||
56 | option = find_option(server_config.options, DHCP_LEASE_TIME); | 65 | option = find_option(server_config.options, DHCP_LEASE_TIME); |
57 | server_config.lease = LEASE_TIME; | 66 | server_config.lease = LEASE_TIME; |
@@ -72,7 +81,7 @@ int udhcpd_main(int argc, char **argv) | |||
72 | read_leases(server_config.lease_file); | 81 | read_leases(server_config.lease_file); |
73 | 82 | ||
74 | if (read_interface(server_config.interface, &server_config.ifindex, | 83 | if (read_interface(server_config.interface, &server_config.ifindex, |
75 | &server_config.server, server_config.arp) < 0) { | 84 | &server_config.server, server_config.arp)) { |
76 | retval = 1; | 85 | retval = 1; |
77 | goto ret; | 86 | goto ret; |
78 | } | 87 | } |
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index 9bb7aeab5..4ed65a2d6 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -30,7 +30,7 @@ static struct xid_item { | |||
30 | } dhcprelay_xid_list = {0, {0}, 0, 0, NULL}; | 30 | } dhcprelay_xid_list = {0, {0}, 0, 0, NULL}; |
31 | 31 | ||
32 | 32 | ||
33 | static struct xid_item * xid_add(uint32_t xid, struct sockaddr_in *ip, int client) | 33 | static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) |
34 | { | 34 | { |
35 | struct xid_item *item; | 35 | struct xid_item *item; |
36 | 36 | ||
@@ -48,7 +48,6 @@ static struct xid_item * xid_add(uint32_t xid, struct sockaddr_in *ip, int clien | |||
48 | return item; | 48 | return item; |
49 | } | 49 | } |
50 | 50 | ||
51 | |||
52 | static void xid_expire(void) | 51 | static void xid_expire(void) |
53 | { | 52 | { |
54 | struct xid_item *item = dhcprelay_xid_list.next; | 53 | struct xid_item *item = dhcprelay_xid_list.next; |
@@ -56,7 +55,7 @@ static void xid_expire(void) | |||
56 | time_t current_time = time(NULL); | 55 | time_t current_time = time(NULL); |
57 | 56 | ||
58 | while (item != NULL) { | 57 | while (item != NULL) { |
59 | if ((current_time-item->timestamp) > MAX_LIFETIME) { | 58 | if ((current_time - item->timestamp) > MAX_LIFETIME) { |
60 | last->next = item->next; | 59 | last->next = item->next; |
61 | free(item); | 60 | free(item); |
62 | item = last->next; | 61 | item = last->next; |
@@ -67,7 +66,7 @@ static void xid_expire(void) | |||
67 | } | 66 | } |
68 | } | 67 | } |
69 | 68 | ||
70 | static struct xid_item * xid_find(uint32_t xid) | 69 | static struct xid_item *xid_find(uint32_t xid) |
71 | { | 70 | { |
72 | struct xid_item *item = dhcprelay_xid_list.next; | 71 | struct xid_item *item = dhcprelay_xid_list.next; |
73 | while (item != NULL) { | 72 | while (item != NULL) { |
@@ -95,7 +94,6 @@ static void xid_del(uint32_t xid) | |||
95 | } | 94 | } |
96 | } | 95 | } |
97 | 96 | ||
98 | |||
99 | /** | 97 | /** |
100 | * get_dhcp_packet_type - gets the message type of a dhcp packet | 98 | * get_dhcp_packet_type - gets the message type of a dhcp packet |
101 | * p - pointer to the dhcp packet | 99 | * p - pointer to the dhcp packet |
@@ -119,7 +117,8 @@ static int get_dhcp_packet_type(struct dhcpMessage *p) | |||
119 | * signal_handler - handles signals ;-) | 117 | * signal_handler - handles signals ;-) |
120 | * sig - sent signal | 118 | * sig - sent signal |
121 | */ | 119 | */ |
122 | static int dhcprelay_stopflag; | 120 | static smallint dhcprelay_stopflag; |
121 | |||
123 | static void dhcprelay_signal_handler(int sig) | 122 | static void dhcprelay_signal_handler(int sig) |
124 | { | 123 | { |
125 | dhcprelay_stopflag = 1; | 124 | dhcprelay_stopflag = 1; |
@@ -130,7 +129,7 @@ static void dhcprelay_signal_handler(int sig) | |||
130 | * dev_list - comma separated list of devices | 129 | * dev_list - comma separated list of devices |
131 | * returns array | 130 | * returns array |
132 | */ | 131 | */ |
133 | static char ** get_client_devices(char *dev_list, int *client_number) | 132 | static char **get_client_devices(char *dev_list, int *client_number) |
134 | { | 133 | { |
135 | char *s, *list, **client_dev; | 134 | char *s, *list, **client_dev; |
136 | int i, cn; | 135 | int i, cn; |
@@ -286,7 +285,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli | |||
286 | (struct sockaddr *)(&client_addr), &addr_size); | 285 | (struct sockaddr *)(&client_addr), &addr_size); |
287 | if (packlen <= 0) | 286 | if (packlen <= 0) |
288 | continue; | 287 | continue; |
289 | if (read_interface(clients[i-1], NULL, &dhcp_msg.giaddr, NULL) < 0) | 288 | if (read_interface(clients[i-1], NULL, &dhcp_msg.giaddr, NULL)) |
290 | dhcp_msg.giaddr = gw_ip; | 289 | dhcp_msg.giaddr = gw_ip; |
291 | pass_on(&dhcp_msg, packlen, i, fds, &client_addr, server_addr); | 290 | pass_on(&dhcp_msg, packlen, i, fds, &client_addr, server_addr); |
292 | } | 291 | } |
@@ -322,7 +321,7 @@ int dhcprelay_main(int argc, char **argv) | |||
322 | 321 | ||
323 | num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket); | 322 | num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket); |
324 | 323 | ||
325 | if (read_interface(argv[2], NULL, &gw_ip, NULL) == -1) | 324 | if (read_interface(argv[2], NULL, &gw_ip, NULL)) |
326 | return 1; | 325 | return 1; |
327 | 326 | ||
328 | dhcprelay_loop(fds, num_sockets, max_socket, clients, &server_addr, gw_ip); | 327 | dhcprelay_loop(fds, num_sockets, max_socket, clients, &server_addr, gw_ip); |
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 648f7623c..1e62f8e40 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c | |||
@@ -44,11 +44,11 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t | |||
44 | struct sockaddr_in *our_ip; | 44 | struct sockaddr_in *our_ip; |
45 | 45 | ||
46 | memset(&ifr, 0, sizeof(ifr)); | 46 | memset(&ifr, 0, sizeof(ifr)); |
47 | fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); | 47 | fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); |
48 | if (fd < 0) { | 48 | // if (fd < 0) { |
49 | bb_perror_msg("socket failed"); | 49 | // bb_perror_msg("socket failed"); |
50 | return -1; | 50 | // return -1; |
51 | } | 51 | // } |
52 | 52 | ||
53 | ifr.ifr_addr.sa_family = AF_INET; | 53 | ifr.ifr_addr.sa_family = AF_INET; |
54 | strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); | 54 | strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); |
@@ -83,6 +83,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t | |||
83 | arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); | 83 | arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); |
84 | } | 84 | } |
85 | 85 | ||
86 | close(fd); | ||
86 | return 0; | 87 | return 0; |
87 | } | 88 | } |
88 | 89 | ||