I'm searching for a function that take an IPv6 address as argument and returns the domain name.
To make it clear, 2a00:1450:8006::68 returns ipv6.google.com.
(The aim is to give this domain name to the getaddrinfo function.)
Thanks :-)
edit1 : I've tried getaddrinfo("2a00:1450:8006::68", "http", NULL, &result);
, it returns "address family for hostname not supported" and getaddrinfo("ipv6.google.com", "http", NULL, &result);
return an error "no address is associated with hotname".
EDIT2 : I agree with you, i've trouble with IPV6 system, I've tried http://test-ipv6.com/ and it appears that I've got no IPV6 adress but with ifconfig
it returns :
adr inet6: fe80::15b:fcff:fe65:d516/64 Scope:Lien
I think you do not have a valid IPv6 configuration. getaddrinfo()
will only return IPv6 answers that are reachable, so if your system does not have an IPv6 address with global scope and a route to the resolved address, the result will be removed from the result set.
The basic idea is that you call getaddrinfo
once and get a list of addresses to connect to -- if that list were to include unreachable addresses, programs would have to run into a timeout first before trying another address.
"Address family for hostname not supported" means that it has recognized that the address is an IPv6 address that need not be resolved via DNS, so it tries to match it against the list of allowed address families, fails and returns the error.
Resolving the host name attempts to get an "A" record for the host name, as that is appropriate for the only address family supported locally. No such record exists, hence it returns the information that no record exists. Since it never asked for the IPv6 address (that would have been pointless), it doesn't complain about the address family mismatch here.