diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-10 11:12:16 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-10 11:12:16 +0000 |
commit | e53738558f2f1aa8cd536545479ab98b0df808c5 (patch) | |
tree | 187265ed8377d2eee805dc7cc6b9150774804805 | |
parent | 0d94820adf87b752c338c194a7291dcf1b96fc76 (diff) | |
download | busybox-w32-e53738558f2f1aa8cd536545479ab98b0df808c5.tar.gz busybox-w32-e53738558f2f1aa8cd536545479ab98b0df808c5.tar.bz2 busybox-w32-e53738558f2f1aa8cd536545479ab98b0df808c5.zip |
*: fix SO_BINDTODEVICE. Kernel wants at least IFNAMSIZ bytes there.
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/xconnect.c | 15 | ||||
-rw-r--r-- | networking/arping.c | 3 | ||||
-rw-r--r-- | networking/ping.c | 4 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 4 |
5 files changed, 21 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index 16e8f48db..e6767e39e 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -437,6 +437,7 @@ ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | |||
437 | * Turn it on before you call bind(). */ | 437 | * Turn it on before you call bind(). */ |
438 | void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */ | 438 | void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */ |
439 | int setsockopt_broadcast(int fd) FAST_FUNC; | 439 | int setsockopt_broadcast(int fd) FAST_FUNC; |
440 | int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC; | ||
440 | /* NB: returns port in host byte order */ | 441 | /* NB: returns port in host byte order */ |
441 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) FAST_FUNC; | 442 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) FAST_FUNC; |
442 | typedef struct len_and_sockaddr { | 443 | typedef struct len_and_sockaddr { |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 5be83241b..d078e9811 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <netinet/in.h> | 10 | #include <netinet/in.h> |
11 | #include <net/if.h> | ||
11 | #include "libbb.h" | 12 | #include "libbb.h" |
12 | 13 | ||
13 | void FAST_FUNC setsockopt_reuseaddr(int fd) | 14 | void FAST_FUNC setsockopt_reuseaddr(int fd) |
@@ -18,6 +19,20 @@ int FAST_FUNC setsockopt_broadcast(int fd) | |||
18 | { | 19 | { |
19 | return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); | 20 | return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); |
20 | } | 21 | } |
22 | int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface) | ||
23 | { | ||
24 | int r; | ||
25 | struct ifreq ifr; | ||
26 | strncpy_IFNAMSIZ(ifr.ifr_name, iface); | ||
27 | /* Actually, ifr_name is at offset 0, and in practice | ||
28 | * just giving char[IFNAMSIZ] instead of struct ifreq works too. | ||
29 | * But just in case it's not true on some obscure arch... */ | ||
30 | r = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)); | ||
31 | if (r) | ||
32 | bb_perror_msg("can't bind to interface %s", iface); | ||
33 | return r; | ||
34 | } | ||
35 | |||
21 | 36 | ||
22 | void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) | 37 | void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) |
23 | { | 38 | { |
diff --git a/networking/arping.c b/networking/arping.c index e7b842f5b..915af3261 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -331,8 +331,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv) | |||
331 | struct sockaddr_in saddr; | 331 | struct sockaddr_in saddr; |
332 | int probe_fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 332 | int probe_fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
333 | 333 | ||
334 | if (setsockopt(probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) == -1) | 334 | setsockopt_bindtodevice(probe_fd, device); |
335 | bb_perror_msg("cannot bind to device %s", device); | ||
336 | memset(&saddr, 0, sizeof(saddr)); | 335 | memset(&saddr, 0, sizeof(saddr)); |
337 | saddr.sin_family = AF_INET; | 336 | saddr.sin_family = AF_INET; |
338 | if (src.s_addr) { | 337 | if (src.s_addr) { |
diff --git a/networking/ping.c b/networking/ping.c index 01a9f9ac5..f2a612fde 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -572,7 +572,7 @@ static void ping4(len_and_sockaddr *lsa) | |||
572 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); | 572 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); |
573 | } | 573 | } |
574 | if (str_I) | 574 | if (str_I) |
575 | setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, str_I, strlen(str_I) + 1); | 575 | setsockopt_bindtodevice(pingsock, str_I); |
576 | 576 | ||
577 | /* enable broadcast pings */ | 577 | /* enable broadcast pings */ |
578 | setsockopt_broadcast(pingsock); | 578 | setsockopt_broadcast(pingsock); |
@@ -622,7 +622,7 @@ static void ping6(len_and_sockaddr *lsa) | |||
622 | if (source_lsa) | 622 | if (source_lsa) |
623 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); | 623 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); |
624 | if (str_I) | 624 | if (str_I) |
625 | setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, str_I, strlen(str_I) + 1); | 625 | setsockopt_bindtodevice(pingsock, str_I); |
626 | 626 | ||
627 | #ifdef ICMP6_FILTER | 627 | #ifdef ICMP6_FILTER |
628 | { | 628 | { |
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 857f0a4de..fdb558db4 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c | |||
@@ -98,8 +98,8 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) | |||
98 | bb_perror_msg_and_die("SO_BROADCAST"); | 98 | bb_perror_msg_and_die("SO_BROADCAST"); |
99 | 99 | ||
100 | /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ | 100 | /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ |
101 | if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &inf, strlen(inf) + 1) == -1) | 101 | if (setsockopt_bindtodevice(fd, inf)) |
102 | bb_perror_msg_and_die("SO_BINDTODEVICE"); | 102 | xfunc_die(); /* warning is already printed */ |
103 | 103 | ||
104 | memset(&addr, 0, sizeof(addr)); | 104 | memset(&addr, 0, sizeof(addr)); |
105 | addr.sin_family = AF_INET; | 105 | addr.sin_family = AF_INET; |