0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-29 08:39:42 +08:00

Family is not set when resolving NIC on android.

Make it ready to enable ipv6 for AIX or HP/UX
This commit is contained in:
Ilya Kulakov 2016-01-21 19:53:35 +06:00
parent e7850410f8
commit 6c9974770b

View File

@ -124,11 +124,17 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_src_)
{
// TODO: Unused parameter, IPv6 support not implemented for AIX or HP/UX.
LIBZMQ_UNUSED (ipv6_);
#if defined ZMQ_HAVE_AIX || defined ZMQ_HAVE_HPUX
// IPv6 support not implemented for AIX or HP/UX.
if (ipv6_)
{
errno = ENODEV;
return -1;
}
#endif
// Create a socket.
const int sd = open_socket (AF_INET, SOCK_DGRAM, 0);
const int sd = open_socket (ipv6_ ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
errno_assert (sd != -1);
struct ifreq ifr;
@ -146,12 +152,25 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
errno = ENODEV;
return -1;
}
if (is_src_)
memcpy (&source_address.ipv4.sin_addr,
&((sockaddr_in*) &ifr.ifr_addr)->sin_addr, sizeof (struct in_addr));
const int family = ifr.ifr_addr.sa_family;
if ((family == AF_INET || (ipv6_ && family == AF_INET6))
&& !strcmp (nic_, ifr.ifr_name))
{
if (is_src_)
memcpy (&source_address, &ifr.ifr_addr,
(family == AF_INET) ? sizeof (struct sockaddr_in)
: sizeof (struct sockaddr_in6));
else
memcpy (&address, &ifr.ifr_addr,
(family == AF_INET) ? sizeof (struct sockaddr_in)
: sizeof (struct sockaddr_in6));
}
else
memcpy (&address.ipv4.sin_addr,
&((sockaddr_in*) &ifr.ifr_addr)->sin_addr, sizeof (struct in_addr));
{
errno = ENODEV;
return -1;
}
return 0;
}