From d514b5510b20faaa89e22952da7cac996da63964 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Mon, 1 Aug 2022 12:21:26 +0400 Subject: [PATCH 1/2] fix: run internet scenario or host game --- source/shared_lib/sources/platform/posix/socket.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 8bc2922f..ac4dd510 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -708,8 +708,12 @@ void Socket::getLocalIPAddressListForPlatform(std::vector &ipList) // Now check all linux network devices struct ifaddrs *ifap = NULL; getifaddrs(&ifap); - for(struct ifaddrs *ifa = ifap; ifa; ifa = ifa->ifa_next) { - if (ifa->ifa_addr->sa_family == AF_INET) { + for(struct ifaddrs *ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) { + continue; + } + if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4 + // is a valid IP4 Address struct sockaddr_in *sa = (struct sockaddr_in *) ifa->ifa_addr; char *addr = inet_ntoa(sa->sin_addr); //printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr); @@ -725,7 +729,7 @@ void Socket::getLocalIPAddressListForPlatform(std::vector &ipList) } } } - freeifaddrs(ifap); + if (ifap != NULL) freeifaddrs(ifap); if(Socket::intfTypes.empty()) { Socket::intfTypes.push_back("lo"); From a8a51d4ef7c9f670cbfd3ac9116d45edc501e92e Mon Sep 17 00:00:00 2001 From: pavanvo Date: Sun, 14 Aug 2022 16:37:07 +0400 Subject: [PATCH 2/2] style: tabs insted of spaces --- .../sources/platform/posix/socket.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index ac4dd510..bcb3b358 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -709,24 +709,24 @@ void Socket::getLocalIPAddressListForPlatform(std::vector &ipList) struct ifaddrs *ifap = NULL; getifaddrs(&ifap); for(struct ifaddrs *ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr) { - continue; - } + if (!ifa->ifa_addr) { + continue; + } if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4 - // is a valid IP4 Address + // is a valid IP4 Address struct sockaddr_in *sa = (struct sockaddr_in *) ifa->ifa_addr; char *addr = inet_ntoa(sa->sin_addr); //printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Interface: [%s] address: [%s]\n",__FILE__,__FUNCTION__,__LINE__,ifa->ifa_name,addr); } - if(strlen(addr) > 0 && - strncmp(addr,"127.",4) != 0 && - strncmp(addr,"0.",2) != 0) { - if(std::find(ipList.begin(),ipList.end(),addr) == ipList.end()) { - ipList.push_back(addr); - } - } + if(strlen(addr) > 0 && + strncmp(addr,"127.",4) != 0 && + strncmp(addr,"0.",2) != 0) { + if(std::find(ipList.begin(),ipList.end(),addr) == ipList.end()) { + ipList.push_back(addr); + } + } } } if (ifap != NULL) freeifaddrs(ifap);