[ds6-devel] gethostbyaddr() problem

Kirk Bollinger kirk at 128bits.org
Wed May 14 16:42:36 CEST 2003


I'm not a programmer but I'm trying to learn and play with
C and IPv6 at the same time so please don't laugh.
Eventually I'd like to be able to contribute to some open source
IPv6 projects. I initially wanted to modify traceroute6 so that when the
probes return different ipv6 addresses but when they all  resolve to the
same thing it won't print the same names multiple times:

ex:
traceroute to orange.kame.net (3ffe:501:4819:2000:203:47ff:fea5:3085) from
2002:XXXX:XXXX:1:2e0:4cff:fe77:42f1, 30 hops max, 16 byte packets

 3  unused.bbtransnet-range.ipv6.eurocyber.net (2001:768:f:4::1)  241.601
ms unused.bbtransnet-range.ipv6.eurocyber.net (2001:768:f:3::1)  244.956
ms unused.bbtransnet-range.ipv6.eurocyber.net (2001:768:f:4::1)  245.948
ms

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

Here's what I have


 int rval;
        struct hostent *hp_one;
        char address[150];
        char *hp1;
        struct sockaddr_in6 foo;
        char buf[64];
        memset(&foo, 0, sizeof(foo));

        hp1 = address;
        getAddress(address);
        printf("The address is: %s", address);

        if ((rval = inet_pton(AF_INET6, address, &foo)) > 0) {
                printf("\nSuccessful inet_pton() call");

                if (inet_ntop(AF_INET6, &foo, buf, sizeof(buf)) != NULL)
                        printf("\ninet6 addr: %s", buf);

        }       else {
                printf("\nERROR: inet_pton() failed!");
        }

        if ((hp_one = gethostbyaddr(&foo.sin6_addr,
			sizeof(&foo.sin6_addr), AF_INET6)) == NULL) {
                printf("\nERROR: gethostbyaddr() returned NULL!");
        } else {
                *hp1 = hp_one->h_name;
                printf("\nhostname is: %s", hp_one->h_name);
       }


the call to gethostbyaddr always returns NULL.

here's the output:


Enter ip address: ::1
The address is: ::1
Successful inet_pton() call
inet6 addr: ::1
ERROR: gethostbyaddr() returned NULL!

thanks!

-kirk



More information about the ds6-devel mailing list