From 47f9256e83b93c507b7c8021e71cf17f1445ebbe Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 18 Nov 2024 22:06:16 -0600 Subject: [PATCH] NetPlay: Implement GetInterfaceListInternal for Windows. --- Source/Core/Core/NetPlayServer.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 0044ce903e..85f8c9c815 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -83,6 +83,10 @@ #include #endif #include +#else +#include +#include +#include #endif namespace NetPlay @@ -2314,7 +2318,32 @@ std::vector> NetPlayServer::GetInterfaceList { std::vector> result; #if defined(_WIN32) + ULONG buffer_size = 0; + GetAdaptersAddresses(AF_INET, 0, nullptr, nullptr, &buffer_size); + std::vector buffer(buffer_size); + auto* const adapters = reinterpret_cast(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(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.