The getaddrinfo()
function not only allows for client programs to efficiently find the correct data for creating a socket to a given host, it also allows for se
Your getaddrinfo
is returning the wrong result for some reason. It's supposed to return the IPv6 socket first. The only thing I can think of is if your OS detects that your system has a low prio IPv6 (6to4 or Teredo) and avoids them, IMO wrongly so in that case. Edit: Just noticed my own computer does the same thing, I use 6to4.
However, you can either listen to both of them, or use AF_INET6
instead of AF_UNSPEC
. Then you can do setsockopt to disable IPV6_V6ONLY
.
getaddrinfo does the reasonable thing here and returns all applicable results (though in the wrong order, as I mentioned). Both one and two listen sockets are valid approaches, depending on your application.