How do I retrieve this information in the ipv6
world?
Thanks,
Joseph
This might help further:
http://ipv6style.m-t.com/en/apps/20030711/index.shtml
Stewart.
http://research.microsoft.com/ur
http://www.microsoft.com/ipv6
"Joseph Galbraith" <Joseph.G...@nospam.nospam> wrote in message
news:OGihE2xC...@TK2MSFTNGP14.phx.gbl...
getaddrinfo is your friend here. It also has the advantage of working for
IPv4 addresses, too.
Alun.
~~~~
--
Software Design Engineer, Internet Information Server (FTP)
This posting is provided "AS IS" with no warranties, and confers no rights.
Yes, we would like to switch to use getaddinfo and getnameinfo.
However, we currently use the h_aliases information returned
in the hostent. We need to be able to retrieve this same
information in an IPv6 compatibile way. (I believe this
information corresponds to the DNS CNAMEs, but I could be
wrong.)
I don't believe either getaddrinfo or getnameinfo return
information about the aliases. (I'm pretty sure getnameinfo
doesn't because it's interfaces doesn't allow multiple names
to be returned.)
getaddrinfo()'s interface looks like it might, but it seems
like empirically it doesn't actually return the information.
(It would have to come back in a field name canonname which
would be a little unintuitive, but I could live with that.)
How can I get the information contained in the hostent's
aliases field in a IPv6 compatible way?
Thank you,
Joseph
Yes, we would like to switch to use getaddinfo and getnameinfo.
> getaddrinfo()'s interface looks like it might, but it seems
> like empirically it doesn't actually return the information.
> (It would have to come back in a field name canonname which
> would be a little unintuitive, but I could live with that.)
You mean "struct addrinfo::ai_canonname"? First call the
getaddrinfo() with the correct hints etc. Then loop over all
the returned ai pointers. Something like:
struct addrinfo hints, *ai;
int i;
memset (&hints, 0, sizeof(hints));
hints.ai_family = af; /* AF_INET, ASF_INET6 etc. */
hints.ai_flags = AI_CANONNAME;
printf ("IPv%c info:", af == AF_INET6 ? '6' : '4');
fflush (stdout);
if (getaddrinfo (host, serv, &hints, &ai) == 0)
{
for (i = 0; ai; ai = ai->ai_next, i++)
{
const struct in_addr *addr4 = &((const struct sockaddr_in*)ai->ai_addr)->sin_addr;
const struct in6_addr *addr6 = &((const struct sockaddr_in6*)ai->ai_addr)->sin6_addr;
char buf [INET6_ADDRSTRLEN];
af = ai->ai_addr->sa_family;
printf ("CNAME %s, ", ai->ai_canonname ? ai->ai_canonname : "<none>");
...
PS. The alias/cname is normally present in the first 'ai' only (when i == 0).
> How can I get the information contained in the hostent's
> aliases field in a IPv6 compatible way?
The above snippet should work for any address-family the Winsock nameresolver
knows about.
--gv