mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Remove EnableIpAddressesNative flag.
PiperOrigin-RevId: 815783697
This commit is contained in:
committed by
Copybara-Service
parent
cce45b745e
commit
faecdcc205
@@ -24,7 +24,6 @@
|
||||
// Standard C/C++ headers
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -32,9 +31,7 @@
|
||||
|
||||
// Nearby connections headers
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/crypto.h"
|
||||
#include "internal/platform/implementation/windows/string_utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -43,52 +40,9 @@
|
||||
#include "winrt/Windows.Networking.Connectivity.h"
|
||||
#include "winrt/base.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
namespace nearby::windows {
|
||||
namespace {
|
||||
|
||||
using ::winrt::Windows::Networking::HostNameType;
|
||||
using ::winrt::Windows::Networking::Connectivity::NetworkAdapter;
|
||||
using ::winrt::Windows::Networking::Connectivity::NetworkInformation;
|
||||
using ::winrt::Windows::Networking::Connectivity::NetworkTypes;
|
||||
|
||||
void GetIpv4AddressesWinRT(std::vector<std::string>& wifi_addresses,
|
||||
std::vector<std::string>& ethernet_addresses,
|
||||
std::vector<std::string>& other_addresses) {
|
||||
try {
|
||||
auto host_names = NetworkInformation::GetHostNames();
|
||||
for (const auto& host_name : host_names) {
|
||||
VLOG(1) << "host_name: " << winrt::to_string(host_name.ToString());
|
||||
if (host_name.IPInformation() != nullptr &&
|
||||
host_name.IPInformation().NetworkAdapter() != nullptr &&
|
||||
host_name.Type() == HostNameType::Ipv4) {
|
||||
NetworkAdapter adapter = host_name.IPInformation().NetworkAdapter();
|
||||
if (adapter.NetworkItem().GetNetworkTypes() == NetworkTypes::None) {
|
||||
// If we're not connected to a network, we don't want to add this
|
||||
// address.
|
||||
continue;
|
||||
}
|
||||
if (adapter.IanaInterfaceType() == Constants::kInterfaceTypeWifi) {
|
||||
wifi_addresses.push_back(winrt::to_string(host_name.ToString()));
|
||||
} else if (adapter.IanaInterfaceType() ==
|
||||
Constants::kInterfaceTypeEthernet) {
|
||||
ethernet_addresses.push_back(winrt::to_string(host_name.ToString()));
|
||||
} else {
|
||||
other_addresses.push_back(winrt::to_string(host_name.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (std::exception exception) {
|
||||
LOG(ERROR) << __func__ << ": Cannot get IPv4 addresses. Exception : "
|
||||
<< exception.what();
|
||||
} catch (const winrt::hresult_error& error) {
|
||||
LOG(ERROR) << __func__ << ": Cannot get IPv4 addresses. WinRT exception: "
|
||||
<< error.code() << ": " << winrt::to_string(error.message());
|
||||
} catch (...) {
|
||||
LOG(ERROR) << __func__ << ": Unknown exception.";
|
||||
}
|
||||
}
|
||||
|
||||
void AddIpUnicastAddresses(IP_ADAPTER_UNICAST_ADDRESS* unicast_addresses,
|
||||
std::vector<std::string>& addresses) {
|
||||
std::string address;
|
||||
@@ -203,36 +157,11 @@ std::string ipaddr_dotdecimal_to_4bytes_string(std::string ipv4_s) {
|
||||
return std::string(ipv4_b, 4);
|
||||
}
|
||||
|
||||
std::vector<std::string> Get4BytesIpv4Addresses() {
|
||||
std::vector<std::string> result;
|
||||
std::vector<std::string> ipv4_addresses = GetIpv4Addresses();
|
||||
for (const auto& ipv4_address : ipv4_addresses) {
|
||||
// Converts IP address from x.x.x.x to 4 bytes format.
|
||||
in_addr address;
|
||||
address.S_un.S_addr = inet_addr(ipv4_address.c_str());
|
||||
std::string ipv4_4bytes_address;
|
||||
ipv4_4bytes_address.resize(4);
|
||||
ipv4_4bytes_address[0] = address.S_un.S_un_b.s_b1;
|
||||
ipv4_4bytes_address[1] = address.S_un.S_un_b.s_b2;
|
||||
ipv4_4bytes_address[2] = address.S_un.S_un_b.s_b3;
|
||||
ipv4_4bytes_address[3] = address.S_un.S_un_b.s_b4;
|
||||
result.push_back(ipv4_4bytes_address);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void GetIpv4Addresses(std::vector<std::string>& wifi_addresses,
|
||||
std::vector<std::string>& ethernet_addresses,
|
||||
std::vector<std::string>& other_addresses) {
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableIpAddressesNative)) {
|
||||
GetIpAddressesNative(AF_INET, wifi_addresses, ethernet_addresses,
|
||||
other_addresses);
|
||||
} else {
|
||||
GetIpv4AddressesWinRT(wifi_addresses, ethernet_addresses, other_addresses);
|
||||
}
|
||||
GetIpAddressesNative(AF_INET, wifi_addresses, ethernet_addresses,
|
||||
other_addresses);
|
||||
}
|
||||
|
||||
std::vector<std::string> GetIpv4Addresses() {
|
||||
@@ -431,5 +360,4 @@ std::optional<std::wstring> GetDnsHostName() {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
} // namespace nearby::windows
|
||||
|
||||
@@ -42,7 +42,6 @@ ByteArray Sha256(absl::string_view input, size_t size);
|
||||
|
||||
// Reads the IPv4 addresses
|
||||
std::vector<std::string> GetIpv4Addresses();
|
||||
std::vector<std::string> Get4BytesIpv4Addresses();
|
||||
std::vector<std::string> GetWifiIpv4Addresses();
|
||||
void GetIpv4Addresses(std::vector<std::string>& wifi_addresses,
|
||||
std::vector<std::string>& ethernet_addresses,
|
||||
|
||||
Reference in New Issue
Block a user