2

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
glglgl
  • 89,107
  • 13
  • 149
  • 217
lilawood
  • 333
  • 2
  • 4
  • 10
  • 2
    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
  • 1
    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

2 Answers2

5

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.

Simon Richter
  • 28,572
  • 1
  • 42
  • 64
  • 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.. GitHub STOP HELPING ICE May 12 '11 at 23:30
  • 1
    @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 00:52
  • 1
    @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 01:07
2

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...

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711