From 70bcabb1618c64f67dc090158fad048faa5310e6 Mon Sep 17 00:00:00 2001 From: Anay Wadhera Date: Mon, 24 Apr 2023 12:27:10 -0700 Subject: [PATCH] update port length to 2 bytes PiperOrigin-RevId: 526722524 --- internal/platform/connection_info_test.cc | 2 +- internal/platform/wifi_lan_connection_info.h | 11 +++++++---- internal/platform/wifi_lan_connection_info_test.cc | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/platform/connection_info_test.cc b/internal/platform/connection_info_test.cc index ed8f9bab..caae8034 100644 --- a/internal/platform/connection_info_test.cc +++ b/internal/platform/connection_info_test.cc @@ -36,7 +36,7 @@ constexpr char kAction = 0x0F; constexpr absl::string_view kBluetoothUuid{"test"}; // WLAN constexpr absl::string_view kIpv4Addr = "\x4C\x8B\x1D\xCE"; -constexpr absl::string_view kPort = "\x12\x34\x56\x78"; +constexpr absl::string_view kPort = "\x12\x34"; constexpr absl::string_view kBssid = "\x0A\x1B\x2C\x34\x58\x7E"; TEST(ConnectionInfoTest, TestRestoreBle) { diff --git a/internal/platform/wifi_lan_connection_info.h b/internal/platform/wifi_lan_connection_info.h index a31bf6b2..46a14a2c 100644 --- a/internal/platform/wifi_lan_connection_info.h +++ b/internal/platform/wifi_lan_connection_info.h @@ -25,10 +25,10 @@ namespace nearby { -constexpr int kIpv4AddressLength = 4; -constexpr int kIpv6AddressLength = 16; -constexpr int kPortLength = 4; -constexpr int kBssidLength = 6; +inline constexpr int kIpv4AddressLength = 4; +inline constexpr int kIpv6AddressLength = 16; +inline constexpr int kPortLength = 2; +inline constexpr int kBssidLength = 6; class WifiLanConnectionInfo : public ConnectionInfo { public: @@ -51,6 +51,9 @@ class WifiLanConnectionInfo : public ConnectionInfo { } std::string ToDataElementBytes() const override; std::string GetIpAddress() const { return ip_address_; } + // This port is expected to be in hex form, such as \xFF\xFF for a value of + // 65535, 2 bytes in length. This field will be represented in network byte + // order (aka big-endian), so \x12\x34 will correspond to port 4660 (0x1234). std::string GetPort() const { return port_; } std::string GetBssid() const { return bssid_; } char GetActions() const override { return actions_; } diff --git a/internal/platform/wifi_lan_connection_info_test.cc b/internal/platform/wifi_lan_connection_info_test.cc index 817e47ff..d35b5cdd 100644 --- a/internal/platform/wifi_lan_connection_info_test.cc +++ b/internal/platform/wifi_lan_connection_info_test.cc @@ -30,7 +30,7 @@ namespace { constexpr absl::string_view kIpv4Addr = "\x4C\x8B\x1D\xCE"; constexpr absl::string_view kIpv6Addr = "\x4C\x8B\x1D\xCE\x4C\x8B\x1D\xCE\x4C\x8B\x1D\xCE\x4C\x8B\x1D\xCE"; -constexpr absl::string_view kPort = "\x12\x34\x56\x78"; +constexpr absl::string_view kPort = "\x12\x34"; constexpr absl::string_view kBssid = "\x0A\x1B\x2C\x34\x58\x7E"; constexpr char kAction = 0x0F;