From owner-freebsd-doc@FreeBSD.ORG Sat May 3 07:50:01 2014 Return-Path: Delivered-To: freebsd-doc@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 37E82C15 for ; Sat, 3 May 2014 07:50:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2361F1058 for ; Sat, 3 May 2014 07:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s437o0M5014908 for ; Sat, 3 May 2014 07:50:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s437o0AU014902; Sat, 3 May 2014 07:50:00 GMT (envelope-from gnats) Date: Sat, 3 May 2014 07:50:00 GMT Message-Id: <201405030750.s437o0AU014902@freefall.freebsd.org> To: freebsd-doc@FreeBSD.org Cc: From: Dreamcat4 Subject: Re: docs/189268: 3 getaddrinfo(3) - hostanme="localhost", but it returns IN_ADDR_ANY (0.0.0.0) X-BeenThere: freebsd-doc@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: Dreamcat4 List-Id: Documentation project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 May 2014 07:50:01 -0000 The following reply was made to PR docs/189268; it has been noted by GNATS. From: Dreamcat4 To: bug-followup@freebsd.org, dreamcat4@gmail.com Cc: Subject: Re: docs/189268: 3 getaddrinfo(3) - hostanme="localhost", but it returns IN_ADDR_ANY (0.0.0.0) Date: Sat, 3 May 2014 08:44:57 +0100 --001a1133059e7da3f704f87a150e Content-Type: text/plain; charset=UTF-8 getaddrinfo() returns a list of results. So I have updated my test program to walk the entire list. It now prints two results for PF_UNSPEC getaddrinfo ~/ root~# gcc test.c -o test && ./test 0.0.0.0 127.0.0.1 getaddrinfo ~/ root~# Where the first result in the list is supposed to be the ipv6's "::1" (but isn't). Anyway heres the new version of the test.c getaddrinfo ~/ root~# cat test.c #include #include #include #include #include #include #include #include /* man getaddrinfo */ int main() { struct addrinfo *addrinfo = NULL; struct addrinfo *rp = NULL; struct addrinfo hints; struct addrinfo res; int err; memset((void*)&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; err = getaddrinfo("localhost", "18083", &hints, &addrinfo); if (addrinfo) { for (rp = addrinfo; rp != NULL; rp = rp->ai_next) { printf("%s\n", inet_ntoa( ((struct sockaddr_in*)rp->ai_addr)->sin_addr )); } freeaddrinfo(addrinfo); return(0); } if (err || !addrinfo) { printf("getaddrinfo failed with code %i.\n",err); return(1); } printf("end_main()\n"); return (0); } getaddrinfo ~/ root~# gcc test.c -o test && ./test 0.0.0.0 127.0.0.1 getaddrinfo ~/ root~# --001a1133059e7da3f704f87a150e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
getaddrinfo() returns a list of results. So I have updated= my test program to walk the entire list. It now prints two results for PF_= UNSPEC

getaddrinfo ~/ root~# gcc test.c -o tes= t && ./test
0.0.0.0
127.0.0.1
getaddrinfo ~/ root~#=C2=A0

Where the first result in the list is supp= osed to be the ipv6's "::1" (but isn't).

Anyway heres the new version of the test.c

getaddrinfo ~/ root~# cat test.c=C2=A0
#include <string.h&g= t;
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>


/* man getaddrinfo */

int main()
{<= /div>
=C2=A0 struct addrinfo *addrinfo =3D NULL;
=C2=A0 struc= t addrinfo *rp =3D NULL;
=C2=A0 struct addrinfo hints;
= =C2=A0 struct addrinfo res;
=C2=A0 int err;

=C2=A0 memset((void*)&hin= ts, 0, sizeof(hints));
=C2=A0 hints.ai_family =C2=A0 =3D PF_UNSPE= C;
=C2=A0 hints.ai_socktype =3D SOCK_STREAM;
=C2=A0 hin= ts.ai_flags =C2=A0 =C2=A0=3D AI_PASSIVE;

=C2=A0 err =3D getaddrinfo("localhost", "= ;18083", &hints, &addrinfo);

=C2=A0 i= f (addrinfo)
=C2=A0 {=C2=A0
=C2=A0 =C2=A0 for (rp =3D a= ddrinfo; rp !=3D NULL; rp =3D rp->ai_next)
=C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 printf("%s\n"= , inet_ntoa( ((struct sockaddr_in*)rp->ai_addr)->sin_addr ));
=C2=A0 =C2=A0 }

=C2=A0 =C2=A0 freeaddrinfo(addr= info);
=C2=A0 =C2=A0 return(0);
=C2=A0 }

=C2=A0 if (err || !addrinfo)
= =C2=A0 {
=C2=A0 =C2=A0 printf("getaddrinfo failed with code = %i.\n",err);
=C2=A0 =C2=A0 return(1);
=C2=A0 }

=C2=A0 printf("end_main()\n");
=C2=A0 return (0);

}

getaddrinfo ~/ root~# gcc test.c -o test && ./test
0.0.0= .0
127.0.0.1
getaddrinfo ~/ root~#=C2=A0

--001a1133059e7da3f704f87a150e--