getaddrinfo vs gethostbyname

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Pierre Goyette (pierre_at_montreal.hcl.com)
Date: 06/30/04


Date: Wed, 30 Jun 2004 19:43:28 -0400

I am adding support to my application for IP V6 and have followed the
programming guidelines from Microsoft.

I replaced the call to 'gethostbyname' to 'getaddrinfo'.

The problem is that getaddrinfo doesn't seem to do what gethostbyname does.

When I call gethostbyname with the a NULL parameter, I get back a list of
all IP V4 address on my machine.

Example:

    192.168.1.101
    192.168.127.1
    192.168.236.1

However, whenever I call getaddrinfo with the parms below (and I tried other
parms), I only seem to get a loopback address.

  Hints.ai_family = PF_INET6;
  Hints.ai_socktype = SOCK_STREAM;
  Hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE;

 rc = getaddrinfo( NULL, szListenPort6, &Hints, &AddrInfo);

I want to listen on specific addresses for my service and I don't seem to be
able to enumerate addresses for IP V6 to do this. I used
GetAdaptersAddresses to get the real addresses but never seem to be able to
connect using those addresses.

All help is greatly appreciated.

Pierre



Relevant Pages

  • Re: Any way to bypass nameserver call in IPV6 ???
    ... >> Apache and several other open source projects have converted ... >> their code from using gethostbyname() to using getaddrinfo(). ... Thanks goes out to Richard Latham and Dale Talcott. ...
    (comp.unix.aix)
  • Re: Any way to bypass nameserver call in IPV6 ???
    ... > their code from using gethostbyname() to using getaddrinfo(). ... I noted that even though I specify a FQDN in ... /etc/"blah blah blah" file. ...
    (comp.unix.aix)
  • Re: Any way to bypass nameserver call in IPV6 ???
    ... >>their code from using gethostbyname() to using getaddrinfo(). ... > I believe you can get rid of the second query by using a resolv.conf ... forwarding only nameserver on each busy host. ...
    (comp.unix.aix)
  • Re: getaddrinfo vs gethostbyname
    ... Because you set AI_PASSIVE in Hints.ai_flags, and call getaddrinfo with node ... "Pierre Goyette" wrote in message ... > I replaced the call to 'gethostbyname' to 'getaddrinfo'. ... > parms), I only seem to get a loopback address. ...
    (microsoft.public.win32.programmer.networks)
  • Re: gethostbyname + timeout
    ... What is the advantages that getaddrinfo() over gethostbyname()? ... the man pages it only emphasizes getaddrinfois thread safe, ... no direct relation to the OP's question that concerns timeout feature. ...
    (comp.unix.programmer)