getaddrinfo() question

Dmitry Sivachenko trtrmitya at gmail.com
Tue Sep 29 22:52:02 UTC 2015


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."

Thanks!



-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_getaddrinfo.c
Type: application/octet-stream
Size: 678 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-net/attachments/20150930/434d0bc2/attachment.obj>


More information about the freebsd-net mailing list