From owner-freebsd-net@freebsd.org Tue Sep 29 22:52:02 2015 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 03E12A0C9EC for ; Tue, 29 Sep 2015 22:52:02 +0000 (UTC) (envelope-from trtrmitya@gmail.com) Received: from mail-la0-x233.google.com (mail-la0-x233.google.com [IPv6:2a00:1450:4010:c03::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7E6B31C53 for ; Tue, 29 Sep 2015 22:52:01 +0000 (UTC) (envelope-from trtrmitya@gmail.com) Received: by laclj5 with SMTP id lj5so26041491lac.3 for ; Tue, 29 Sep 2015 15:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=ry9gPp9XDRNrqA3T8K0A5KZOxLoTPkCW3ScrOjUbYgc=; b=seBwvPWZucM9NE+dk0Md/kJm1qB7NrgaIocC7hg8yi9cyarqRw2QBQlt2jRoM5B7a/ 3ZuvGT+bCu3eXw9H2XbgQKin9qgtR3kBSkJB5lr8yy9mDw3EG57p5B7qEQUOzoT9NDka MRmb+jm4MD5cil/f/aRx3y3kFYT/ObA2ugbke/y6MwAQcIoB1IZgitleYi1Ufkbgx2ht iM5qqEcaqq0y9ECPRkqh1X14hgBrZNYpllQ+ohDsY+Ry6YrUKPorG+6LgtX4ei/02aMn jY4uvxF9G8CCmIlAi4JeV9bLxcbTUYAkXYE1o0/k1zoMIA3NgmFpyiEgSut9tEP0Rr1l 19Sg== X-Received: by 10.152.224.130 with SMTP id rc2mr139330lac.116.1443567119096; Tue, 29 Sep 2015 15:51:59 -0700 (PDT) Received: from [10.0.1.4] (broadband-5-228-251-240.nationalcablenetworks.ru. [5.228.251.240]) by smtp.gmail.com with ESMTPSA id j11sm459487lfe.24.2015.09.29.15.51.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Sep 2015 15:51:57 -0700 (PDT) From: Dmitry Sivachenko Content-Type: multipart/mixed; boundary="Apple-Mail=_267DA67E-FB01-48D6-857A-D1FE3D23A94B" Subject: getaddrinfo() question Message-Id: Date: Wed, 30 Sep 2015 01:51:56 +0300 To: FreeBSD Net Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) X-Mailer: Apple Mail (2.2104) X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Sep 2015 22:52:02 -0000 --Apple-Mail=_267DA67E-FB01-48D6-857A-D1FE3D23A94B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello! I have a machine (FreeBSD-10/stable) with both ipv4 and ipv6 addresses = configured. Also I have ip6addrctl_policy=3D"ipv4_prefer" in rc.conf. I am trying to resolve a hostname which has both A and AAAA records and = I expect getaddrinfo() to return A record because of ipv4_prefer. I am running a sample program attached. When I use hints.ai_flags =3D AI_PASSIVE flag, the program prints = "AF_INET6" (why?), if I change that line to hints.ai_flags =3D 0; it = printf "AF_INET" (as expected). Can you please explain why AI_PASSIVE makes a difference? On FreeBSD, the manual page is unclear about the behavior when hostname = is not NULL and AI_PASSIVE is used, but on Linux it explicitly states = that "If node is not NULL, then the AI_PASSIVE flag is ignored." Thanks! --Apple-Mail=_267DA67E-FB01-48D6-857A-D1FE3D23A94B Content-Disposition: attachment; filename=test_getaddrinfo.c Content-Type: application/octet-stream; name="test_getaddrinfo.c" Content-Transfer-Encoding: 7bit #include #include #include #include #include int main() { struct addrinfo hints, *result; const char* host = "wfe0.ysv.freebsd.org"; memset(&result, 0, sizeof(result)); memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; hints.ai_protocol = 0; if (getaddrinfo(host, NULL, &hints, &result) == 0) { switch (result->ai_family) { case AF_INET: printf("AF_INET\n"); break; case AF_INET6: printf("AF_INET6\n"); break; } } } --Apple-Mail=_267DA67E-FB01-48D6-857A-D1FE3D23A94B--