Commit 93ccb5a1 authored by Constantin Rack's avatar Constantin Rack Committed by GitHub

Merge pull request #2215 from Bklyn/udp-bugfix

Problem: inconsistent indentation and tabs in code
parents 5879f729 10181d76
...@@ -240,135 +240,135 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -240,135 +240,135 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
#include <netioapi.h> #include <netioapi.h>
int zmq::tcp_address_t::get_interface_name(unsigned long index, char ** dest) const { int zmq::tcp_address_t::get_interface_name(unsigned long index, char ** dest) const {
char * buffer = (char*)malloc(IF_MAX_STRING_SIZE); char * buffer = (char*)malloc(IF_MAX_STRING_SIZE);
alloc_assert(buffer); alloc_assert(buffer);
char * if_name_result = NULL; char * if_name_result = NULL;
#ifndef ZMQ_HAVE_WINDOWS_TARGET_XP #ifndef ZMQ_HAVE_WINDOWS_TARGET_XP
if_name_result = if_indextoname(index, buffer); if_name_result = if_indextoname(index, buffer);
#endif #endif
if (if_name_result == NULL) { if (if_name_result == NULL) {
free(buffer); free(buffer);
return -1; return -1;
} }
*dest = buffer; *dest = buffer;
return 0; return 0;
} }
int zmq::tcp_address_t::wchar_to_utf8(const WCHAR * src, char ** dest) const { int zmq::tcp_address_t::wchar_to_utf8(const WCHAR * src, char ** dest) const {
int rc; int rc;
int buffer_len = WideCharToMultiByte(CP_UTF8, 0, int buffer_len = WideCharToMultiByte(CP_UTF8, 0,
src, -1, src, -1,
NULL, 0, NULL, 0,
NULL, 0); NULL, 0);
char * buffer = (char*) malloc(buffer_len); char * buffer = (char*) malloc(buffer_len);
alloc_assert(buffer); alloc_assert(buffer);
rc = WideCharToMultiByte(CP_UTF8, 0, rc = WideCharToMultiByte(CP_UTF8, 0,
src, -1, src, -1,
buffer, buffer_len, buffer, buffer_len,
NULL, 0); NULL, 0);
if (rc == 0) { if (rc == 0) {
free(buffer); free(buffer);
return -1; return -1;
} }
*dest = buffer; *dest = buffer;
return 0; return 0;
} }
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_)
{ {
int rc; int rc;
bool found = false; bool found = false;
const int max_attempts = 10; const int max_attempts = 10;
int iterations = 0; int iterations = 0;
IP_ADAPTER_ADDRESSES * addresses = NULL; IP_ADAPTER_ADDRESSES * addresses = NULL;
IP_ADAPTER_ADDRESSES * current_addresses = NULL; IP_ADAPTER_ADDRESSES * current_addresses = NULL;
unsigned long out_buf_len = sizeof(IP_ADAPTER_ADDRESSES); unsigned long out_buf_len = sizeof(IP_ADAPTER_ADDRESSES);
do { do {
addresses = (IP_ADAPTER_ADDRESSES *) malloc(out_buf_len); addresses = (IP_ADAPTER_ADDRESSES *) malloc(out_buf_len);
alloc_assert(addresses); alloc_assert(addresses);
rc = GetAdaptersAddresses(AF_UNSPEC, rc = GetAdaptersAddresses(AF_UNSPEC,
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER,
NULL, NULL,
addresses, &out_buf_len); addresses, &out_buf_len);
if (rc == ERROR_BUFFER_OVERFLOW) { if (rc == ERROR_BUFFER_OVERFLOW) {
free(addresses); free(addresses);
addresses = NULL; addresses = NULL;
} }
else { else {
break; break;
} }
iterations++; iterations++;
} while ((rc == ERROR_BUFFER_OVERFLOW) && (iterations < max_attempts)); } while ((rc == ERROR_BUFFER_OVERFLOW) && (iterations < max_attempts));
if (rc == 0) { if (rc == 0) {
current_addresses = addresses; current_addresses = addresses;
while (current_addresses) { while (current_addresses) {
char * if_name = NULL; char * if_name = NULL;
char * if_friendly_name = NULL; char * if_friendly_name = NULL;
int str_rc1, str_rc2; int str_rc1, str_rc2;
str_rc1 = get_interface_name(current_addresses->IfIndex, &if_name); str_rc1 = get_interface_name(current_addresses->IfIndex, &if_name);
str_rc2 = wchar_to_utf8(current_addresses->FriendlyName, &if_friendly_name); str_rc2 = wchar_to_utf8(current_addresses->FriendlyName, &if_friendly_name);
// Find a network adapter by its "name" or "friendly name" // Find a network adapter by its "name" or "friendly name"
if ( if (
((str_rc1 == 0) && (!strcmp(nic_, if_name))) ((str_rc1 == 0) && (!strcmp(nic_, if_name)))
|| ((str_rc2 == 0) && (!strcmp(nic_, if_friendly_name))) || ((str_rc2 == 0) && (!strcmp(nic_, if_friendly_name)))
) { ) {
// Iterate over all unicast addresses bound to the current network interface // Iterate over all unicast addresses bound to the current network interface
IP_ADAPTER_UNICAST_ADDRESS * unicast_address = current_addresses->FirstUnicastAddress; IP_ADAPTER_UNICAST_ADDRESS * unicast_address = current_addresses->FirstUnicastAddress;
IP_ADAPTER_UNICAST_ADDRESS * current_unicast_address = unicast_address; IP_ADAPTER_UNICAST_ADDRESS * current_unicast_address = unicast_address;
while (current_unicast_address) { while (current_unicast_address) {
ADDRESS_FAMILY family = current_unicast_address->Address.lpSockaddr->sa_family; ADDRESS_FAMILY family = current_unicast_address->Address.lpSockaddr->sa_family;
if (family == AF_INET || if (family == AF_INET ||
(ipv6_ && family == AF_INET6) (ipv6_ && family == AF_INET6)
) { ) {
if (is_src_) if (is_src_)
memcpy(&source_address, current_unicast_address->Address.lpSockaddr, memcpy(&source_address, current_unicast_address->Address.lpSockaddr,
(family == AF_INET) ? sizeof(struct sockaddr_in) (family == AF_INET) ? sizeof(struct sockaddr_in)
: sizeof(struct sockaddr_in6)); : sizeof(struct sockaddr_in6));
else else
memcpy(&address, current_unicast_address->Address.lpSockaddr, memcpy(&address, current_unicast_address->Address.lpSockaddr,
(family == AF_INET) ? sizeof(struct sockaddr_in) (family == AF_INET) ? sizeof(struct sockaddr_in)
: sizeof(struct sockaddr_in6)); : sizeof(struct sockaddr_in6));
found = true; found = true;
break; break;
} }
current_unicast_address = current_unicast_address->Next; current_unicast_address = current_unicast_address->Next;
} }
if (found) break; if (found) break;
} }
if (str_rc1 == 0) free(if_name); if (str_rc1 == 0) free(if_name);
if (str_rc2 == 0) free(if_friendly_name); if (str_rc2 == 0) free(if_friendly_name);
current_addresses = current_addresses->Next; current_addresses = current_addresses->Next;
} }
free(addresses); free(addresses);
} }
if (!found) { if (!found) {
errno = ENODEV; errno = ENODEV;
return -1; return -1;
} }
return 0; return 0;
} }
#else #else
...@@ -459,21 +459,21 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -459,21 +459,21 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
// Resolve the literal address. Some of the error info is lost in case // Resolve the literal address. Some of the error info is lost in case
// of error, however, there's no way to report EAI errors via errno. // of error, however, there's no way to report EAI errors via errno.
rc = getaddrinfo(interface_, NULL, &req, &res); rc = getaddrinfo(interface_, NULL, &req, &res);
#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.
if ((req.ai_family = AF_INET6) && (rc == WSAHOST_NOT_FOUND)) { if ((req.ai_family = AF_INET6) && (rc == WSAHOST_NOT_FOUND)) {
req.ai_family = AF_INET; req.ai_family = AF_INET;
rc = getaddrinfo(interface_, NULL, &req, &res); rc = getaddrinfo(interface_, NULL, &req, &res);
} }
#endif #endif
if (rc) { if (rc) {
errno = ENODEV; errno = ENODEV;
return -1; return -1;
} }
// Use the first result. // Use the first result.
zmq_assert (res != NULL); zmq_assert (res != NULL);
......
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