Make use of address candidates in Hotspot credentials.

PiperOrigin-RevId: 830572287
This commit is contained in:
Francis Tsui
2025-11-10 13:17:43 -08:00
committed by Copybara-Service
parent 35a42d4d31
commit e49fe76dc5
16 changed files with 316 additions and 112 deletions
@@ -29,7 +29,6 @@
#include "internal/platform/cancellation_flag_listener.h"
#include "internal/platform/exception.h"
#include "internal/platform/implementation/wifi_hotspot.h"
#include "internal/platform/implementation/wifi_utils.h"
#include "internal/platform/logging.h"
#include "internal/platform/medium_environment.h"
#include "internal/platform/prng.h"
@@ -219,9 +218,8 @@ std::unique_ptr<api::WifiHotspotSocket> WifiHotspotMedium::ConnectToService(
// First, find an instance of remote medium, that exposed this service.
auto& env = MediumEnvironment::Instance();
auto* remote_medium = static_cast<WifiHotspotMedium*>(
env.GetWifiHotspotMedium({}, WifiUtils::GetHumanReadableIpAddress(
{service_address.address.data(),
service_address.address.size()})));
env.GetWifiHotspotMedium({}, std::string(service_address.address.begin(),
service_address.address.end())));
if (remote_medium == nullptr) {
return {};
}
@@ -15,6 +15,7 @@
#include <windows.h>
#include <cstdint>
#include <cstring>
#include <exception>
#include <memory>
#include <string>
@@ -86,8 +87,18 @@ void WifiHotspotServerSocket::PopulateHotspotCredentials(
"addresses configured on computer.";
return;
}
hotspot_credentials.SetGateway(hotspot_ipaddr);
hotspot_credentials.SetPort(GetPort());
std::vector<char> hotspot_ipaddr_bytes;
uint32_t address_int = inet_addr(hotspot_ipaddr.c_str());
if (address_int != INADDR_NONE) {
hotspot_ipaddr_bytes.resize(4);
std::memcpy(hotspot_ipaddr_bytes.data(),
reinterpret_cast<char*>(&address_int), 4);
}
ServiceAddress service_address = {
.address = hotspot_ipaddr_bytes,
.port = static_cast<uint16_t>(GetPort()),
};
hotspot_credentials.SetAddressCandidates({service_address});
}
bool WifiHotspotServerSocket::Listen(int port, bool dual_stack) {