Skip to content

Commit

Permalink
add check for inet_pton in configure.win
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyu1994 committed Apr 21, 2022
1 parent 406dcfc commit ff8c604
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
28 changes: 28 additions & 0 deletions R-package/configure.win
Original file line number Diff line number Diff line change
Expand Up @@ -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/" \
Expand Down
4 changes: 2 additions & 2 deletions src/network/socket_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ff8c604

Please sign in to comment.