From owner-freebsd-questions@FreeBSD.ORG Tue May 1 14:48:19 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E0B7E1065672 for ; Tue, 1 May 2012 14:48:19 +0000 (UTC) (envelope-from unga888@yahoo.com) Received: from nm11-vm0.bullet.mail.bf1.yahoo.com (nm11-vm0.bullet.mail.bf1.yahoo.com [98.139.213.136]) by mx1.freebsd.org (Postfix) with SMTP id 927FD8FC15 for ; Tue, 1 May 2012 14:48:19 +0000 (UTC) Received: from [98.139.212.145] by nm11.bullet.mail.bf1.yahoo.com with NNFMP; 01 May 2012 14:48:13 -0000 Received: from [98.139.215.251] by tm2.bullet.mail.bf1.yahoo.com with NNFMP; 01 May 2012 14:48:13 -0000 Received: from [127.0.0.1] by omp1064.mail.bf1.yahoo.com with NNFMP; 01 May 2012 14:48:13 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 43348.76494.bm@omp1064.mail.bf1.yahoo.com Received: (qmail 41455 invoked by uid 60001); 1 May 2012 14:48:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1335883692; bh=MGumfbhwAxrwFKQbuGMStFohUfurq2A5YMhyJPHoHRo=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=46VNAM2dL3EgIFoky8RmD3Vmt0f3WiAvX5uLtk024I4gDGdgyokbQkiDU15W5ZpLZvz/4j/SS89V8kpbK8pm5ae50Oo15hjC1kgVUO62GcFPiFvJ+Xs0gF7QJhnJtgmPuE2W+UMlDYq3m/qCsCZnx3vdYeOoQ2RkDP2Br9u7YqM= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ggLlKofmA8UGnWZsLHz7MTaF5f5dYBHq6GWifjB3st5CQT+r2TVTfukhlkH0DgSHsFx+LhQWQwlm+NIK61k4ZyvaPzLoV9Iihiqt7jalKlVciZ4UDq4s1Tknc8Jz2gbgAIPKxMvOfHF5a3HjYTdOM+VaRwVLMvuiAPjjqXahG4A=; X-YMail-OSG: kqcnbccVM1lm.W2pCH1UnZJGBf.z32jPOd0mkqXvEXuIjki HuLZjxvHzcqHx6XE_PPwSiOpjYRvaSAEcjJGc5MEPr9j7BZku..pUs_alSE1 bFXOWZGYqEAB5YNAtDsVJ3eg2Y9Sk.Tt0M4u7cX.UKNpWcdzkF5X6.FBpVkw KD6jW_KlB0x7U8sZWn3GY8RNv0EZi2fkmYPEiNyjE4XzLXqgm3h1XDhqW90f LoTTueohH8JMsE2dO_todDtQyNqvczut71kkwSoBwQWcSHzCdOoIEmNwp3kg yXrnD6vi50xyhT8zEcx1tlPWjTEMIeC89LAUZ0pqJgErWxaD4uFRBakhgVkA SCRRgOVjfOvmEAJCcYZ8.0XzXEZ4GW2gp82gDWB4QMSVnS5GLyHwKHSk6nXP Jl7p1DL5czpcfhv5atS_hMSsgA7Mt6G99kXS3CKZBD3izwMZ6IBqh1JtHxeB .93mcW1iJdKx9ShAHw1p79GqWJrivAaVwYW5uCPEFbKGFc8A- Received: from [112.134.103.48] by web160104.mail.bf1.yahoo.com via HTTP; Tue, 01 May 2012 07:48:12 PDT X-Mailer: YahooMailWebService/0.8.118.349524 References: <1335866914.5649.YahooMailNeo@web160106.mail.bf1.yahoo.com> <4F9FC2AD.30905@FreeBSD.org> Message-ID: <1335883692.40276.YahooMailNeo@web160104.mail.bf1.yahoo.com> Date: Tue, 1 May 2012 07:48:12 -0700 (PDT) From: Unga To: Matthew Seaman In-Reply-To: <4F9FC2AD.30905@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "freebsd-questions@freebsd.org" Subject: Re: localhost not recognised in getaddrinfo(3) in FreeBSD 9.0-STABLE X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Unga List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 May 2012 14:48:20 -0000 > From: Matthew Seaman =0A> To: Unga =0A> Cc: "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