NetPlay: Implement GetInterfaceListInternal for Windows.

This commit is contained in:
Jordan Woyak 2024-11-18 22:06:16 -06:00
parent 0f2c2c7ae0
commit 47f9256e83
1 changed files with 29 additions and 0 deletions

View File

@ -83,6 +83,10 @@
#include <ifaddrs.h>
#endif
#include <arpa/inet.h>
#else
#include <iphlpapi.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
namespace NetPlay
@ -2314,7 +2318,32 @@ std::vector<std::pair<std::string, std::string>> NetPlayServer::GetInterfaceList
{
std::vector<std::pair<std::string, std::string>> result;
#if defined(_WIN32)
ULONG buffer_size = 0;
GetAdaptersAddresses(AF_INET, 0, nullptr, nullptr, &buffer_size);
std::vector<char> buffer(buffer_size);
auto* const adapters = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data());
if (GetAdaptersAddresses(AF_INET, 0, nullptr, adapters, &buffer_size) == NO_ERROR)
{
for (auto* adapter = adapters; adapter != nullptr; adapter = adapter->Next)
{
if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK)
continue;
auto* const unicast = adapter->FirstUnicastAddress;
if (!unicast)
continue;
char addr_str[INET_ADDRSTRLEN] = {};
inet_ntop(AF_INET, &reinterpret_cast<sockaddr_in*>(unicast->Address.lpSockaddr)->sin_addr,
addr_str, sizeof(addr_str));
result.emplace_back(WStringToUTF8(adapter->FriendlyName), addr_str);
}
}
else
{
WARN_LOG_FMT(NETPLAY, "GetAdaptersAddresses");
}
#elif defined(ANDROID)
// Android has no getifaddrs for some stupid reason. If this
// functionality ends up actually being used on Android, fix this.