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 /libbb | |
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.
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xconnect.c | 15 |
1 files changed, 15 insertions, 0 deletions
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 | { |