The man page for gethostbyname2(3) says: The gethostbyname2() function is an evolution of gethostbyname() which is intended to allow lookups in address families other than AF_INET, for ex- ample AF_INET6. Currently the af argument must be specified as AF_INET else the function will return NULL after having set h_errno to NETDB_INTERNAL This appears to be inaccurate: gethostbyname2("myhost6", AF_INET6) returns valid results. From looking at the source, it would appear that the manual is correct only when the resolver looks the name up in NIS. However, I don't have an NIS server and have not tested this. Fix: Suggestion: apply the following patch to /usr/src/lib/libc/net/gethostbyname.3 : How-To-Repeat: * /etc/host.conf should contain: hosts (and optionally "bind", either before or after "hosts") * /etc/hosts should contain: fec0::a:b:c:d myhost6 myhost6.my.domain * Compile ('cc -o foo foo.c') and run the following program: #include <stdio.h> #include <netdb.h> #include <sys/socket.h> main() { struct hostent *he; char buf[256]; he = gethostbyname2("myhost6", AF_INET6); if (he == NULL) { perror("gethostbyname2"); exit(1); } if (he->h_addrtype != AF_INET6) fprintf(stderr, "h_addrtype != AF_INET6 (%d)\n", he->h_addrtype); printf("address is [%s]\n", inet_ntop(AF_INET6, he->h_addr_list[0], buf, 256)); } This program prints address is [fec0::a:b:c:d]
Uhm - I'm just curious: What has _NIS_ to do with DNS issues???? Alex
On Fri, 5 Jan 2001, Alexander Langer wrote: > Uhm - I'm just curious: > > What has _NIS_ to do with DNS issues???? Nothing directly. The gethost*() functions get the host information from either /etc/hosts, NIS, or DNS, as specified in /etc/host.conf . gethostbyname() is the classic "get host information" function, but it only handles IPv4 (AF_INET). gethostbyname2() is more generic and can handle IPv6 (AF_INET6). gethostbyname2("myhost.dom.ain", AF_INET6) works quite well for /etc/hosts and DNS. The only case in which it doesn't work, as far as I can tell, is with NIS. I don't know whether this is a limitation of NIS itself, or just FreeBSD's implementation of it. At any rate, the man page for gethostbyname2() implies that only AF_INET works. This doesn't appear to be true. -- Andrew Arensburger This message *does* represent the arensb@ooblick.com views of ooblick.com ACK and you shall receive.
State Changed From-To: open->suspended Committed to HEAD, leaving it open as a reminder to MFC.
Responsible Changed From-To: freebsd-doc->alex I keep this open
To query IPv6 address from NIS, we need to use special map `ipnodes.byname'. -CURRENT version of getaddrinfo(3) do this (I dunno if it acutually works). However, gethostbyname2(3) and getipnodebyname(3) don't do this.
State Changed From-To: suspended->closed Close this now.