Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Sep 2015 08:40:28 -0500
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        Dmitry Sivachenko <trtrmitya@gmail.com>, FreeBSD Net <freebsd-net@freebsd.org>
Subject:   Re: getaddrinfo() question
Message-ID:  <560BE64C.7090800@FreeBSD.org>
In-Reply-To: <F5AD2BAC-7927-46CA-A52C-287685DD4260@gmail.com>
References:  <F5AD2BAC-7927-46CA-A52C-287685DD4260@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 09/29/2015 17:51, Dmitry Sivachenko wrote:
> Hello!
>
> I have a machine (FreeBSD-10/stable) with both ipv4 and ipv6 addresses configured.
> Also I have ip6addrctl_policy="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 = AI_PASSIVE flag, the program prints "AF_INET6" (why?), if I change that line to hints.ai_flags = 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."

I haven't looked at the code or the RFCs recently, so my reply shouldn't be considered even remotely authoritative, but this behavior makes sense to me.  I believe ip6addrctl only applies to active/outgoing connections, since client programs usually don't provide a convenient way to choose the address family.  Passive/listening programs are different by nature:  they usually provide a way to configure the desired address families, and they usually want to listen on all families by default.  By using PF_UNSPEC with AI_PASSIVE, you're saying you want to listen on the given host's addresses, regardless of protocol family/version.  If you follow the ai_next pointers, you'll see that you're getting two addrinfo results:  AF_INET6 and AF_INET.  Since you're going to open passive/listening sockets, the order is irrelevant.

Like I said, though, this is just my interpretation.

Eric



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?560BE64C.7090800>