Finding the Right “Network Interface" for IPv6

I am trying to use Boost for some IPv6 and multicast network communications. I need to build an IPv6 multicast socket that uses a specific network interface index.

I managed to find the correct multicast option to set the network interface index to boost / asio / ip / detail / socket_option.hpp: explicit multicast_request (const boost :: asio :: ip :: address_v6 & multicast_address, unsigned long network_interface = 0)

The problem is that I do not know how to find the correct value for the "network_interface" parameter. Is there a way to get the value of network_interface using a local IPv6 address that I can provide? I looked through the documentation and examples, but found nothing.

- Dylan

+3
source share
2 answers

I don't think this is a platform-independent way of understanding this, just as there is no portable solution for listing local addresses .

On Linux, you can find what you want in the second column /proc/net/if_inet6, which is also more efficiently accessible through the interface rtnetlink(7).

+2
source

Each platform provides APIs for listing network interfaces, for example. getifaddrsfor many Unix and GetAdaptersAddressesfor Windows Note. Windows has a separate numerical space for IPv4 and IPv6 adapters, which makes the API call if_nametoindexquite confusing.

, OpenPGM , Windows :

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

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

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

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

+2

All Articles