def join_ipv6_beacon_group(sock, ifindex):
"""Joins the MAAS IPv6 multicast group using the specified UDP socket.
:param sock: An opened IPv6 UDP socket.
:param ifindex: The interface index that should join the multicast group.
"""
# XXX mpontillo 2017-06-21: Twisted doesn't support IPv6 here yet.
# It would be nice to do this:
# transport.joinGroup(BEACON_IPV6_MULTICAST)
ipv6_join_sockopt_args = (
socket.inet_pton(socket.AF_INET6, BEACON_IPV6_MULTICAST) +
struct.pack("I", ifindex)
)
try:
sock.setsockopt(
socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP,
ipv6_join_sockopt_args)
except OSError:
# Do this on a best-effort basis. We might get an "Address already in
# use" error if the group is already joined, or (for whatever reason)
# it is not possible to join a multicast group using this interface.
pass
评论列表
文章目录