[ds6-devel] gethostbyaddr() problem
Kirk Bollinger
kirk at 128bits.org
Wed May 28 13:30:44 CEST 2003
On Thu, 15 May 2003, Mauro Tortonesi wrote:
> 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;
thanks for the help!
now, I have one more thing I can't get to work. I want to print out the
addresses in ascii. I know that inet_ntop() is discouraged but it should
work.
here's my code:
if (res->ai_family == AF_INET6)
{
printf("\nAddress family: AF_INET6");
//printf("\nThe address is: %s", ((struct sockaddr_in6
*)res->ai_addr)->sin6_addr);
printf("\nnet_byte_order in hex is: %x", ((struct sockaddr_in6
*)res->ai_addr)->sin6_addr);
memset(&sin6, 0, sizeof(struct sockaddr_in6));
memcpy(&sin6, (struct sockaddr_in6 *)res->ai_addr, sizeof(struct
sockaddr_in6));
inet_ntop(AF_INET6, &sin6.sin6_addr, buf, 16);
printf("\nAddress is: %s", buf);
here's the output I'm getting:
Address family: AF_INET6
net_byte_order in hex is: 105fe3f
Address is:
I'm having fun playing and learning.
-kirk
More information about the ds6-devel
mailing list