[ds6-devel] gethostbyaddr() problem

Mauro Tortonesi mauro at deepspace6.net
Thu May 15 01:51:55 CEST 2003


On Wed, 14 May 2003, Kirk Bollinger wrote:

> I found one reference that said gethostbyaddr didn't support AF_INET6 but
> other web sites seem to have it as supported.

gethostbyaddr does __NOT__ support AF_INET6.

you have to use getnameinfo, instead. see rfc2553 or the latest
draft-ietf-ipngwg-rfc2553bis-*.txt at www.ietf.org.

> Here's what I have

[...]

you should try to use getaddrinfo instead of inet_pton and getnameinfo
instead of inet_ntop wherever possible. e.g.:

char buf[256];
struct sockaddr_in6 sin6;
struct addrinfo hints, *res;


inet_ntop(AF_INET6, &sin6, buf, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';

becomes:

getnameinfo(&sin6, sizeof(sin6), buf, sizeof(buf) - 1,
            NULL, 0, NI_NUMERICHOST);
buf[sizeof(buf) - 1] = '\0';


and:


inet_pton(AF_INET6, buf, &sin6);

becomes:

getaddrinfo(buf, "ftp", &hints, &res);

the address you were looking for is in:

((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;


-- 
Aequam memento rebus in arduis servare mentem...

Mauro Tortonesi			mauro at deepspace6.net
				mauro at ferrara.linux.it
Deep Space 6 - IPv6 on Linux	http://www.deepspace6.net
Ferrara Linux Users Group	http://www.ferrara.linux.it


More information about the ds6-devel mailing list