localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE

Matthew Seaman matthew at FreeBSD.org
Tue May 1 11:02:10 UTC 2012


On 01/05/2012 11:08, Unga wrote:
> Following code fragment works in FreeBSD 8.1-RELEASE, but not in FreeBSD 9.0-STABLE:
> 
> error = getaddrinfo("localhost", port, &hints, &res0);
>  if (error)
>     {
>      fprintf(stderr,"getaddrinfo failed - %s\n", gai_strerror(error));
>      exit(1);
>     }
> 
> It complains: getaddrinfo failed - hostname nor servname provided, or not known
> 
> Any idea why?
> 

So, what is the variable 'port' initialized to?  It should be a const
char* with the name of a network service found in /etc/services or else
the string representation of a port number in decimal.

Failing that, this is almost certainly a configuration snafu on your
9.0-STABLE box.

Does this machine have an entry for localhost in /etc/hosts ? Can it
resolve localhost via the DNS? Or through any other means such as NIS or
LDAP?

What does:

    % getent hosts localhost

return?

If that fails, sanity check /etc/nsswitch.conf and /etc/resolv.conf

	Cheers,

	Matthew	

-- 
Dr Matthew J Seaman MA, D.Phil.
PGP: http://www.infracaninophile.co.uk/pgpkey


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20120501/defe2939/signature.pgp


More information about the freebsd-questions mailing list