Re: localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE
> From: Matthew Seaman > To: Unga > Cc: "freebsd-questions@freebsd.org" > Sent: Tuesday, May 1, 2012 11:02 AM > Subject: Re: localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE > > 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. > #define MYPORT 4321 char port[10]; snprintf(port, sizeof(port), "%d", MYPORT); error = getaddrinfo("localhost", port, &hints, &res0); Pls note, using 127.0.0.1 instead of localhost works. But I prefer to use localhost. > 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? > $ getent hosts localhost 127.0.0.1 localhost localhost.my.domain ftp.sam511.lan > If that fails, sanity check /etc/nsswitch.conf and /etc/resolv.conf > cat /etc/nsswitch.conf group: compat group_compat: nis hosts: files dns networks: files passwd: compat passwd_compat: nis shells: files services: compat services_compat: nis protocols: files rpc: files cat /etc/resolv.conf nameserver 192.168.1.1 Regards Unga ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE
On 05/01/2012 01:02 PM, Matthew Seaman wrote: 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 Hi While updating 9.0-RELEASE to 9-STABLE today mergemaster wanted to put in a new hosts file that does not contain the localhost entry. I don know why this changed, but I left the localhost entry in my hosts file. Cheers Disclaimer: http://www.ose.nl/email ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE
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 signature.asc Description: OpenPGP digital signature
localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE
Hi all 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? Best regards Unga ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"