Commit 6853e3f9 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #2514 from lytboris/freebsd-enable-ai_v4mapped

re-enable AI_V4MAPPED on FreeBSD & DragonFlyBSD
parents 63e1984a ef8b0c60
...@@ -448,12 +448,10 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -448,12 +448,10 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
// service-name irregularity due to indeterminate socktype. // service-name irregularity due to indeterminate socktype.
req.ai_flags = AI_PASSIVE | AI_NUMERICHOST; req.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
#if defined AI_V4MAPPED && !defined ZMQ_HAVE_FREEBSD && !defined ZMQ_HAVE_DRAGONFLY #if defined AI_V4MAPPED
// In this API we only require IPv4-mapped addresses when // In this API we only require IPv4-mapped addresses when
// no native IPv6 interfaces are available (~AI_ALL). // no native IPv6 interfaces are available (~AI_ALL).
// This saves an additional DNS roundtrip for IPv4 addresses. // This saves an additional DNS roundtrip for IPv4 addresses.
// Note: While the AI_V4MAPPED flag is defined on FreeBSD system,
// it is not supported here. See libzmq issue #331.
if (req.ai_family == AF_INET6) if (req.ai_family == AF_INET6)
req.ai_flags |= AI_V4MAPPED; req.ai_flags |= AI_V4MAPPED;
#endif #endif
...@@ -463,6 +461,15 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -463,6 +461,15 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
rc = getaddrinfo(interface_, NULL, &req, &res); rc = getaddrinfo(interface_, NULL, &req, &res);
#if defined AI_V4MAPPED
// Some OS do have AI_V4MAPPED defined but it is not supported in getaddrinfo()
// returning EAI_BADFLAGS. Detect this and retry
if (rc == EAI_BADFLAGS && (req.ai_flags & AI_V4MAPPED)) {
req.ai_flags &= ~AI_V4MAPPED;
rc = getaddrinfo(interface_, NULL, &req, &res);
}
#endif
#if defined ZMQ_HAVE_WINDOWS #if defined ZMQ_HAVE_WINDOWS
// Resolve specific case on Windows platform when using IPv4 address // Resolve specific case on Windows platform when using IPv4 address
// with ZMQ_IPv6 socket option. // with ZMQ_IPv6 socket option.
...@@ -509,12 +516,10 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo ...@@ -509,12 +516,10 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo
// doesn't really matter, since it's not included in the addr-output. // doesn't really matter, since it's not included in the addr-output.
req.ai_socktype = SOCK_STREAM; req.ai_socktype = SOCK_STREAM;
#if defined AI_V4MAPPED && !defined ZMQ_HAVE_FREEBSD && !defined ZMQ_HAVE_DRAGONFLY #if defined AI_V4MAPPED
// In this API we only require IPv4-mapped addresses when // In this API we only require IPv4-mapped addresses when
// no native IPv6 interfaces are available. // no native IPv6 interfaces are available.
// This saves an additional DNS roundtrip for IPv4 addresses. // This saves an additional DNS roundtrip for IPv4 addresses.
// Note: While the AI_V4MAPPED flag is defined on FreeBSD system,
// it is not supported here. See libzmq issue #331.
if (req.ai_family == AF_INET6) if (req.ai_family == AF_INET6)
req.ai_flags |= AI_V4MAPPED; req.ai_flags |= AI_V4MAPPED;
#endif #endif
...@@ -526,7 +531,17 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo ...@@ -526,7 +531,17 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo
#else #else
addrinfo *res; addrinfo *res;
#endif #endif
const int rc = getaddrinfo (hostname_, NULL, &req, &res); int rc = getaddrinfo (hostname_, NULL, &req, &res);
#if defined AI_V4MAPPED
// Some OS do have AI_V4MAPPED defined but it is not supported in getaddrinfo()
// returning EAI_BADFLAGS. Detect this and retry
if (rc == EAI_BADFLAGS && (req.ai_flags & AI_V4MAPPED)) {
req.ai_flags &= ~AI_V4MAPPED;
rc = getaddrinfo(hostname_, NULL, &req, &res);
}
#endif
if (rc) { if (rc) {
switch (rc) { switch (rc) {
case EAI_MEMORY: case EAI_MEMORY:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment