diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/network/core/host.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp index 14fe4f303..7b7f22784 100644 --- a/src/network/core/host.cpp +++ b/src/network/core/host.cpp @@ -112,11 +112,18 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi if (sock == INVALID_SOCKET) return; DWORD len = 0; - INTERFACE_INFO *ifo = AllocaM(INTERFACE_INFO, limit); - memset(ifo, 0, limit * sizeof(*ifo)); - if ((WSAIoctl(sock, SIO_GET_INTERFACE_LIST, NULL, 0, &ifo[0], limit * sizeof(*ifo), &len, NULL, NULL)) != 0) { - closesocket(sock); - return; + int num = 2; + INTERFACE_INFO *ifo = CallocT<INTERFACE_INFO>(num); + + for(;;) { + if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, NULL, 0, ifo, num * sizeof(*ifo), &len, NULL, NULL) == 0) break; + free(ifo); + if (WSAGetLastError() != WSAEFAULT) { + closesocket(sock); + return; + } + num *= 2; + ifo = CallocT<INTERFACE_INFO>(num); } for (uint j = 0; j < len / sizeof(*ifo); j++) { @@ -131,6 +138,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi *broadcast->Append() = NetworkAddress(address, sizeof(sockaddr)); } + free(ifo); closesocket(sock); } |