Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetPlay: Implement GetInterfaceListInternal for Windows. #13192

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Source/Core/Core/NetPlayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
#include <ifaddrs.h>
#endif
#include <arpa/inet.h>
#else
#include <iphlpapi.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#endif

namespace NetPlay
Expand Down Expand Up @@ -2323,7 +2327,33 @@ 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());
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<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: {}", 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.
Expand Down