From faecdcc20571b60f16c6857376e348b5626265e3 Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Mon, 6 Oct 2025 10:23:26 -0700 Subject: [PATCH] Remove EnableIpAddressesNative flag. PiperOrigin-RevId: 815783697 --- .../platform/implementation/windows/utils.cc | 80 +------------------ .../platform/implementation/windows/utils.h | 1 - 2 files changed, 4 insertions(+), 77 deletions(-) diff --git a/internal/platform/implementation/windows/utils.cc b/internal/platform/implementation/windows/utils.cc index 036f75ef..c4f0a331 100644 --- a/internal/platform/implementation/windows/utils.cc +++ b/internal/platform/implementation/windows/utils.cc @@ -24,7 +24,6 @@ // Standard C/C++ headers #include #include -#include #include #include #include @@ -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& wifi_addresses, - std::vector& ethernet_addresses, - std::vector& 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& 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 Get4BytesIpv4Addresses() { - std::vector result; - std::vector 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& wifi_addresses, std::vector& ethernet_addresses, std::vector& 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 GetIpv4Addresses() { @@ -431,5 +360,4 @@ std::optional GetDnsHostName() { return std::nullopt; } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/utils.h b/internal/platform/implementation/windows/utils.h index d3d79bfe..6dbb7e7a 100644 --- a/internal/platform/implementation/windows/utils.h +++ b/internal/platform/implementation/windows/utils.h @@ -42,7 +42,6 @@ ByteArray Sha256(absl::string_view input, size_t size); // Reads the IPv4 addresses std::vector GetIpv4Addresses(); -std::vector Get4BytesIpv4Addresses(); std::vector GetWifiIpv4Addresses(); void GetIpv4Addresses(std::vector& wifi_addresses, std::vector& ethernet_addresses,