Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get 'aliases' the IPv6 way...

275 views
Skip to first unread message

Joseph Galbraith

unread,
Feb 4, 2005, 7:56:29 PM2/4/05
to
Using gethostbyname or gethostbyaddr the resulting
HOSTENT contains all the aliases for the server.

How do I retrieve this information in the ipv6
world?

Thanks,

Joseph

Stewart Tansley [MSFT]

unread,
Feb 8, 2005, 4:01:16 AM2/8/05
to
I think you're looking for getaddrinfo and getnameinfo.

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...

Alun Jones [MSFT]

unread,
Feb 4, 2005, 8:20:32 PM2/4/05
to
"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.


Joseph Galbraith

unread,
Feb 17, 2005, 6:27:33 PM2/17/05
to
Alun Jones [MSFT] wrote:
> "Joseph Galbraith" <Joseph.G...@nospam.nospam> wrote in message
> news:OGihE2xC...@TK2MSFTNGP14.phx.gbl...
>
>>Using gethostbyname or gethostbyaddr the resulting
>>HOSTENT contains all the aliases for the server.
>>
>>How do I retrieve this information in the ipv6
>>world?
>
>
> getaddrinfo is your friend here. It also has the advantage of working for
> IPv4 addresses, too.

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

Joseph Galbraith

unread,
Feb 17, 2005, 6:27:11 PM2/17/05
to Alun Jones [MSFT]
Alun Jones [MSFT] wrote:
> "Joseph Galbraith" <Joseph.G...@nospam.nospam> wrote in message
> news:OGihE2xC...@TK2MSFTNGP14.phx.gbl...
>
>>Using gethostbyname or gethostbyaddr the resulting
>>HOSTENT contains all the aliases for the server.
>>
>>How do I retrieve this information in the ipv6
>>world?
>
>
> getaddrinfo is your friend here. It also has the advantage of working for
> IPv4 addresses, too.

Yes, we would like to switch to use getaddinfo and getnameinfo.

Gisle Vanem

unread,
Feb 18, 2005, 1:40:01 AM2/18/05
to
"Joseph Galbraith" wrote:

> 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

skiski...@msn.com

unread,
Feb 9, 2017, 7:16:03 PM2/9/17
to
It doesn't work, the first ai_cononame is the hostname but after all the following are NULL.. getHostent is maybe deprecied but I can't get the aliases list with getaddrinfo...
0 new messages