enumerating ipv4 and ipv6 address of my cards using boost asio

Viewed 7177

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.

1 Answers
Related