Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check existence of inet_pton for win32 in CMakeLists.txt (fixes #5019) #5159

Merged
merged 14 commits into from
May 23, 2022
Prev Previous commit
Next Next commit
add check for inet_pton in configure.win
shiyu1994 committed Apr 21, 2022
commit ff8c604c3a3acf38b98a2885fc4e89ff94fb6345
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -327,9 +327,9 @@ endif()
if(WIN32)
include(CheckSymbolExists)
list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
check_symbol_exists(inet_pton "ws2tcpip.h" INET_PTON_FOUND)
if(INET_PTON_FOUND)
add_definitions(-DHAS_INET_PTON)
check_symbol_exists(inet_pton "ws2tcpip.h" WIN32_INET_PTON_FOUND)
if(WIN32_INET_PTON_FOUND)
add_definitions(-DWIN32_HAS_INET_PTON)
endif()
endif()

28 changes: 28 additions & 0 deletions R-package/configure.win
Original file line number Diff line number Diff line change
@@ -70,6 +70,34 @@ then
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DMM_MALLOC=1"
fi

###############
# INET_PTON #
###############

ac_inet_pton="no"

cat > conftest.cpp <<EOL
#ifdef _WIN32
#include <ws2tcpip.h>
#endif
int main() {
#ifdef _WIN32
void* p = inet_pton;
#endif
return 0;
}
EOL

${CXX} ${CXXFLAGS} ${CPPFLAGS} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_inet_pton="yes"
rm -f ./conftest
rm -f ./conftest.cpp
echo "checking whether INET_PTON works...${ac_inet_pton}"

if test "${ac_inet_pton}" = "yes";
then
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DWIN32_HAS_INET_PTON=1"
fi

# Generate Makevars.win from Makevars.win.in
sed -e \
"s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \
4 changes: 2 additions & 2 deletions src/network/socket_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -60,8 +60,8 @@ const int INVALID_SOCKET = -1;
#endif

#ifdef _WIN32
// existence of inet_pton is checked in CMakeLists.txt and stored in HAS_INET_PTON
#ifndef HAS_INET_PTON
// existence of inet_pton is checked in CMakeLists.txt and stored in WIN32_HAS_INET_PTON
#ifndef WIN32_HAS_INET_PTON
// not using visual studio in windows
inline int inet_pton(int af, const char *src, void *dst) {
struct sockaddr_storage ss;