Bug 23823 - gethostbyname2 man page is inaccurate
Summary: gethostbyname2 man page is inaccurate
Status: Closed FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Books & Articles (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: alex
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2000-12-25 10:50 UTC by arensb
Modified: 2001-05-08 12:22 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (282 bytes, patch)
2000-12-25 10:50 UTC, arensb
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description arensb 2000-12-25 10:50:01 UTC
	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]
Comment 1 alex 2001-01-05 20:17:18 UTC
Uhm - I'm just curious:

What has _NIS_ to do with DNS issues????

Alex
Comment 2 arensb 2001-01-05 21:01:07 UTC
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.
Comment 3 alex freebsd_committer freebsd_triage 2001-01-06 12:48:53 UTC
State Changed
From-To: open->suspended

Committed to HEAD, leaving it open as a reminder to MFC. 


Comment 4 alex freebsd_committer freebsd_triage 2001-01-06 12:48:53 UTC
Responsible Changed
From-To: freebsd-doc->alex

I keep this open
Comment 5 Hajimu UMEMOTO freebsd_committer freebsd_triage 2001-03-17 17:22:07 UTC
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.
Comment 6 alex freebsd_committer freebsd_triage 2001-05-08 12:21:35 UTC
State Changed
From-To: suspended->closed

Close this now.