Add an interface_index argument to joinMulticastGroup.
This commit is contained in:
parent
8b95e9fb2d
commit
28e1a83057
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue