diff options
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 d48c50339..27c7424b6 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <netinet/in.h> | 9 | #include <netinet/in.h> |
10 | #include <net/if.h> | ||
10 | #include "libbb.h" | 11 | #include "libbb.h" |
11 | 12 | ||
12 | void FAST_FUNC setsockopt_reuseaddr(int fd) | 13 | void FAST_FUNC setsockopt_reuseaddr(int fd) |
@@ -17,6 +18,20 @@ int FAST_FUNC setsockopt_broadcast(int fd) | |||
17 | { | 18 | { |
18 | return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); | 19 | return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); |
19 | } | 20 | } |
21 | int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface) | ||
22 | { | ||
23 | int r; | ||
24 | struct ifreq ifr; | ||
25 | strncpy(ifr.ifr_name, iface, IFNAMSIZ); | ||
26 | /* Actually, ifr_name is at offset 0, and in practice | ||
27 | * just giving char[IFNAMSIZ] instead of struct ifreq works too. | ||
28 | * But just in case it's not true on some obscure arch... */ | ||
29 | r = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)); | ||
30 | if (r) | ||
31 | bb_perror_msg("can't bind to interface %s", iface); | ||
32 | return r; | ||
33 | } | ||
34 | |||
20 | 35 | ||
21 | void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) | 36 | void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) |
22 | { | 37 | { |