X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=udpstream.cpp;h=77476499a69a2e13b61d1708ef366f222359424d;hp=74d6ef03ce7853658e8836bbb4a07256e32c9e5c;hb=6544fa0ec3f3a501bcb89ea977756911bd7f3ebd;hpb=b08dc2a81825a298a03f2dee2ae7dd7045e72739 diff --git a/udpstream.cpp b/udpstream.cpp index 74d6ef0..7747649 100644 --- a/udpstream.cpp +++ b/udpstream.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -9,7 +10,7 @@ #define SO_MAX_PACING_RATE 47 #endif -UDPStream::UDPStream(const sockaddr_in6 &dst, uint32_t pacing_rate, int ttl) +UDPStream::UDPStream(const sockaddr_in6 &dst, uint32_t pacing_rate, int ttl, int multicast_iface_index) : dst(dst) { sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); @@ -41,6 +42,18 @@ UDPStream::UDPStream(const sockaddr_in6 &dst, uint32_t pacing_rate, int ttl) log_perror("setsockopt(IPV6_MULTICAST_HOPS)"); } } + + if (multicast_iface_index != -1) { + ip_mreqn mr; + memset(&mr, 0, sizeof(mr)); + mr.imr_ifindex = multicast_iface_index; + if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &mr, sizeof(mr)) == -1) { + log_perror("setsockopt(IP_MULTICAST_IF)"); + } + if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF, &multicast_iface_index, sizeof(multicast_iface_index)) == -1) { + log_perror("setsockopt(IPV6_MULTICAST_IF)"); + } + } } UDPStream::~UDPStream()