From d7d56086d5dfa7f651497011059908b28244c88e Mon Sep 17 00:00:00 2001 From: derselbst Date: Fri, 7 Jul 2017 15:14:25 +0200 Subject: [PATCH] cmake: check for inet_ntop fix build with mingw32, fix #132 --- fluidsynth/CMakeLists.txt | 16 ++++++++++++---- fluidsynth/src/utils/fluid_sys.c | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/fluidsynth/CMakeLists.txt b/fluidsynth/CMakeLists.txt index 4118c4c7..e42e310c 100644 --- a/fluidsynth/CMakeLists.txt +++ b/fluidsynth/CMakeLists.txt @@ -166,6 +166,12 @@ if ( WIN32 ) if ( MINGW ) set ( MINGW32 1 ) add_definitions ( -mms-bitfields ) + include(CheckFunctionExists) + CHECK_FUNCTION_EXISTS ( "inet_ntop" HAVE_INETNTOP ) + if (NOT HAVE_INETNTOP ) + set ( IPV6 0 ) + set ( IPV6_SUPPORT 0 ) + endif ( NOT HAVE_INETNTOP ) endif ( MINGW ) else ( WIN32 ) # Check PThreads, but not in Windows @@ -390,10 +396,12 @@ else ( enable-dbus ) endif ( enable-dbus ) unset ( IPV6_SUPPORT CACHE ) -if ( enable-ipv6 ) - set ( IPV6 1 ) - set ( IPV6_SUPPORT 1 ) -endif ( enable-ipv6 ) +if ( HAVE_INETNTOP ) + if ( enable-ipv6 ) + set ( IPV6 1 ) + set ( IPV6_SUPPORT 1 ) + endif ( enable-ipv6 ) +endif ( HAVE_INETNTOP ) # General configuration file configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake diff --git a/fluidsynth/src/utils/fluid_sys.c b/fluidsynth/src/utils/fluid_sys.c index ee7d8d92..768e9e15 100644 --- a/fluidsynth/src/utils/fluid_sys.c +++ b/fluidsynth/src/utils/fluid_sys.c @@ -1008,13 +1008,20 @@ fluid_server_socket_run (void *data) server_socket->cont = 0; return; } else { +#ifdef HAVE_INETNTOP #ifdef IPV6 inet_ntop(AF_INET6, &addr.sin6_addr, straddr, sizeof(straddr)); #else inet_ntop(AF_INET, &addr.sin_addr, straddr, sizeof(straddr)); #endif +#endif +#ifdef HAVE_INETNTOP retval = server_socket->func (server_socket->data, client_socket, straddr); +#else + retval = server_socket->func (server_socket->data, client_socket, + inet_ntoa (addr.sin_addr)); +#endif if (retval != 0) fluid_socket_close(client_socket); @@ -1141,7 +1148,9 @@ static void fluid_server_socket_run (void *data) char straddr[INET6_ADDRSTRLEN]; #else struct sockaddr_in addr; +#ifdef HAVE_INETNTOP char straddr[INET_ADDRSTRLEN]; +#endif #endif socklen_t addrlen = sizeof (addr); int r; @@ -1165,13 +1174,20 @@ static void fluid_server_socket_run (void *data) } else { +#ifdef HAVE_INETNTOP #ifdef IPV6 inet_ntop(AF_INET6, &addr.sin6_addr, straddr, sizeof(straddr)); #else inet_ntop(AF_INET, &addr.sin_addr, straddr, sizeof(straddr)); #endif +#endif +#ifdef HAVE_INETNTOP r = server_socket->func (server_socket->data, client_socket, straddr); +#else + r = server_socket->func (server_socket->data, client_socket, + inet_ntoa (addr.sin_addr)); +#endif if (r != 0) fluid_socket_close (client_socket); }