Last active
January 30, 2021 23:09
-
-
Save cmol/c6fa21148fd50ea998e0b78c0d1569cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_socket(multicast_addr, multicast_port, ifindex) | |
# Create, bind, and return a UDP multicast socket | |
UDPSocket.new(Socket::AF_INET6).tap do | s | | |
ip = IPAddr.new(multicast_addr).hton + [ifindex].pack('I') | |
s.setsockopt(Socket::IPPROTO_IPV6, Socket::IPV6_JOIN_GROUP, ip) | |
s.setsockopt(Socket::IPPROTO_IPV6, Socket::IPV6_MULTICAST_HOPS, [1].pack('I')) | |
s.setsockopt(Socket::IPPROTO_IPV6, Socket::IPV6_MULTICAST_IF, [ifindex].pack('I')) | |
s.bind("::", multicast_port) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment