From 43471263f8defb73609ada4b6d5c2925688b87dd Mon Sep 17 00:00:00 2001 From: Mike Kuznetsov Date: Wed, 23 Dec 2020 09:25:18 -0600 Subject: [PATCH 1/4] Fixes for IPv6 on Windows --- ACE/ace/SOCK_Dgram.cpp | 46 +++++++++++++++++++++-------------- ACE/ace/config-win32-common.h | 6 ++--- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/ACE/ace/SOCK_Dgram.cpp b/ACE/ace/SOCK_Dgram.cpp index c67fe8c58bae7..0537ef32b3c53 100644 --- a/ACE/ace/SOCK_Dgram.cpp +++ b/ACE/ace/SOCK_Dgram.cpp @@ -786,21 +786,34 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, ACE_OS::ace_isdigit (net_if[0]) && (if_ix = ACE_OS::atoi (net_if)) > 0; - IP_ADAPTER_ADDRESSES tmp_addrs; - // Initial call to determine actual memory size needed - ULONG bufLen = 0; - char *buf = 0; - if (::GetAdaptersAddresses (AF_INET6, 0, 0, &tmp_addrs, &bufLen) - == ERROR_BUFFER_OVERFLOW) + ULONG bufLen = 15000; // Initial size as per Microsoft + char* buf = 0; + ACE_NEW_RETURN(buf, char[bufLen], -1); + DWORD dwRetVal = 0; + ULONG iterations = 0; + const ULONG maxTries = 3; + PIP_ADAPTER_ADDRESSES pAddrs; + do { - ACE_NEW_RETURN (buf, char[bufLen], -1); - } + pAddrs = reinterpret_cast (buf); + dwRetVal = ::GetAdaptersAddresses(AF_INET6, 0, 0, pAddrs, &bufLen); + if (dwRetVal == ERROR_BUFFER_OVERFLOW) + { + delete[] buf; + ACE_NEW_RETURN(buf, char[bufLen], -1); + iterations++; + } + else + { + break; + } + } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (iterations < maxTries)); - // Get required output buffer and retrieve info for real. - PIP_ADAPTER_ADDRESSES pAddrs = reinterpret_cast (buf); - if (::GetAdaptersAddresses (AF_INET6, 0, 0, pAddrs, &bufLen) != NO_ERROR) + if (dwRetVal != NO_ERROR) { - pAddrs = 0; + delete[] buf; + errno = EINVAL; + return -1; } while (pAddrs) @@ -819,14 +832,11 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, delete[] buf; // clean up -#endif /* ACE_WIN32 */ +#else /* ACE_WIN32 */ #ifndef ACE_LACKS_IF_NAMETOINDEX - if (lmreq.ipv6mr_interface == 0) - { - lmreq.ipv6mr_interface = ACE_OS::if_nametoindex (ACE_TEXT_ALWAYS_CHAR (net_if)); - } - + lmreq.ipv6mr_interface = ACE_OS::if_nametoindex(ACE_TEXT_ALWAYS_CHAR(net_if)); #endif /* ACE_LACKS_IF_NAMETOINDEX */ +#endif /* ACE_WIN32 */ if (lmreq.ipv6mr_interface == 0) { errno = EINVAL; diff --git a/ACE/ace/config-win32-common.h b/ACE/ace/config-win32-common.h index 31b3bffd3f94f..25dfff287497b 100644 --- a/ACE/ace/config-win32-common.h +++ b/ACE/ace/config-win32-common.h @@ -278,10 +278,6 @@ #define ACE_LACKS_GETIPNODEBYNAME_IPV6 #define ACE_LACKS_KILL #define ACE_LACKS_INET_ATON -#if _WIN32_WINNT < 0x0600 -# define ACE_LACKS_INET_NTOP -# define ACE_LACKS_INET_PTON -#endif #define ACE_LACKS_MADVISE #define ACE_LACKS_MKFIFO #define ACE_LACKS_MODE_MASKS @@ -566,6 +562,8 @@ # define ACE_HAS_WIN32_TRYLOCK #endif #if _WIN32_WINNT < 0x600 +# define ACE_LACKS_INET_NTOP +# define ACE_LACKS_INET_PTON # define ACE_LACKS_IF_NAMETOINDEX #endif #define ACE_LACKS_IF_NAMEINDEX From f5c406b5cf67fd86deacd54a76d98bdc552ff5ec Mon Sep 17 00:00:00 2001 From: Mike Kuznetsov Date: Wed, 23 Dec 2020 09:36:42 -0600 Subject: [PATCH 2/4] Removed trailing whitespace --- ACE/ace/SOCK_Dgram.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACE/ace/SOCK_Dgram.cpp b/ACE/ace/SOCK_Dgram.cpp index 0537ef32b3c53..0b6e0bbce09c7 100644 --- a/ACE/ace/SOCK_Dgram.cpp +++ b/ACE/ace/SOCK_Dgram.cpp @@ -802,7 +802,7 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, delete[] buf; ACE_NEW_RETURN(buf, char[bufLen], -1); iterations++; - } + } else { break; From 96c0e79c13f98142c0e04c88f4e2ec4bc22396d5 Mon Sep 17 00:00:00 2001 From: Mike Kuznetsov Date: Mon, 4 Jan 2021 11:53:44 -0600 Subject: [PATCH 3/4] Fixes as per PR#1352 review --- ACE/ace/SOCK_Dgram.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ACE/ace/SOCK_Dgram.cpp b/ACE/ace/SOCK_Dgram.cpp index 0b6e0bbce09c7..997bb9f66af91 100644 --- a/ACE/ace/SOCK_Dgram.cpp +++ b/ACE/ace/SOCK_Dgram.cpp @@ -787,8 +787,8 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, (if_ix = ACE_OS::atoi (net_if)) > 0; ULONG bufLen = 15000; // Initial size as per Microsoft - char* buf = 0; - ACE_NEW_RETURN(buf, char[bufLen], -1); + char *buf = 0; + ACE_NEW_RETURN (buf, char[bufLen], -1); DWORD dwRetVal = 0; ULONG iterations = 0; const ULONG maxTries = 3; @@ -796,18 +796,18 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, do { pAddrs = reinterpret_cast (buf); - dwRetVal = ::GetAdaptersAddresses(AF_INET6, 0, 0, pAddrs, &bufLen); + dwRetVal = ::GetAdaptersAddresses (AF_INET6, 0, 0, pAddrs, &bufLen); if (dwRetVal == ERROR_BUFFER_OVERFLOW) { delete[] buf; - ACE_NEW_RETURN(buf, char[bufLen], -1); - iterations++; + ACE_NEW_RETURN (buf, char[bufLen], -1); + ++iterations; } else { break; } - } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (iterations < maxTries)); + } while (dwRetVal == ERROR_BUFFER_OVERFLOW && iterations < maxTries); if (dwRetVal != NO_ERROR) { @@ -834,7 +834,7 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, #else /* ACE_WIN32 */ #ifndef ACE_LACKS_IF_NAMETOINDEX - lmreq.ipv6mr_interface = ACE_OS::if_nametoindex(ACE_TEXT_ALWAYS_CHAR(net_if)); + lmreq.ipv6mr_interface = ACE_OS::if_nametoindex (ACE_TEXT_ALWAYS_CHAR (net_if)); #endif /* ACE_LACKS_IF_NAMETOINDEX */ #endif /* ACE_WIN32 */ if (lmreq.ipv6mr_interface == 0) From eb4963c474759e86e6c621a5b240e708ec7af690 Mon Sep 17 00:00:00 2001 From: Mike Kuznetsov Date: Mon, 4 Jan 2021 15:11:53 -0600 Subject: [PATCH 4/4] Fixes as per PR#1352 review --- ACE/ace/SOCK_Dgram.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACE/ace/SOCK_Dgram.cpp b/ACE/ace/SOCK_Dgram.cpp index 997bb9f66af91..c858926541e77 100644 --- a/ACE/ace/SOCK_Dgram.cpp +++ b/ACE/ace/SOCK_Dgram.cpp @@ -791,7 +791,7 @@ ACE_SOCK_Dgram::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq, ACE_NEW_RETURN (buf, char[bufLen], -1); DWORD dwRetVal = 0; ULONG iterations = 0; - const ULONG maxTries = 3; + ULONG const maxTries = 3; PIP_ADAPTER_ADDRESSES pAddrs; do {