Skip to content

Commit

Permalink
Fix redefinition of inet_pton with mingw-w64
Browse files Browse the repository at this point in the history
It may be missing in mingw32, but not in mingw-w64.
But travis is on Ubuntu Trusty, so its mingw-w64 is ancient and missing inet_pton,
so the proper thing to do is to check for it.
  • Loading branch information
wiiaboo authored and rndi committed Oct 30, 2018
1 parent 61e0151 commit 69279a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(haiUtil)
include(FindPkgConfig)
# XXX See 'if (MINGW)' condition below, may need fixing.
include(FindThreads)
include(CheckFunctionExists)

# Platform shortcuts
set_if(DARWIN ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down Expand Up @@ -87,6 +88,7 @@ option(ENABLE_GETNAMEINFO "In-logs sockaddr-to-string should do rev-dns" OFF)
option(USE_GNUTLS "Should use gnutls instead of openssl" OFF)
option(ENABLE_CXX_DEPS "Extra library dependencies in srt.pc for the CXX libraries useful with C language" ON)
option(USE_STATIC_LIBSTDCXX "Should use static rather than shared libstdc++" OFF)
option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)

set(TARGET_srt "srt" CACHE STRING "The name for the haisrt library")

Expand Down Expand Up @@ -145,6 +147,22 @@ endif()
# When you use crosscompiling, you have to take care that PKG_CONFIG_PATH
# and CMAKE_PREFIX_PATH are set properly.

# symbol exists in win32, but function does not.
if(WIN32)
if(ENABLE_INET_PTON)
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
check_function_exists(inet_pton HAVE_INET_PTON)
add_definitions(-D_WIN32_WINNT=0x0600)
else()
add_definitions(-D_WIN32_WINNT=0x0501)
endif()
else()
check_function_exists(inet_pton HAVE_INET_PTON)
endif()
if (DEFINED HAVE_INET_PTON)
add_definitions(-DHAVE_INET_PTON=1)
endif()

# find OpenSSL
if ( USE_GNUTLS )
message(STATUS "SSL Dependency: using GNUTLS with Nettle, as requested")
Expand Down
4 changes: 2 additions & 2 deletions apps/apputil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ inline void SysCleanupNetwork() {}
// See:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms742214(v=vs.85).aspx
// http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedInternet3b.html
#ifdef __MINGW32__
#if defined(_WIN32) && !defined(HAVE_INET_PTON)
static inline int inet_pton(int af, const char * src, void * dst)
{
struct sockaddr_storage ss;
Expand Down Expand Up @@ -115,7 +115,7 @@ static inline int inet_pton(int af, const char * src, void * dst)

return 0;
}
#endif // __MINGW__
#endif // _WIN32 && !HAVE_INET_PTON

#ifdef _WIN32
inline int SysError() { return ::GetLastError(); }
Expand Down

0 comments on commit 69279a6

Please sign in to comment.