mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-11 02:28:39 +00:00
fixed RetrieveNetmask for windows (#3338)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
* fixed RetrieveNetmask for windows * clang..
This commit is contained in:
parent
e3fe6e2809
commit
df85efde7c
1 changed files with 30 additions and 20 deletions
|
@ -262,33 +262,43 @@ bool NetUtilInternal::RetrieveNetmask() {
|
||||||
auto success = false;
|
auto success = false;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::vector<u8> adapter_addresses(sizeof(IP_ADAPTER_ADDRESSES));
|
ULONG flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER;
|
||||||
ULONG size_infos = sizeof(IP_ADAPTER_ADDRESSES);
|
ULONG family = AF_INET; // Only IPv4
|
||||||
|
ULONG buffer_size = 15000;
|
||||||
|
|
||||||
if (GetAdaptersAddresses(AF_INET, 0, NULL,
|
std::vector<BYTE> buffer(buffer_size);
|
||||||
reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_addresses.data()),
|
auto adapter_addresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data());
|
||||||
&size_infos) == ERROR_BUFFER_OVERFLOW)
|
|
||||||
adapter_addresses.resize(size_infos);
|
|
||||||
|
|
||||||
if (GetAdaptersAddresses(AF_INET, 0, NULL,
|
DWORD result = GetAdaptersAddresses(family, flags, nullptr, adapter_addresses, &buffer_size);
|
||||||
reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_addresses.data()),
|
if (result == ERROR_BUFFER_OVERFLOW) {
|
||||||
&size_infos) == NO_ERROR &&
|
buffer.resize(buffer_size);
|
||||||
size_infos) {
|
adapter_addresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data());
|
||||||
PIP_ADAPTER_ADDRESSES adapter;
|
result = GetAdaptersAddresses(family, flags, nullptr, adapter_addresses, &buffer_size);
|
||||||
for (adapter = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_addresses.data()); adapter;
|
}
|
||||||
adapter = adapter->Next) {
|
|
||||||
PIP_ADAPTER_UNICAST_ADDRESS unicast = adapter->FirstUnicastAddress;
|
if (result != NO_ERROR)
|
||||||
if (unicast) {
|
return false;
|
||||||
|
|
||||||
|
for (auto adapter = adapter_addresses; adapter != nullptr; adapter = adapter->Next) {
|
||||||
|
// Skip loopback and down interfaces
|
||||||
|
if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK || adapter->OperStatus != IfOperStatusUp)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (auto unicast = adapter->FirstUnicastAddress; unicast != nullptr;
|
||||||
|
unicast = unicast->Next) {
|
||||||
|
if (unicast->Address.lpSockaddr->sa_family == AF_INET) {
|
||||||
ULONG prefix_length = unicast->OnLinkPrefixLength;
|
ULONG prefix_length = unicast->OnLinkPrefixLength;
|
||||||
ULONG mask = prefix_length == 0 ? 0 : 0xFFFFFFFF << (32 - prefix_length);
|
ULONG mask = prefix_length == 0 ? 0 : 0xFFFFFFFF << (32 - prefix_length);
|
||||||
in_addr addr{};
|
|
||||||
addr.S_un.S_addr = htonl(mask);
|
in_addr mask_addr{};
|
||||||
inet_ntop(AF_INET, &addr, netmaskStr, INET_ADDRSTRLEN);
|
mask_addr.S_un.S_addr = htonl(mask);
|
||||||
success = true;
|
|
||||||
|
if (inet_ntop(AF_INET, &mask_addr, netmaskStr, INET_ADDRSTRLEN)) {
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
ifaddrs* ifap;
|
ifaddrs* ifap;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue