Subject: Re: IPv6 with gethostbyname2 and gethostbyaddr
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-net
Date: 07/05/2002 04:50:00
> I read that gethostbyname2 and gethostbyaddr for IPv6 is being
> deprecated and that I should use getaddrinfo or getnodebyname
> instead.  And inet_aton manual recommends getaddrinfo and getnameinfo
> for IPv6.

> But how can I get gethostbyname2 and gethostbyaddr to work for IPv6?

Why would you want to?  Why _not_ use getnameinfo and getaddrinfo?

> Here are some examples:

>  $ ./a.out -6 ::1
>  Hostname: ::1
>  Address:

Well, yes, the first four octets of ::1 are zero.  What's surprising
about this?

>  $ ./a.out -6 localhost
>  Hostname: localhost
>  Address:

> I wanted the above to return:
>  Hostname: localhost
>  Address: ::1

Then you need to print it out correctly.  The printf responsible for
that line reads

>             printf("Address: %u.%u.%u.%u\n",
>                     (0xff & h->h_addr_list[idx][0]),
>                     (0xff & h->h_addr_list[idx][1]),
>                     (0xff & h->h_addr_list[idx][2]),
>                     (0xff & h->h_addr_list[idx][3]) );

and I am not really able to comprehend any mindset that expects that to
_ever_ print "Address: ::1".

You are also using sockaddr_in and inet_aton, which are IPv4-only.
(I'm not sure about gethostbyaddr(), but I think it too may be

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B