R: Re: [ds6-devel] gethostbyaddr() problem
simone at deepspace6.net
simone at deepspace6.net
Wed May 28 22:50:08 CEST 2003
IIRC the last parameter should be sizeof(buf) instead of 16 and buf should be large enough to hold the representation, e.g. at least 38 bytes... Check the return value to see if conversion succeded.
Bye
--
Sent from my wireless blackberry handheld.
-----Original Message-----
From: Kirk Bollinger <kirk at 128bits.org>
To: ds6-devel at deepspace6.net <ds6-devel at deepspace6.net>
Sent: Wed May 28 21:30:44 2003
Subject: Re: [ds6-devel] gethostbyaddr() problem
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
_______________________________________________
ds6-devel mailing list
ds6-devel at deepspace6.net
http://lists.deepspace6.net/listinfo/ds6-devel
More information about the ds6-devel
mailing list