From 3b856530031aff08567f0c2373f61b6324c327c4 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 77a52e814b..cf21adfdc4 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -84,6 +84,10 @@ #include #endif #include +#else +#include +#include +#include #endif namespace NetPlay @@ -2323,7 +2327,33 @@ 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()); + const ULONG adapters_result = GetAdaptersAddresses(AF_INET, 0, nullptr, adapters, &buffer_size); + if (adapters_result == 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: {}", adapters_result); + } #elif defined(ANDROID) // Android has no getifaddrs for some stupid reason. If this // functionality ends up actually being used on Android, fix this.