fix : failed to find local ip in windows
This commit is contained in:
@@ -65,7 +65,28 @@ apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool nonbloc
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
|
bool GetAdapterState(const IP_ADAPTER_INFO *pAdapter)
|
||||||
|
{
|
||||||
|
if(pAdapter == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MIB_IFROW info;
|
||||||
|
memset(&info ,0 ,sizeof(MIB_IFROW));
|
||||||
|
info.dwIndex = pAdapter->Index;
|
||||||
|
if (GetIfEntry(&info) != NOERROR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (info.dwOperStatus == IF_OPER_STATUS_NON_OPERATIONAL
|
||||||
|
|| info.dwOperStatus == IF_OPER_STATUS_UNREACHABLE
|
||||||
|
|| info.dwOperStatus == IF_OPER_STATUS_DISCONNECTED
|
||||||
|
|| info.dwOperStatus == IF_OPER_STATUS_CONNECTING)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
ULONG ulOutbufLen = sizeof(IP_ADAPTER_INFO);
|
ULONG ulOutbufLen = sizeof(IP_ADAPTER_INFO);
|
||||||
@@ -78,7 +99,7 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
|||||||
|
|
||||||
IP_ADAPTER_INFO *pAdapter = reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get());
|
IP_ADAPTER_INFO *pAdapter = reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get());
|
||||||
if (NO_ERROR == dlRetVal && pAdapter != NULL) {
|
if (NO_ERROR == dlRetVal && pAdapter != NULL) {
|
||||||
while (pAdapter) {
|
while (GetAdapterState(pAdapter)) {
|
||||||
std::string str_ip = pAdapter->IpAddressList.IpAddress.String;
|
std::string str_ip = pAdapter->IpAddressList.IpAddress.String;
|
||||||
std::string str_mask = pAdapter->IpAddressList.IpMask.String;
|
std::string str_mask = pAdapter->IpAddressList.IpMask.String;
|
||||||
ULONG host_ip = inet_addr(const_cast<char *>(str_ip.c_str()));
|
ULONG host_ip = inet_addr(const_cast<char *>(str_ip.c_str()));
|
||||||
|
|||||||
@@ -210,6 +210,9 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
|
|||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
LOG_INFO(" LocalIP: {}", inet_ntoa(*(struct in_addr *)&local_ip));
|
||||||
|
LOG_INFO("Command Port: {}", lidar_info.cmd_port);
|
||||||
|
LOG_INFO("Data Port: {}", lidar_info.data_port);
|
||||||
CommPacket packet;
|
CommPacket packet;
|
||||||
memset(&packet, 0, sizeof(packet));
|
memset(&packet, 0, sizeof(packet));
|
||||||
handshake_req.ip_addr = local_ip;
|
handshake_req.ip_addr = local_ip;
|
||||||
|
|||||||
Reference in New Issue
Block a user