cmake: check for inet_ntop

fix build with mingw32, fix #132
This commit is contained in:
derselbst 2017-07-07 15:14:25 +02:00
parent e53230bb2f
commit d7d56086d5
2 changed files with 28 additions and 4 deletions

View File

@ -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

View File

@ -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);
}