Is there any C++ function to test whether the computer on which my program is running supports IPv6 connectivity?
I need to know something like result of this page http://test-ipv6.com/, but in C++.
EDIT: I was trying to use getifaddrs()
. But return value can be AF_INET6 found
, because I really have IPv6 address set, but IPv6 connectivity does not work (probably because ISP). So is there some way how to check if IPv6 connectivity works indeed?
All modern operating systems support IPv6, so you don't have to worry about whether the protocol is available. (If it isn't, your program won't compile anyway.)
But the only way to determine if the computer actually has working IPv6 connectivity is to attempt an IPv6 connection.
This is actually what Microsoft does with their network status indicator in Windows. They attempt to load a URL from an IPv6-only web server and a URL from an IPv4-only web server. If both of these fail, you get the yellow triangle with exclamation point over the network icon in the system tray.
Since I needed a similar functionality, but I also needed the actual IPv6 addresses, I created my own public service which includes this functionality (and several other things). So I have an IPv6-only URL which returns the public IPv6 address, and an IPv4-only URL which returns the public IPv4 address.
Because one of the URLs is only accessible via IPv6, and the other is only accessible via IPv4, you can independently verify connectivity for each protocol.
Either way, if your attempt to fetch the URL fails, you can examine the returned error to determine what the problem might be.