Take the 2-minute tour ×

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
share|improve this question
Seems like a roundabout way to get an address structure to me. Why not just pass "2a00:1450:8006::68" to getaddrinfo? –  Santa May 12 '11 at 23:00
It sounds like your machine and/or network doesn't support IPv6 - is it supposed to work? –  Carl Norum May 12 '11 at 23:10
No idea about your code, but I should mention that 2a00:1450:8006::68 actually has no reverse DNS. It would help if you actually tried to use an IPv6 address that has reverse DNS. –  Jeremy Visser May 13 '11 at 12:47
Absolutely every single interface gets an IPv6 address in the fe80::/64 range if your stack is even capable of IPv6. –  Omnifarious Nov 13 '11 at 19:38
Make that fe80::/10. Differing sources say different things. But I believe the standards say fe80::/10. –  Omnifarious Nov 13 '11 at 19:47
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
I think you're right about what's happening, but I also think this is a bug. The behavior you describe is only supposed to happen if the AI_ADDRCONFIG is set in the hints. –  R.. May 12 '11 at 23:30
@R.: For glibc, supplying hints as NULL is equivalent to ai_family = AF_SPEC and ai_flags = AI_V4MAPPED | AI_ADDRCONFIG. This would seem to be against the POSIX spec. –  caf May 13 '11 at 0:52
What is AF_SPEC? –  R.. May 13 '11 at 1:01
@R.: I meant AF_UNSPEC there. The deviant behaviour is noted in the "NOTES" section of the glibc getaddrinfo(3) man page as something that is "...considered an improvement on the specification.". –  caf May 13 '11 at 1:07
add comment

You're right to use getaddrinfo as the first step, but it cannot do reverse-dns lookups for you. You'll need to use getaddrinfo to convert the string form of the address to a sockaddr, which you can then pass to getnameinfo to do the reverse lookup.

With that said, I think Carl's comment is also relevant. It seems like your system is configured not to support IPv6...

share|improve this answer
add comment

Your Answer


