Merge pull request #9191 from sepalani/net-interface

IP/Top: Add Android network interface
This commit is contained in:
Léo Lam
2020-11-28 18:22:33 +01:00
committed by GitHub
7 changed files with 204 additions and 2 deletions

View File

@ -50,6 +50,10 @@
#include <unistd.h>
#endif
#ifdef __ANDROID__
#include "jni/AndroidCommon/AndroidCommon.h"
#endif
namespace IOS::HLE::Device
{
enum SOResultCode : s32
@ -217,7 +221,14 @@ static std::optional<DefaultInterface> GetSystemDefaultInterface()
return DefaultInterface{entry.dwAddr, entry.dwMask, entry.dwBCastAddr};
}
}
#elif !defined(__ANDROID__)
#elif defined(__ANDROID__)
const u32 addr = GetNetworkIpAddress();
const u32 prefix_length = GetNetworkPrefixLength();
const u32 netmask = (1 << prefix_length) - 1;
const u32 gateway = GetNetworkGateway();
if (addr || netmask || gateway)
return DefaultInterface{addr, netmask, gateway};
#else
// Assume that the address that is used to access the Internet corresponds
// to the default interface.
auto get_default_address = []() -> std::optional<in_addr> {
@ -261,7 +272,7 @@ static std::optional<DefaultInterface> GetSystemDefaultInterface()
}
}
#endif
return {};
return std::nullopt;
}
static DefaultInterface GetSystemDefaultInterfaceOrFallback()