Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPV6 link local multicasting

I'm trying to figure out how to do the equivalent of an IPV4 broadcast using IPV6.

I'm creating a non-blocking IPV6 UDP socket.

From the side broadcasting i'm literally just doing a sendto "FF02::1" on port 12346.

On the listen side I discovered I need to join the group so I did the following:

    ipv6_mreq membership;
    memset( &membership.ipv6mr_multiaddr, 0, sizeof( in6_addr ) );
    membership.ipv6mr_multiaddr.u.Word[0]   = htons( 0xff02 );
    membership.ipv6mr_multiaddr.u.Word[7]   = htons( 0x0001 );
    membership.ipv6mr_interface             = 0;

    if( enable )
    {
        if ( 0 != setsockopt( m_Socket, SOL_SOCKET, IPV6_JOIN_GROUP, (char*)&membership, sizeof( ipv6_mreq ) ) )
        {
            DisplayError();
            return false;
        }
    }

However setsockopt always returns "WSAENOPROTOOPT". Why? Can anyone help me on this one? I'm at a complete loss.

Edit: I change the level to "IPPROTO_IPV6" but now I get a "WSAEINVAL".

like image 644
Goz Avatar asked Jun 18 '10 08:06

Goz


People also ask

Does IPv6 support multicast?

IPv6 defines three types of addresses: unicast, anycast, and multicast.

What is IPv6 multicast?

The IPv6 multicast address provides a method for distributing identical information or services to a defined group of interfaces, called the multicast group. Typically, the interfaces of the multicast group are on different nodes. An interface can belong to any number of multicast groups.

What is IPv6 link local used for?

IPv6 link-local addresses are addresses that can be used to communicate with nodes (hosts and routers) on an attached link. Packets with those addresses are not forwarded by routers.

What are the two types of IPv6 multicast addresses?

Unlike IPv4, there is no broadcast address in IPv6. Instead, IPv6 uses multicast, including an all-IPv6 devices well-known multicast address and a solicited-node multicast address.


2 Answers

The interface must be set for locally scoped IPv6 because the addresses are only unique to the interface. In simpler terms the address fe80::1 can belong to both eth0 and eth1 but are completely separate.

So this means you need to explicitly send a multicast packet on every up interface that supports multicast, or provide the user with a means of specifying a particular interface.

(edit) If it helps you can check out multicast code here,

http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/

like image 97
Steve-o Avatar answered Oct 30 '22 15:10

Steve-o


I think the problem is that you are leaving the ipv6mr_interface value at zero, which isn't good enough if you want to use a link-scope multicast address like ff02::1. You need to set the ipv6mr_interface value to the number corresponding with the local network interface you want the packets to be sent/received on. (You can find out what interface indices are available on the current computer by calling getaddrinfo() and reading the sin6_addr.s6_addr values out of the (struct sockaddr_in6 *)'s that it hands to you)

(If at this point you are thinking to yourself, wouldn't it be so much easier if interface zero acted as an "all interfaces" setting... yes, it would be. Alas, IPv6 doesn't do that for some reason :( )

like image 34
Jeremy Friesner Avatar answered Oct 30 '22 15:10

Jeremy Friesner