Commit 074069b8 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wsdapi/tests: Call GetAdaptersAddresses() in a loop.

parent 1b83a376
...@@ -331,26 +331,34 @@ cleanup_addresses: ...@@ -331,26 +331,34 @@ cleanup_addresses:
freeaddrinfo(interfaceAddr); freeaddrinfo(interfaceAddr);
} }
static IP_ADAPTER_ADDRESSES *get_adapters( ULONG family )
{
ULONG err, size = 4096;
IP_ADAPTER_ADDRESSES *tmp, *ret;
if (!(ret = malloc( size ))) return NULL;
err = GetAdaptersAddresses( family, 0, NULL, ret, &size );
while (err == ERROR_BUFFER_OVERFLOW)
{
if (!(tmp = realloc( ret, size ))) break;
ret = tmp;
err = GetAdaptersAddresses( family, 0, NULL, ret, &size );
}
if (err == ERROR_SUCCESS) return ret;
free( ret );
return NULL;
}
static BOOL start_listening_on_all_addresses(messageStorage *msgStorage, ULONG family) static BOOL start_listening_on_all_addresses(messageStorage *msgStorage, ULONG family)
{ {
IP_ADAPTER_ADDRESSES *adapterAddresses = NULL, *adapterAddress; IP_ADAPTER_ADDRESSES *adapterAddresses, *adapterAddress;
ULONG bufferSize = 0;
LPSOCKADDR sockaddr; LPSOCKADDR sockaddr;
DWORD addressLength; DWORD addressLength;
char address[64]; char address[64];
BOOL ret = FALSE; BOOL ret = FALSE;
ULONG retVal;
retVal = GetAdaptersAddresses(family, 0, NULL, NULL, &bufferSize); /* family should be AF_INET or AF_INET6 */
if (retVal != ERROR_BUFFER_OVERFLOW) goto cleanup;
/* Get size of buffer for adapters */
adapterAddresses = malloc(bufferSize);
if (adapterAddresses == NULL) goto cleanup;
/* Get list of adapters */ adapterAddresses = get_adapters(family); /* family should be AF_INET or AF_INET6 */
retVal = GetAdaptersAddresses(family, 0, NULL, adapterAddresses, &bufferSize); if (!adapterAddresses) return FALSE;
if (retVal != ERROR_SUCCESS) goto cleanup;
for (adapterAddress = adapterAddresses; adapterAddress != NULL; adapterAddress = adapterAddress->Next) for (adapterAddress = adapterAddresses; adapterAddress != NULL; adapterAddress = adapterAddress->Next)
{ {
...@@ -378,14 +386,11 @@ cleanup: ...@@ -378,14 +386,11 @@ cleanup:
static BOOL send_udp_multicast_of_type(const char *data, int length, ULONG family) static BOOL send_udp_multicast_of_type(const char *data, int length, ULONG family)
{ {
IP_ADAPTER_ADDRESSES *adapter_addresses = NULL, *adapter_addr; IP_ADAPTER_ADDRESSES *adapter_addresses, *adapter_addr;
static const struct in6_addr i_addr_zero; static const struct in6_addr i_addr_zero;
struct addrinfo *multi_address; struct addrinfo *multi_address;
ULONG bufferSize = 0;
LPSOCKADDR sockaddr; LPSOCKADDR sockaddr;
BOOL ret = FALSE;
const char ttl = 8; const char ttl = 8;
ULONG retval;
SOCKET s; SOCKET s;
/* Resolve the multicast address */ /* Resolve the multicast address */
...@@ -397,16 +402,8 @@ static BOOL send_udp_multicast_of_type(const char *data, int length, ULONG famil ...@@ -397,16 +402,8 @@ static BOOL send_udp_multicast_of_type(const char *data, int length, ULONG famil
if (multi_address == NULL) if (multi_address == NULL)
return FALSE; return FALSE;
/* Get size of buffer for adapters */ adapter_addresses = get_adapters(family);
retval = GetAdaptersAddresses(family, 0, NULL, NULL, &bufferSize); if (!adapter_addresses) return FALSE;
if (retval != ERROR_BUFFER_OVERFLOW) goto cleanup;
adapter_addresses = malloc(bufferSize);
if (adapter_addresses == NULL) goto cleanup;
/* Get list of adapters */
retval = GetAdaptersAddresses(family, 0, NULL, adapter_addresses, &bufferSize);
if (retval != ERROR_SUCCESS) goto cleanup;
for (adapter_addr = adapter_addresses; adapter_addr != NULL; adapter_addr = adapter_addr->Next) for (adapter_addr = adapter_addresses; adapter_addr != NULL; adapter_addr = adapter_addr->Next)
{ {
...@@ -433,12 +430,9 @@ static BOOL send_udp_multicast_of_type(const char *data, int length, ULONG famil ...@@ -433,12 +430,9 @@ static BOOL send_udp_multicast_of_type(const char *data, int length, ULONG famil
closesocket(s); closesocket(s);
} }
ret = TRUE;
cleanup:
freeaddrinfo(multi_address); freeaddrinfo(multi_address);
free(adapter_addresses); free(adapter_addresses);
return ret; return TRUE;
} }
typedef struct IWSDiscoveryPublisherNotifyImpl { typedef struct IWSDiscoveryPublisherNotifyImpl {
......
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