Commit f25a9c83 authored by Constantin Rack's avatar Constantin Rack

Merge pull request #1723 from GreatFruitOmsk/master

Family is not set when resolving NIC on android.
parents cfbeac6a 6c997477
...@@ -124,11 +124,17 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -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_) 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. #if defined ZMQ_HAVE_AIX || defined ZMQ_HAVE_HPUX
LIBZMQ_UNUSED (ipv6_); // IPv6 support not implemented for AIX or HP/UX.
if (ipv6_)
{
errno = ENODEV;
return -1;
}
#endif
// Create a socket. // 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); errno_assert (sd != -1);
struct ifreq ifr; struct ifreq ifr;
...@@ -146,12 +152,25 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -146,12 +152,25 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
errno = ENODEV; errno = ENODEV;
return -1; return -1;
} }
if (is_src_)
memcpy (&source_address.ipv4.sin_addr, const int family = ifr.ifr_addr.sa_family;
&((sockaddr_in*) &ifr.ifr_addr)->sin_addr, sizeof (struct in_addr)); 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 else
memcpy (&address.ipv4.sin_addr, {
&((sockaddr_in*) &ifr.ifr_addr)->sin_addr, sizeof (struct in_addr)); errno = ENODEV;
return -1;
}
return 0; return 0;
} }
......
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