def set_ipv4_multicast_source_address(sock, source_address):
"""Sets the given socket up to send multicast from the specified source.
Ensures the multicast TTL is set to 1, so that packets are not forwarded
beyond the local link.
:param sock: An opened IP socket.
:param source_address: A string representing an IPv4 source address.
"""
sock.setsockopt(
socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 1)
sock.setsockopt(
socket.IPPROTO_IP, socket.IP_MULTICAST_IF,
socket.inet_aton(source_address))
评论列表
文章目录