FAQ
I am trying to send and receive packages via an ipv6 multicast. But I
can't get it working. What I thought was, that on the listener site, I
just need to bind my socket to the interfaces ipv6 local link address
and on the sender site, to the multicast address (in my case ff02::).
That doesn't work :)

I am using this: http://code.activestate.com/recipes/442490/ as an
example code, but I do not understand to which ipv6 address the socket
must be bind, to get this working on my link local network.

To make clear what I want to do: Every node in my ff80:: network
should receive a UDP package and answer with something. The sending
node then receives all the answers and puts them in some kind of data
structure. Can't be to hard to do this, but I am just lost in ipv6 ;)

Search Discussions

  • Martin v. Löwis at Apr 13, 2009 at 5:51 pm

    Kai Timmer wrote:
    I am trying to send and receive packages via an ipv6 multicast. But I
    can't get it working. What I thought was, that on the listener site, I
    just need to bind my socket to the interfaces ipv6 local link address
    and on the sender site, to the multicast address (in my case ff02::).
    That doesn't work :)
    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.

    On the sending side, you just use sendto, passing the multicast
    address as the recipient.

    HTH,
    Martin
  • Kai Timmer at Apr 14, 2009 at 8:25 am

    On 13 Apr., 19:51, "Martin v. L?wis" 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.
  • Martin v. Löwis at Apr 14, 2009 at 6:25 pm

    I get the following error: "socket.error: [Errno 22] Invalid
    argument". So it complains about the multicast address.
    The fragment

    py> import socket
    py> s = socket.inet_pton(socket.AF_INET6, "ff02::1")
    py> sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    py> sock.bind(('', 9090))
    py> sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP,
    socket.inet_pton(socket.AF_INET6, "ff02::1")+'\0'*4)

    works fine for me.

    Regards,
    Martin

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 13, '09 at 4:27p
activeApr 14, '09 at 6:25p
posts4
users2
websitepython.org

2 users in discussion

Kai Timmer: 2 posts Martin v. Löwis: 2 posts

People

Translate

site design / logo © 2022 Grokbase