Skip to content

Commit

Permalink
Merge pull request #1353 from kuznetsovmoci/IPv6_fixes
Browse files Browse the repository at this point in the history
Fixes for IPv6 on Windows
  • Loading branch information
mitza-oci authored Jan 7, 2021
2 parents a8ed6a2 + eb4963c commit 6ac2240
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
44 changes: 27 additions & 17 deletions ACE/ace/SOCK_Dgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions ACE/ace/config-win32-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,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
Expand Down Expand Up @@ -555,6 +551,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
Expand Down

0 comments on commit 6ac2240

Please sign in to comment.