summaryrefslogtreecommitdiff
path: root/sysdep
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/bsd/sysio.h8
-rw-r--r--sysdep/linux/sysio.h15
-rw-r--r--sysdep/unix/io.c3
3 files changed, 24 insertions, 2 deletions
diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h
index 87c78fb3..ff821a77 100644
--- a/sysdep/bsd/sysio.h
+++ b/sysdep/bsd/sysio.h
@@ -22,6 +22,14 @@ get_inaddr(ip_addr *a, struct in6_addr *ia)
ipa_ntoh(*a);
}
+static inline char *
+sysio_bind_to_iface(sock *s)
+{
+ /* Unfortunately not available */
+ return NULL;
+}
+
+
#else
#include <net/if.h>
diff --git a/sysdep/linux/sysio.h b/sysdep/linux/sysio.h
index 1cfbcc4b..795d0b36 100644
--- a/sysdep/linux/sysio.h
+++ b/sysdep/linux/sysio.h
@@ -6,6 +6,8 @@
* Can be freely distributed and used under the terms of the GNU GPL.
*/
+#include <net/if.h>
+
#ifdef IPV6
#ifndef IPV6_UNICAST_HOPS
@@ -28,9 +30,18 @@ get_inaddr(ip_addr *a, struct in6_addr *ia)
ipa_ntoh(*a);
}
-#else
+static inline char *
+sysio_bind_to_iface(sock *s)
+{
+ struct ifreq ifr;
+ strcpy(ifr.ifr_name, s->iface->name);
+ if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
+ return "SO_BINDTODEVICE";
-#include <net/if.h>
+ return NULL;
+}
+
+#else
static inline void
set_inaddr(struct in_addr *ia, ip_addr a)
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index abfa5c26..a0dbb418 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -876,6 +876,9 @@ sk_setup_multicast(sock *s)
if (setsockopt(s->fd, SOL_IPV6, IPV6_MULTICAST_IF, &index, sizeof(index)) < 0)
ERR("IPV6_MULTICAST_IF");
+ if (err = sysio_bind_to_iface(s))
+ goto bad;
+
return 0;
bad: