IPv6 connectivity test in C++

别来无恙 提交于 2019-12-24 03:35:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13441324/ipv6-connectivity-test-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!