From owner-freebsd-questions@FreeBSD.ORG Fri Jul 13 02:00:49 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 BED561065673 for ; Fri, 13 Jul 2012 02:00:49 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (mx-out.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id 75AB48FC0A for ; Fri, 13 Jul 2012 02:00:49 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id q6D21oTp045911 for freebsd-questions@freebsd.org; Thu, 12 Jul 2012 21:01:50 -0500 (CDT) Date: Thu, 12 Jul 2012 21:01:50 -0500 (CDT) From: Robert Bonomi Message-Id: <201207130201.q6D21oTp045911@mail.r-bonomi.com> To: freebsd-questions@freebsd.org In-Reply-To: <80BE761E-42B1-4111-ACEC-0C31E43D105D@lafn.org> Subject: Re: IPv6 && getaddrinfo(3C) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jul 2012 02:00:49 -0000 > From: Doug Hardie > Date: Thu, 12 Jul 2012 14:21:38 -0700 > Subject: Re: IPv6 && getaddrinfo(3C) > > On 12 July 2012, at 07:24, Matthias Apitz wrote: > > > Hello, > > > > I'm playing around with IPv6 code on a FreeBSD 9 system and can't get > > getaddrinfo(3C) to do what it should do as stated in its man page: > > accept an IPv6 and IPv4 IP addr, it only works with the IPv6 form: > > > > $ ./a.out ::1 > > host: ::1 read: SSH-2.0-OpenSSH_5.6p1 FreeBSD-20101111 > > $ ./a.out 127.0.0.1 > > host: 127.0.0.1 ssh: getaddrinfo failed code 8: hostname nor servname > > provided, or not known > > $ telnet 127.0.0.1 22 > > Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. > > SSH-2.0-OpenSSH_5.6p1 FreeBSD-20101111 > > > > the used C-code is attached below; what I'm doing wrong in the code? > > > > Thanks > > > > matthias > > > > /* IPv6 client code using getaddrinfo */ > > > > #include > > #include > > #include > > #include > > #include > > #include > > #include > > > > > > main(argc, argv) /* client side */ > > int argc; char *argv[]; > > { > > > > struct addrinfo req, *ans; int code, s, n; char buf[1024]; > > > > memset(&req, 0, sizeof(req)); > > req.ai_flags = AI_ADDRCONFIG|AI_NUMERICHOST; > > req.ai_family = AF_INET6; /* Same as AF_INET6. */ Isn't the setting of 'req.ai_family', above, going to guarantee that something that "looks like" an IPv4 address will not be considered valid? After all, what *POSSIBLE* _IPv6_info_ is there about an IPv4 address? Per the manpage example, try PF_UNSPEC.