I'm using BSD sockets, and while I imagine it's easy to determine if a user's OS supports IPv6 (by trying to make a socket with AF_INET6), I'm not sure how to programmatically determine if their router or ISP doesn't support such a connection. Will the connection simply fail, and if so, how do I distinguish that failure from a server simply being offline?
4 Answers
This post has a lot of good information on the subject, and specifically talks about getaddrinfo
providing information like this.
-
But let's say that getaddrinfo returns a linked list that includes an IPv6 address. Does this necessarily mean I can connect to that address? In other words, can I say for sure that if my router or ISP doesn't support IPv6, getaddrinfo will never include such an address in the addrinfo structure? – Jun 14 '11 at 15:58
As Ulrich Drepper says in his Userlevel IPv6 Programming Introduction, you should call getaddrinfo
with the AI_ADDRCONFIG
flag set (which ensures you will only get address types currently configured on the system), then try each result in order until one succeeds (as the results are sorted, with the first most likely to succeed, and so forth) or all fail.

- 35,395
- 6
- 71
- 104
-
But when you say "on the system", that sounds like what the _OS_ supports, rather than what their network supports -- or am I wrong? – Jun 14 '11 at 16:49
-
@oskar: It's whatever your interfaces are currently configured for, so you won't get any IPv6 addresses unless your system has an IPv6 address, and no IPv4 addresses unless your system has one of those. In any case, I would not expect an OS that does not support IPv6 to return IPv6 addresses in the first place. – Hasturkun Jun 14 '11 at 17:36
One idea would be to include multiple test servers, of as high "quality" as imaginable. I think Google are reachable over IPv6 for instance, and they tend to keep their things running. Add 4-5 more, and you should have a pretty low probability of them all being down at the same time.

- 391,730
- 64
- 469
- 606
-
So can I assume that connect() will fail in a way that is indistinguishable from a normal failed connection? I was hoping there would be a different error code returned, but logically I guess the OS wouldn't know enough to do that. – Jun 14 '11 at 15:40
Most people with publicly routable addresses configured (not fe80::/10 fc00::/7 and friends) and a ipv6 default route would be expected to be connected.
However, normally you shouldn't care whether the problem is because the server is unreachable in one particular way compared to being unreachable for some other reason.

- 30,608
- 7
- 64
- 57
-
The reason I care about it failing due to IPv6 is I can code it to only try IPv4 addresses from that point on. – Jun 14 '11 at 16:00