Date: Tue, 1 May 2012 07:48:12 -0700 (PDT) From: Unga <unga888@yahoo.com> To: Matthew Seaman <matthew@FreeBSD.org> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@FreeBSD.org> Subject: Re: localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE Message-ID: <1335883692.40276.YahooMailNeo@web160104.mail.bf1.yahoo.com> In-Reply-To: <4F9FC2AD.30905@FreeBSD.org> References: <1335866914.5649.YahooMailNeo@web160106.mail.bf1.yahoo.com> <4F9FC2AD.30905@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> From: Matthew Seaman <matthew@FreeBSD.org>=0A> To: Unga <unga888@yahoo.co= m>=0A> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@FreeBSD.org>= =0A> Sent: Tuesday, May 1, 2012 11:02 AM=0A> Subject: Re: localhost not rec= ognised in getaddrinfo(3) in FreeBSD 9.0-STABLE=0A> =0A> On 01/05/2012 11:0= 8, Unga wrote:=0A>> Following code fragment works in FreeBSD 8.1-RELEASE, = but not in FreeBSD =0A> 9.0-STABLE:=0A>> =0A>> error =3D getaddrinfo("loca= lhost", port, &hints, &res0);=0A>> =A0 if (error)=0A>> =A0 =A0 {=0A>> =A0 = =A0 =A0 fprintf(stderr,"getaddrinfo failed - %s\n", =0A> gai_strerror(error= ));=0A>> =A0 =A0 =A0 exit(1);=0A>> =A0 =A0 }=0A>> =0A>> It complains: get= addrinfo failed - hostname nor servname provided, or not =0A> known=0A>> = =0A>> Any idea why?=0A>> =0A> =0A> So, what is the variable 'port' initial= ized to?=A0 It should be a const=0A> char* with the name of a network servi= ce found in /etc/services or else=0A> the string representation of a port n= umber in decimal.=0A> =0A#define MYPORT =A0=A0=A0 =A0=A0=A0 4321=0A=0Achar= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 port[10];=0Asnprintf(port, si= zeof(port), "%d", MYPORT);=0A=0Aerror =3D getaddrinfo("localhost", port, &h= ints, &res0);=0A=0APls note, using 127.0.0.1 instead of localhost works. Bu= t I prefer to use localhost. =0A=0A> Failing that, this is almost certainly= a configuration snafu on your=0A> 9.0-STABLE box.=0A> =0A> Does this machi= ne have an entry for localhost in /etc/hosts ? Can it=0A> resolve localhost= via the DNS? Or through any other means such as NIS or=0A> LDAP?=0A> =0A> = What does:=0A> =0A> =A0 =A0 % getent hosts localhost=0A> =0A> return?=0A> = =0A=0A$ getent hosts localhost=0A127.0.0.1=A0=A0=A0=A0=A0=A0=A0=A0 localhos= t=A0 localhost.my.domain ftp.sam511.lan=0A=0A> If that fails, sanity check = /etc/nsswitch.conf and /etc/resolv.conf=0A> =0A=0Acat /etc/nsswitch.conf=0A= =0Agroup: compat=0Agroup_compat: nis=0Ahosts: files dns=0Anetworks: files= =0Apasswd: compat=0Apasswd_compat: nis=0Ashells: files=0Aservices: compat= =0Aservices_compat: nis=0Aprotocols: files=0Arpc: files=0A=0Acat /etc/resol= v.conf=0A=0Anameserver 192.168.1.1=0A=0ARegards=0AUnga
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1335883692.40276.YahooMailNeo>