From 0622263362b329e647e3b6f5afe6f699424025d6 Mon Sep 17 00:00:00 2001 From: Jingwei Zhang Date: Fri, 25 Oct 2019 10:16:11 +0800 Subject: [PATCH 1/2] Bug Fix: Failed to connect lidar when multi adapter presented with first one disconnected Bug Description: When you have more than one network adater on your compter, this part of the code is supposed to find one that is connecting and working fine and obtain its ip address for handshaking request. However, it failed to do so when the first network adapter is not connected. Thus GetAdapterState returns false and we stopped trying on the other adapters. Fix: Try each adapter, if it is not working, we try the next one. Either we find one and we move onto the following process or we find none and quit. --- sdk_core/src/base/network_util.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sdk_core/src/base/network_util.cpp b/sdk_core/src/base/network_util.cpp index c3a8f16..4041ee4 100644 --- a/sdk_core/src/base/network_util.cpp +++ b/sdk_core/src/base/network_util.cpp @@ -99,20 +99,23 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) { IP_ADAPTER_INFO *pAdapter = reinterpret_cast(pAdapterInfo.get()); if (NO_ERROR == dlRetVal && pAdapter != NULL) { - while (GetAdapterState(pAdapter)) { - std::string str_ip = pAdapter->IpAddressList.IpAddress.String; - std::string str_mask = pAdapter->IpAddressList.IpMask.String; - ULONG host_ip = inet_addr(const_cast(str_ip.c_str())); - ULONG host_mask = inet_addr(const_cast(str_mask.c_str())); + while (pAdapter != NULL) { + if (GetAdapterState(pAdapter)) { + std::string str_ip = pAdapter->IpAddressList.IpAddress.String; + std::string str_mask = pAdapter->IpAddressList.IpMask.String; + ULONG host_ip = inet_addr(const_cast(str_ip.c_str())); + ULONG host_mask = inet_addr(const_cast(str_mask.c_str())); - if ((host_ip & host_mask) == - (client_addr.sin_addr.S_un.S_addr & host_mask)) { - local_ip = host_ip; - found = true; - break; - } - pAdapter = pAdapter->Next; - } + if ((host_ip & host_mask) == + (client_addr.sin_addr.S_un.S_addr & host_mask)) { + local_ip = host_ip; + found = true; + break; + } + } + + pAdapter = pAdapter->Next; + } } return found; } From 46331941a9f4f32bd9081dec446a122f59a5663d Mon Sep 17 00:00:00 2001 From: jingweiz2017 Date: Fri, 25 Oct 2019 10:49:02 +0800 Subject: [PATCH 2/2] Update network_util.cpp Adjust the indentation. --- sdk_core/src/base/network_util.cpp | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/sdk_core/src/base/network_util.cpp b/sdk_core/src/base/network_util.cpp index 4041ee4..799b97d 100644 --- a/sdk_core/src/base/network_util.cpp +++ b/sdk_core/src/base/network_util.cpp @@ -99,24 +99,25 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) { IP_ADAPTER_INFO *pAdapter = reinterpret_cast(pAdapterInfo.get()); if (NO_ERROR == dlRetVal && pAdapter != NULL) { - while (pAdapter != NULL) { - if (GetAdapterState(pAdapter)) { - std::string str_ip = pAdapter->IpAddressList.IpAddress.String; - std::string str_mask = pAdapter->IpAddressList.IpMask.String; - ULONG host_ip = inet_addr(const_cast(str_ip.c_str())); - ULONG host_mask = inet_addr(const_cast(str_mask.c_str())); + while (pAdapter != NULL) { + if (GetAdapterState(pAdapter)) { + std::string str_ip = pAdapter->IpAddressList.IpAddress.String; + std::string str_mask = pAdapter->IpAddressList.IpMask.String; + ULONG host_ip = inet_addr(const_cast(str_ip.c_str())); + ULONG host_mask = inet_addr(const_cast(str_mask.c_str())); - if ((host_ip & host_mask) == - (client_addr.sin_addr.S_un.S_addr & host_mask)) { - local_ip = host_ip; - found = true; - break; - } - } + if ((host_ip & host_mask) == + (client_addr.sin_addr.S_un.S_addr & host_mask)) { + local_ip = host_ip; + found = true; + break; + } + } - pAdapter = pAdapter->Next; - } + pAdapter = pAdapter->Next; + } } + return found; } #else @@ -152,4 +153,4 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) { } #endif } // namespace util -} // namespace livox \ No newline at end of file +} // namespace livox