tags:

views:

320

answers:

2

I write or modify programs which perform name resolution and need a good control of the process. So I do not use getaddrinfo(), I go deeper and use res_query() / res_send() / etc in resolv.h, documented in resolver(3).

Although not documented, the common way to set the resolver used is to update _res.nsaddr_list. But this array, defined in resolv.h, stores struct sockaddr_in, that is IPv4 addresses only. (IPv6 addresses are struct sockaddr_in6, a family-independant system would use struct sockaddr.)

I'm looking for a way (preferrably portable, at least among the various Unix) to tell _res that I want also IPv6 addresses.

Apparently, a long time ago, there was in FreeBSD a _res_ext with this ability but I cannot find it anymore in a recent FreeBSD 7 (grep _res_ext /usr/include/resolv.h finds nothing). You can still find code which uses it (try yourself with Google Codesearch).

Thanks to Alnitak, I noticed it is apparently now _res._ext and not .res_ext. I wonder where these sort of things are documented or announced... I have no idea how portable _res._ext is. I can find it on Debian and FreeBSD. It seems there are few programs which use it.

+2  A: 

Stéphane - if your resolv.h doesn't include any support for sockaddr_in6 then that suggests that on your particular O/S the resolver does not itself support IPv6 transport.

I've checked some of my systems here:

  • MacOS X 10.5.6 - supports the BIND 9 library, which has a res_setservers() function which can take IPv6 addresses, no _res._ext extension.

  • CentOS 5.2 - has the _res._ext extension, although there's no mention of IPv6 in the man page for resolv.conf except that there's a setting to tell the resolver to return AAAA records before looking for A records for gethostbyname().

EDIT - also, the CVS repository for FreeBSD suggests that FreeBSD 7.0 (see tag FREEBSD_7_0_0_RELEASE) does also support res_setservers() from Bind 9.

Alnitak
But undocumented :-( susanna:~ % uname -r 7.0-RELEASE susanna:~ % man res_setservers No manual entry for res_setservers
bortzmeyer
I do not find `res_setservers` on Linux/glibc machines. I assume there is no standard for IPv6 resolution :-(
bortzmeyer
odd - it's in the resolv.h file :(. The symbol does exist in Mac OS X, although it's really res_9_setservers and a #define gives access to the normal version.
Alnitak
+1  A: 

glibc:

res_setservers: no
__res_state._u._ext.nsaddrs
__res_state._u._ext.nsmap

set the latter to MAXNS+1 according to:

http://sourceware.org/ml/libc-hacker/2002-05/msg00035.html

BSD-libc:

res_setservers: yes
__res_state._u._ext.__res_state_ext

Seems messy to me and you'll probably need autoconf.