Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enumerating ipv4 and ipv6 address of my cards using boost asio

I am trying to enumerate ipv4 and ipv6 addresses of all the network cards(I have 2 cards) my pc.

I am using the following code to do that.

using boost::asio::ip::tcp;
boost::asio::io_service io_service;

    tcp::resolver resolver(io_service);
    tcp::resolver::query query(boost::asio::ip::host_name(),"");
    tcp::resolver::iterator it=resolver.resolve(query);

    while(it!=tcp::resolver::iterator())
    {
        boost::asio::ip::address addr=(it++)->endpoint().address();
        if(addr.is_v6())
        {
            std::cout<<"ipv6 address: ";
        }
        else
            std::cout<<"ipv4 address: ";

        std::cout<<addr.to_string()<<std::endl;

    }

The code displays correct ipv4 addresses but not ipv6. Here is the output

ipv6 address: ::1
ipv4 address: 192.168.10.200
ipv4 address: 192.168.10.236

I have very minimum knowledge of ipv6. When I list the information about network interface using ipconfig/all I see that the actual ipv6 addresses are

fe80::226:5aff:fe14:5687%5 
fe80::225:64ff:feb2:4f61%4

Can someone please guide me how to list the ipv6 addresses. Thanks.

like image 653
dev Avatar asked Jun 13 '11 06:06

dev


1 Answers

If the platform is Windows 7 SP1 the link-local interfaces are being skipped as they are tagged "SkipAsSource" by Windows which means that getaddrinfo will not return them and hence neither will Boost.

You can try to inspect the flag with the following command:

netsh int ipv6 show addresses level=verbose

Address fe80::e0:0:0:0%14 Parameters
---------------------------------------------------------
Interface Luid     : Teredo Tunneling Pseudo-Interface
Scope Id           : 0.14
Valid Lifetime     : infinite
Preferred Lifetime : infinite
DAD State          : Deprecated
Address Type       : Other
Skip as Source     : **true**
like image 170
Steve-o Avatar answered Oct 13 '22 01:10

Steve-o