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;
|
||||
|
||||
#ifdef _WIN32
|
||||
std::vector<u8> adapter_addresses(sizeof(IP_ADAPTER_ADDRESSES));
|
||||
ULONG size_infos = sizeof(IP_ADAPTER_ADDRESSES);
|
||||
ULONG flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER;
|
||||
ULONG family = AF_INET; // Only IPv4
|
||||
ULONG buffer_size = 15000;
|
||||
|
||||
if (GetAdaptersAddresses(AF_INET, 0, NULL,
|
||||
reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_addresses.data()),
|
||||
&size_infos) == ERROR_BUFFER_OVERFLOW)
|
||||
adapter_addresses.resize(size_infos);
|
||||
std::vector<BYTE> buffer(buffer_size);
|
||||
auto adapter_addresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data());
|
||||
|
||||
if (GetAdaptersAddresses(AF_INET, 0, NULL,
|
||||
reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_addresses.data()),
|
||||
&size_infos) == NO_ERROR &&
|
||||
size_infos) {
|
||||
PIP_ADAPTER_ADDRESSES adapter;
|
||||
for (adapter = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_addresses.data()); adapter;
|
||||
adapter = adapter->Next) {
|
||||
PIP_ADAPTER_UNICAST_ADDRESS unicast = adapter->FirstUnicastAddress;
|
||||
if (unicast) {
|
||||
DWORD result = GetAdaptersAddresses(family, flags, nullptr, adapter_addresses, &buffer_size);
|
||||
if (result == ERROR_BUFFER_OVERFLOW) {
|
||||
buffer.resize(buffer_size);
|
||||
adapter_addresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data());
|
||||
result = GetAdaptersAddresses(family, flags, nullptr, adapter_addresses, &buffer_size);
|
||||
}
|
||||
|
||||
if (result != NO_ERROR)
|
||||
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 mask = prefix_length == 0 ? 0 : 0xFFFFFFFF << (32 - prefix_length);
|
||||
in_addr addr{};
|
||||
addr.S_un.S_addr = htonl(mask);
|
||||
inet_ntop(AF_INET, &addr, netmaskStr, INET_ADDRSTRLEN);
|
||||
success = true;
|
||||
|
||||
in_addr mask_addr{};
|
||||
mask_addr.S_un.S_addr = htonl(mask);
|
||||
|
||||
if (inet_ntop(AF_INET, &mask_addr, netmaskStr, INET_ADDRSTRLEN)) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
ifaddrs* ifap;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue