From e53738558f2f1aa8cd536545479ab98b0df808c5 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Wed, 10 Dec 2008 11:12:16 +0000 Subject: *: fix SO_BINDTODEVICE. Kernel wants at least IFNAMSIZ bytes there. --- libbb/xconnect.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libbb') 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 @@ */ #include +#include #include "libbb.h" void FAST_FUNC setsockopt_reuseaddr(int fd) @@ -18,6 +19,20 @@ int FAST_FUNC setsockopt_broadcast(int fd) { return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); } +int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface) +{ + int r; + struct ifreq ifr; + strncpy_IFNAMSIZ(ifr.ifr_name, iface); + /* Actually, ifr_name is at offset 0, and in practice + * just giving char[IFNAMSIZ] instead of struct ifreq works too. + * But just in case it's not true on some obscure arch... */ + r = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)); + if (r) + bb_perror_msg("can't bind to interface %s", iface); + return r; +} + void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) { -- cgit v1.2.3