X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=udpstream.cpp;h=74d6ef03ce7853658e8836bbb4a07256e32c9e5c;hp=1e79494a3d8d302c5195ea17efeab83954eb37ea;hb=b08dc2a81825a298a03f2dee2ae7dd7045e72739;hpb=e58011d0b12b490acaf7b65f7462a119ca8d6410 diff --git a/udpstream.cpp b/udpstream.cpp index 1e79494..74d6ef0 100644 --- a/udpstream.cpp +++ b/udpstream.cpp @@ -9,8 +9,8 @@ #define SO_MAX_PACING_RATE 47 #endif -UDPStream::UDPStream(const sockaddr_in6 &dst, uint32_t pacing_rate) - : dst(dst) +UDPStream::UDPStream(const sockaddr_in6 &dst, uint32_t pacing_rate, int ttl) + : dst(dst) { sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (sock == -1) { @@ -24,6 +24,23 @@ UDPStream::UDPStream(const sockaddr_in6 &dst, uint32_t pacing_rate) log_perror("setsockopt(SO_MAX_PACING_RATE)"); } } + + if (ttl != -1) { + // Seemingly the IPv4 parameters are used for sending to IPv4, + // even on an AF_INET6 socket, so we need to set both. + if (setsockopt(sock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) == -1) { + log_perror("setsockopt(IP_TTL)"); + } + if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) == -1) { + log_perror("setsockopt(IP_MULTICAST_TTL)"); + } + if (setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) == -1) { + log_perror("setsockopt(IPV6_UNICAST_HOPS)"); + } + if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) == -1) { + log_perror("setsockopt(IPV6_MULTICAST_HOPS)"); + } + } } UDPStream::~UDPStream()