forked from eden-emu/eden
android: Improve network gateway handling
This commit is contained in:
parent
d9c0ec8f83
commit
848fd4b34c
1 changed files with 20 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright yuzu/Citra Emulator Project / Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -117,6 +117,16 @@ std::vector<NetworkInterface> GetAvailableNetworkInterfaces() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
// On Android, we can't reliably get gateway info from /proc/net/route
|
||||||
|
// Just use 0 as the gateway address
|
||||||
|
result.emplace_back(NetworkInterface{
|
||||||
|
.name{ifa->ifa_name},
|
||||||
|
.ip_address{Common::BitCast<struct sockaddr_in>(*ifa->ifa_addr).sin_addr},
|
||||||
|
.subnet_mask{Common::BitCast<struct sockaddr_in>(*ifa->ifa_netmask).sin_addr},
|
||||||
|
.gateway{in_addr{.s_addr = 0}}
|
||||||
|
});
|
||||||
|
#else
|
||||||
u32 gateway{};
|
u32 gateway{};
|
||||||
|
|
||||||
std::ifstream file{"/proc/net/route"};
|
std::ifstream file{"/proc/net/route"};
|
||||||
|
@ -177,14 +187,14 @@ std::vector<NetworkInterface> GetAvailableNetworkInterfaces() {
|
||||||
.ip_address{Common::BitCast<struct sockaddr_in>(*ifa->ifa_addr).sin_addr},
|
.ip_address{Common::BitCast<struct sockaddr_in>(*ifa->ifa_addr).sin_addr},
|
||||||
.subnet_mask{Common::BitCast<struct sockaddr_in>(*ifa->ifa_netmask).sin_addr},
|
.subnet_mask{Common::BitCast<struct sockaddr_in>(*ifa->ifa_netmask).sin_addr},
|
||||||
.gateway{in_addr{.s_addr = gateway}}});
|
.gateway{in_addr{.s_addr = gateway}}});
|
||||||
|
#endif // ANDROID
|
||||||
}
|
}
|
||||||
|
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // _WIN32
|
||||||
|
|
||||||
std::optional<NetworkInterface> GetSelectedNetworkInterface() {
|
std::optional<NetworkInterface> GetSelectedNetworkInterface() {
|
||||||
const auto& selected_network_interface = Settings::values.network_interface.GetValue();
|
const auto& selected_network_interface = Settings::values.network_interface.GetValue();
|
||||||
|
@ -194,6 +204,12 @@ std::optional<NetworkInterface> GetSelectedNetworkInterface() {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
if (selected_network_interface.empty()) {
|
||||||
|
return network_interfaces[0];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const auto res =
|
const auto res =
|
||||||
std::ranges::find_if(network_interfaces, [&selected_network_interface](const auto& iface) {
|
std::ranges::find_if(network_interfaces, [&selected_network_interface](const auto& iface) {
|
||||||
return iface.name == selected_network_interface;
|
return iface.name == selected_network_interface;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue