Date: Wed, 30 Sep 2015 01:51:56 +0300 From: Dmitry Sivachenko <trtrmitya@gmail.com> To: FreeBSD Net <freebsd-net@freebsd.org> Subject: getaddrinfo() question Message-ID: <F5AD2BAC-7927-46CA-A52C-287685DD4260@gmail.com>
next in thread | raw e-mail | index | archive | help
--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 <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <string.h> #include <stdio.h> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F5AD2BAC-7927-46CA-A52C-287685DD4260>