sending and receiving ipv6 multicasts
Kai Timmer
email at kait.de
Tue Apr 14 04:25:11 EDT 2009
On 13 Apr., 19:51, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> On the receiving side, you also need to set the IPV6_JOIN_GROUP
> socket option - else your kernel doesn't know you are interested in
> packets for that address. You need to bind to the multicast port,
> and optionally to the multicast address.
If I do the following
s , ifn = createSocket("eth0")
maddr = ("ff02::1", 10101)
maddr = socket.getaddrinfo(maddr[0], maddr[1], socket.AF_INET6,
socket.SOCK_DGRAM)[0][-1]
group = socket.inet_pton(socket.AF_INET6, maddr[0]) + ifn #ifn is the
interface index
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, group)
s.bind(maddr)
def createSocket(if=""):
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if hasattr(socket, "SO_REUSEPORT"):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP,
1)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS,
224)
ifn = if_nametoindex(if)
ifn = struct.pack("I", ifn)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF,
ifn)
return sock, ifn
I get the following error: "socket.error: [Errno 22] Invalid
argument". So it complains about the multicast address.
More information about the Python-list
mailing list