From 28e1a830573e42a6c521f2f443cf7e3f4669d5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 11 Sep 2017 13:35:34 +0200 Subject: [PATCH] Add an interface_index argument to joinMulticastGroup. --- source/eventcore/driver.d | 2 +- source/eventcore/drivers/posix/sockets.d | 6 +++--- source/eventcore/drivers/winapi/sockets.d | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index 76bae24..7747cde 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -279,7 +279,7 @@ interface EventDriverSockets { bool setBroadcast(DatagramSocketFD socket, bool enable); /// Joins the multicast group associated with the given IP address. - bool joinMulticastGroup(DatagramSocketFD socket, scope Address multicast_address); + bool joinMulticastGroup(DatagramSocketFD socket, scope Address multicast_address, uint interface_index = 0); /// Receives a single datagram. void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish); diff --git a/source/eventcore/drivers/posix/sockets.d b/source/eventcore/drivers/posix/sockets.d index cc0f62e..3607174 100644 --- a/source/eventcore/drivers/posix/sockets.d +++ b/source/eventcore/drivers/posix/sockets.d @@ -577,7 +577,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets return () @trusted { return setsockopt(cast(sock_t)socket, SOL_SOCKET, SO_BROADCAST, &tmp_broad, tmp_broad.sizeof); } () == 0; } - final override bool joinMulticastGroup(DatagramSocketFD socket, scope Address multicast_address) + final override bool joinMulticastGroup(DatagramSocketFD socket, scope Address multicast_address, uint interface_index = 0) { switch (multicast_address.addressFamily) { default: assert(false, "Multicast only supported for IPv4/IPv6 sockets."); @@ -589,7 +589,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets auto addr = () @trusted { return cast(sockaddr_in*)multicast_address.name; } (); ip_mreq mreq; mreq.imr_multiaddr = addr.sin_addr; - mreq.imr_interface.s_addr = htonl(INADDR_ANY); + mreq.imr_interface.s_addr = htonl(interface_index); return () @trusted { return setsockopt(cast(sock_t)socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, ip_mreq.sizeof); } () == 0; case AddressFamily.INET6: version (Windows) { @@ -601,7 +601,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets auto addr = () @trusted { return cast(sockaddr_in6*)multicast_address.name; } (); ipv6_mreq mreq; mreq.ipv6mr_multiaddr = addr.sin6_addr; - mreq.ipv6mr_interface = 0; + mreq.ipv6mr_interface = htonl(interface_index); return () @trusted { return setsockopt(cast(sock_t)socket, IPPROTO_IP, IPV6_JOIN_GROUP, &mreq, ipv6_mreq.sizeof); } () == 0; } } diff --git a/source/eventcore/drivers/winapi/sockets.d b/source/eventcore/drivers/winapi/sockets.d index f8f2323..b08ee1c 100644 --- a/source/eventcore/drivers/winapi/sockets.d +++ b/source/eventcore/drivers/winapi/sockets.d @@ -444,7 +444,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { return () @trusted { return setsockopt(cast(SOCKET)socket, SOL_SOCKET, SO_BROADCAST, &tmp_broad, tmp_broad.sizeof); } () == 0; } - final override bool joinMulticastGroup(DatagramSocketFD socket, scope Address multicast_address) + final override bool joinMulticastGroup(DatagramSocketFD socket, scope Address multicast_address, uint interface_index) { import std.socket : AddressFamily; @@ -458,7 +458,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { auto addr = () @trusted { return cast(sockaddr_in*)multicast_address.name; } (); ip_mreq mreq; mreq.imr_multiaddr = addr.sin_addr; - mreq.imr_interface.s_addr = htonl(INADDR_ANY); + mreq.imr_interface.s_addr = htonl(interface_index); return () @trusted { return setsockopt(cast(SOCKET)socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, ip_mreq.sizeof); } () == 0; case AddressFamily.INET6: struct ipv6_mreq { @@ -468,7 +468,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { auto addr = () @trusted { return cast(sockaddr_in6*)multicast_address.name; } (); ipv6_mreq mreq; mreq.ipv6mr_multiaddr = addr.sin6_addr; - mreq.ipv6mr_interface = 0; + mreq.ipv6mr_interface = htonl(interface_index); return () @trusted { return setsockopt(cast(SOCKET)socket, IPPROTO_IP, IPV6_JOIN_GROUP, &mreq, ipv6_mreq.sizeof); } () == 0; } }