mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-06-01 12:15:13 -06:00
Merge c4c7165c4f into b9b46ecb65
This commit is contained in:
commit
3c550491c1
@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#if BOOST_OS_WINDOWS
|
#if BOOST_OS_WINDOWS
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
|
#elif BOOST_OS_LINUX
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <net/if.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// AC lib (manages internet connection)
|
// AC lib (manages internet connection)
|
||||||
@ -81,6 +84,37 @@ void _GetLocalIPAndSubnetMask(uint32& localIp, uint32& subnetMask)
|
|||||||
cemuLog_logDebug(LogType::Force, "_GetLocalIPAndSubnetMask(): Failed to find network IP and subnet mask");
|
cemuLog_logDebug(LogType::Force, "_GetLocalIPAndSubnetMask(): Failed to find network IP and subnet mask");
|
||||||
_GetLocalIPAndSubnetMaskFallback(localIp, subnetMask);
|
_GetLocalIPAndSubnetMaskFallback(localIp, subnetMask);
|
||||||
}
|
}
|
||||||
|
#elif BOOST_OS_LINUX
|
||||||
|
void _GetLocalIPAndSubnetMask(uint32& localIp, uint32& subnetMask)
|
||||||
|
{
|
||||||
|
struct ifaddrs *ifaddr;
|
||||||
|
if (getifaddrs(&ifaddr) == -1)
|
||||||
|
{
|
||||||
|
cemuLog_log(LogType::Force, "Failed to acquire local IP and subnet mask");
|
||||||
|
_GetLocalIPAndSubnetMaskFallback(localIp, subnetMask);
|
||||||
|
}
|
||||||
|
stdx::scope_exit _ifa([&]{ freeifaddrs(ifaddr); });
|
||||||
|
|
||||||
|
for (const struct ifaddrs* ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next)
|
||||||
|
{
|
||||||
|
if (ifa->ifa_addr == nullptr || ifa->ifa_addr->sa_family != AF_INET)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(ifa->ifa_flags & IFF_UP) || !(ifa->ifa_flags & IFF_RUNNING))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ifa->ifa_flags & IFF_LOOPBACK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto* addr_in = reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr);
|
||||||
|
localIp = ntohl(addr_in->sin_addr.s_addr);
|
||||||
|
const auto* mask_in = reinterpret_cast<struct sockaddr_in*>(ifa->ifa_netmask);
|
||||||
|
subnetMask = ntohl(mask_in->sin_addr.s_addr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cemuLog_logDebug(LogType::Force, "_GetLocalIPAndSubnetMask(): Failed to find network IP and subnet mask");
|
||||||
|
_GetLocalIPAndSubnetMaskFallback(localIp, subnetMask);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
void _GetLocalIPAndSubnetMask(uint32& localIp, uint32& subnetMask)
|
void _GetLocalIPAndSubnetMask(uint32& localIp, uint32& subnetMask)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user