Merge pull request #24 from vibe-d/multicast_if

Add an interface_index argument to joinMulticastGroup.
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2017-09-11 14:11:21 +02:00 committed by GitHub
commit 100bd2c491
3 changed files with 7 additions and 7 deletions

View file

@ -279,7 +279,7 @@ interface EventDriverSockets {
bool setBroadcast(DatagramSocketFD socket, bool enable); bool setBroadcast(DatagramSocketFD socket, bool enable);
/// Joins the multicast group associated with the given IP address. /// 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. /// Receives a single datagram.
void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish); void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish);

View file

@ -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; 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) { switch (multicast_address.addressFamily) {
default: assert(false, "Multicast only supported for IPv4/IPv6 sockets."); 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; } (); auto addr = () @trusted { return cast(sockaddr_in*)multicast_address.name; } ();
ip_mreq mreq; ip_mreq mreq;
mreq.imr_multiaddr = addr.sin_addr; 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; return () @trusted { return setsockopt(cast(sock_t)socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, ip_mreq.sizeof); } () == 0;
case AddressFamily.INET6: case AddressFamily.INET6:
version (Windows) { version (Windows) {
@ -601,7 +601,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
auto addr = () @trusted { return cast(sockaddr_in6*)multicast_address.name; } (); auto addr = () @trusted { return cast(sockaddr_in6*)multicast_address.name; } ();
ipv6_mreq mreq; ipv6_mreq mreq;
mreq.ipv6mr_multiaddr = addr.sin6_addr; 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; return () @trusted { return setsockopt(cast(sock_t)socket, IPPROTO_IP, IPV6_JOIN_GROUP, &mreq, ipv6_mreq.sizeof); } () == 0;
} }
} }

View file

@ -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; 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; import std.socket : AddressFamily;
@ -458,7 +458,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
auto addr = () @trusted { return cast(sockaddr_in*)multicast_address.name; } (); auto addr = () @trusted { return cast(sockaddr_in*)multicast_address.name; } ();
ip_mreq mreq; ip_mreq mreq;
mreq.imr_multiaddr = addr.sin_addr; 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; return () @trusted { return setsockopt(cast(SOCKET)socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, ip_mreq.sizeof); } () == 0;
case AddressFamily.INET6: case AddressFamily.INET6:
struct ipv6_mreq { struct ipv6_mreq {
@ -468,7 +468,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
auto addr = () @trusted { return cast(sockaddr_in6*)multicast_address.name; } (); auto addr = () @trusted { return cast(sockaddr_in6*)multicast_address.name; } ();
ipv6_mreq mreq; ipv6_mreq mreq;
mreq.ipv6mr_multiaddr = addr.sin6_addr; 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; return () @trusted { return setsockopt(cast(SOCKET)socket, IPPROTO_IP, IPV6_JOIN_GROUP, &mreq, ipv6_mreq.sizeof); } () == 0;
} }
} }