Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c - Using the name resolver of resolv.h with IPv6

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...