From: trustee on
Hey all,

the gethostbyname manpage says that you can pass an IPv6 address to
it.

"... Here name is either a host name, or an IPv4 address in standard
dot notation, or an IPv6 address in colon (and possibly dot) notation.
(See RFC 1884 for the description of IPv6 addresses.)"

But calls like this fail on my system (return value = NULL):

gethostbyname("::1");
gethostbyname("2001:200:0:8002:203:47ff:fea5:3085"); // www.kame.net

Alternative functions like getaddrinfo or gethostbyname*2* can handle
these addresses.

Is this an error in the manpage or what could be the problem?

Kernel version: 2.6.26-2

Bye.
From: Ersek, Laszlo on
In article <e8e1cb1d-9693-4803-bf29-b4828de384e0(a)j27g2000yqn.googlegroups.com>, trustee <trustee(a)arcor.de> writes:

> But calls like this fail on my system (return value = NULL):
>
> gethostbyname("::1");
> gethostbyname("2001:200:0:8002:203:47ff:fea5:3085"); // www.kame.net

Two problems:
1) Those arguments are not names. They are addresses.
2) "The gethostbyname() function shall return an entry containing
addresses of address family AF_INET for the host with name name."

http://www.opengroup.org/onlinepubs/000095399/functions/gethostbyname.html

You are after AF_INET6.

Ulrich Drepper wrote a great tutorial.

http://people.redhat.com/drepper/userapi-ipv6.html

Cheers,
lacos
From: Barry Margolin on
In article <Njkdss1D7FSs(a)ludens>, lacos(a)ludens.elte.hu (Ersek, Laszlo)
wrote:

> In article
> <e8e1cb1d-9693-4803-bf29-b4828de384e0(a)j27g2000yqn.googlegroups.com>, trustee
> <trustee(a)arcor.de> writes:
>
> > But calls like this fail on my system (return value = NULL):
> >
> > gethostbyname("::1");
> > gethostbyname("2001:200:0:8002:203:47ff:fea5:3085"); // www.kame.net
>
> Two problems:
> 1) Those arguments are not names. They are addresses.

So? He quoted a sentence from the documentation that said that the
argument can be either a name, an IPv4 address, or an IPv6 address.

> 2) "The gethostbyname() function shall return an entry containing
> addresses of address family AF_INET for the host with name name."
>
> http://www.opengroup.org/onlinepubs/000095399/functions/gethostbyname.html

His question was about Linux, not POSIX. POSIX says that the behavior
is undefined if the argument is a numeric string, and Linux apparently
defines this to parse the address and return it.

>
> You are after AF_INET6.

He knows that, he said that gethostbyaddr2() does it right. But the man
page says that gethostbyaddr() should also work.

>
> Ulrich Drepper wrote a great tutorial.
>
> http://people.redhat.com/drepper/userapi-ipv6.html
>
> Cheers,
> lacos

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Ersek, Laszlo on
In article <barmar-C06191.15453603032010(a)news.eternal-september.org>,
Barry Margolin <barmar(a)alum.mit.edu> writes:
> In article <Njkdss1D7FSs(a)ludens>, lacos(a)ludens.elte.hu (Ersek, Laszlo)
> wrote:
>
>> Two problems:
>> 1) Those arguments are not names. They are addresses.
>
> So? He quoted a sentence from the documentation that said that the
> argument can be either a name, an IPv4 address, or an IPv6 address.
>
>> 2) "The gethostbyname() function shall return an entry containing
>> addresses of address family AF_INET for the host with name name."
>>
>> http://www.opengroup.org/onlinepubs/000095399/functions/gethostbyname.html
>
> His question was about Linux, not POSIX. POSIX says that the behavior
> is undefined if the argument is a numeric string, and Linux apparently
> defines this to parse the address and return it.

In general, I don't trust Linux manual pages -- not even for Linux. For
example, on my Debian Lenny desktop, there is

Package: manpages-dev
Version: 3.05-1
Description: Manual pages about using GNU/Linux for development
These man pages describe the Linux programming interface, including
these two sections:
2 = Linux system calls.

(Many lines snipped for brevity.)

Then,

$ man 2 write

----v----
WRITE(2) Linux Programmer's Manual WRITE(2)

NAME
write - write to a file descriptor

[...]

Linux 2007-06-18 WRITE(2)
----^----

The manual page does not contain a single instance of the word
"SIGXFSZ", even though Linux *does* generate SIGXFSZ for the thread when
appropriate.

.... Additionally, I just checked the glibc manual on this same system.
It bears no mention of SIGXFSZ in write()'s description either.
(Low-Level I/O | I/O Primitives.)

FreeBSD distributes (parts of) SUSv3.

http://www.opengroup.org/press/01jun04.htm

(I'm not bashing the people maintaining the glibc or the Linux
documentation. It's obvious that with limited resources, making the
implementation standards-conformant is more important than making the
decomentation implementation-conformant. I'm only saying, when one tries
to write portable code, it's more fruitful to check the POSIX docs for
Linux than to check the Linux docs themselves.)

Cheers,
lacos
From: Ersek, Laszlo on
In article <VOIRhp0HkbnY(a)ludens>, lacos(a)ludens.elte.hu (Ersek, Laszlo) writes:
> In article <barmar-C06191.15453603032010(a)news.eternal-september.org>,
> Barry Margolin <barmar(a)alum.mit.edu> writes:
>> In article <Njkdss1D7FSs(a)ludens>, lacos(a)ludens.elte.hu (Ersek, Laszlo)
>> wrote:
>>
>>> Two problems:
>>> 1) Those arguments are not names. They are addresses.
>>
>> So? He quoted a sentence from the documentation that said that the
>> argument can be either a name, an IPv4 address, or an IPv6 address.
>>
>>> 2) "The gethostbyname() function shall return an entry containing
>>> addresses of address family AF_INET for the host with name name."
>>>
>>> http://www.opengroup.org/onlinepubs/000095399/functions/gethostbyname.html
>>
>> His question was about Linux, not POSIX. POSIX says that the behavior
>> is undefined

unspecified


>> if the argument is a numeric string, and Linux apparently
>> defines this to parse the address and return it.
>
> In general, I don't trust Linux manual pages -- not even for Linux.
>
> [snip]
>
> (I'm not bashing the people maintaining the glibc or the Linux
> documentation. It's obvious that with limited resources, making the
> implementation standards-conformant is more important than making the
> decomentation implementation-conformant. I'm only saying, when one tries
> to write portable code, it's more fruitful to check the POSIX docs for
> Linux than to check the Linux docs themselves.)

Case in point, a google search of

gethostbyname glibc IPv6

turned up, as second hit, Debian Bug report #455762, from two years ago:

"[libc6] gethostbyname fails on IPv6 addresses"

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=455762

----v----
Tags: ipv6, upstream, wontfix
Found in version glibc/2.7-4
Forwarded to http://sourceware.org/bugzilla/show_bug.cgi?id=5479
----^----

It's instructive what the upstream maintainer thinks of the issue.

----v----
This never worked, people hardly ever use mapped addresses, and
gethostby* should not *EVER* be used in the first place. Anything to
get people away from gethostby* is a good thing.
----^----

The implementation is POSIX conformant, and the manual page is borked.

Cheers,
lacos