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.
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**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With