mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
When calling GetIpAddress() before GetInformation(), it will fail to get right IP Address.
PiperOrigin-RevId: 489261279
This commit is contained in:
@@ -15,9 +15,9 @@
|
||||
#ifndef PLATFORM_IMPL_WINDOWS_WIFI_H_
|
||||
#define PLATFORM_IMPL_WINDOWS_WIFI_H_
|
||||
|
||||
#include <objbase.h>
|
||||
#include <windows.h>
|
||||
#include <wlanapi.h>
|
||||
#include <objbase.h>
|
||||
#include <wtypes.h>
|
||||
|
||||
// Nearby connections headers
|
||||
@@ -25,8 +25,8 @@
|
||||
#include "internal/platform/wifi_utils.h"
|
||||
|
||||
// WinRT headers
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.h"
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Collections.h"
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.h"
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Connectivity.h"
|
||||
|
||||
namespace location {
|
||||
@@ -117,6 +117,7 @@ class WifiMedium : public api::WifiMedium {
|
||||
// Since the WiFi interface capability won't change in the connection session,
|
||||
// we only need to query it once at the beginning
|
||||
void InitCapability();
|
||||
std::string InternalGetIpAddress();
|
||||
|
||||
bool wifi_interface_valid_;
|
||||
api::WifiCapability wifi_capability_;
|
||||
|
||||
@@ -194,7 +194,7 @@ api::WifiInformation& WifiMedium::GetInformation() {
|
||||
p_intf_list = NULL;
|
||||
WlanCloseHandle(client_handle, NULL);
|
||||
|
||||
wifi_information_.ip_address_dot_decimal = GetIpAddress();
|
||||
wifi_information_.ip_address_dot_decimal = InternalGetIpAddress();
|
||||
if (!wifi_information_.ip_address_dot_decimal.empty()) {
|
||||
wifi_information_.ip_address_4_bytes = ipaddr_dotdecimal_to_4bytes_string(
|
||||
wifi_information_.ip_address_dot_decimal);
|
||||
@@ -204,6 +204,11 @@ api::WifiInformation& WifiMedium::GetInformation() {
|
||||
}
|
||||
|
||||
std::string WifiMedium::GetIpAddress() {
|
||||
GetInformation();
|
||||
return wifi_information_.ip_address_dot_decimal;
|
||||
}
|
||||
|
||||
std::string WifiMedium::InternalGetIpAddress() {
|
||||
try {
|
||||
auto host_names = NetworkInformation::GetHostNames();
|
||||
for (auto host_name : host_names) {
|
||||
|
||||
Reference in New Issue
Block a user