summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Mitz <mitza@objectcomputing.com>2021-01-05 08:51:46 -0600
committerGitHub <noreply@github.com>2021-01-05 08:51:46 -0600
commita43b786edefd6ec11df656d918d16777da08f782 (patch)
tree8937077f7f8f83826f1bc0a9154cfb3256e4764b
parentf1733f33df42f11ceade9575a010cc5a0495a8af (diff)
parenteb4963c474759e86e6c621a5b240e708ec7af690 (diff)
downloadATCD-a43b786edefd6ec11df656d918d16777da08f782.tar.gz
Merge pull request #1352 from kuznetsovmoci/IPv6_fixes
[ACE6] Fixes for IPv6 multicast and inet_ntop/inet_pton on Windows
-rw-r--r--ACE/ace/SOCK_Dgram.cpp44
-rw-r--r--ACE/ace/config-win32-common.h6
2 files changed, 29 insertions, 21 deletions
diff --git a/ACE/ace/SOCK_Dgram.cpp b/ACE/ace/SOCK_Dgram.cpp
index c67fe8c58ba..c858926541e 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;
+ ULONG bufLen = 15000; // Initial size as per Microsoft
char *buf = 0;
- if (::GetAdaptersAddresses (AF_INET6, 0, 0, &tmp_addrs, &bufLen)
- == ERROR_BUFFER_OVERFLOW)
+ ACE_NEW_RETURN (buf, char[bufLen], -1);
+ DWORD dwRetVal = 0;
+ ULONG iterations = 0;
+ ULONG const maxTries = 3;
+ PIP_ADAPTER_ADDRESSES pAddrs;
+ do
{
- ACE_NEW_RETURN (buf, char[bufLen], -1);
- }
+ pAddrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES> (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<PIP_ADAPTER_ADDRESSES> (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 31b3bffd3f9..25dfff28749 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