mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-12-01 00:21:14 +00:00
Add IPv6 support to socket APIs
This commit is contained in:
parent
380fd258d7
commit
3e08eaea00
5 changed files with 114 additions and 6 deletions
|
@ -66,6 +66,7 @@ option ( enable-midishare "compile MidiShare support (if it is available)" on )
|
|||
option ( enable-readline "compile readline lib line editing (if it is available)" on )
|
||||
option ( enable-dbus "compile DBUS support (if it is available)" on )
|
||||
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" on )
|
||||
option ( enable-ipv6 "enable ipv6 support " on )
|
||||
|
||||
# Platform specific options
|
||||
if ( ${CMAKE_SYSTEM} MATCHES "Linux" )
|
||||
|
@ -388,6 +389,12 @@ else ( enable-dbus )
|
|||
unset_pkg_config ( DBUS )
|
||||
endif ( enable-dbus )
|
||||
|
||||
unset ( IPV6_SUPPORT CACHE )
|
||||
if ( enable-ipv6 )
|
||||
set ( IPV6 1 )
|
||||
set ( IPV6_SUPPORT 1 )
|
||||
endif ( enable-ipv6 )
|
||||
|
||||
# General configuration file
|
||||
configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake
|
||||
${CMAKE_BINARY_DIR}/config.h )
|
||||
|
|
|
@ -103,6 +103,12 @@ else ( AUFILE_SUPPORT )
|
|||
message ( "Audio to file driver: no" )
|
||||
endif ( AUFILE_SUPPORT )
|
||||
|
||||
if ( IPV6_SUPPORT )
|
||||
message ( "IPV6 Support : yes" )
|
||||
else ( IPV6_SUPPORT )
|
||||
message ( "IPV6 Support : no" )
|
||||
endif ( IPV6_SUPPORT )
|
||||
|
||||
if ( WITH_READLINE )
|
||||
message ( "Readline: yes (NOTE: GPL library)" )
|
||||
else ( WITH_READLINE )
|
||||
|
|
|
@ -452,7 +452,37 @@ else
|
|||
fi
|
||||
AM_CONDITIONAL(LADCCA_SUPPORT, test "$LADCCA_FOUND" = "yes")
|
||||
|
||||
|
||||
#Checking for IPV6 support
|
||||
AC_MSG_CHECKING(for IPv6 support)
|
||||
AC_ARG_ENABLE(ipv6, AS_HELP_STRING([--enable-ipv6],
|
||||
[Enable IPV6 support (default=auto)]),
|
||||
ENABLE_IPV6=$enableval,
|
||||
ENABLE_IPV6=yes)
|
||||
if test "$ENABLE_IPV6" = "yes" ; then
|
||||
AC_CACHE_VAL(ac_cv_ipv6,
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdlib.h>
|
||||
main()
|
||||
{
|
||||
int fd;
|
||||
struct sockaddr_in6 foo;
|
||||
fd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
exit(fd >= 0 ? 0 : 1);
|
||||
}],
|
||||
ac_cv_ipv6=yes,
|
||||
ac_cv_ipv6=no,
|
||||
ac_cv_ipv6=yes))
|
||||
AC_MSG_RESULT($ac_cv_ipv6)
|
||||
if test $ac_cv_ipv6 = yes ; then
|
||||
AC_DEFINE(IPV6,1,[check if system supports IPV6])
|
||||
else
|
||||
ENABLE_IPV6="no"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
|
@ -543,6 +573,11 @@ else
|
|||
echo "LADSPA support: no"
|
||||
fi
|
||||
|
||||
if test "${ENABLE_IPV6}" = "yes"; then
|
||||
echo "IPV6 support: yes"
|
||||
else
|
||||
echo "IPV6 support: no"
|
||||
fi
|
||||
if test "${LASH_FOUND}" = "yes"; then
|
||||
echo "LASH support: yes (NOTE: GPL library)"
|
||||
else
|
||||
|
|
|
@ -139,6 +139,9 @@
|
|||
/* Include the LADSPA Fx unit */
|
||||
#cmakedefine LADSPA @LADSPA_SUPPORT@
|
||||
|
||||
/* Define to enable IPV6 support */
|
||||
#cmakedefine IPV6 @IPV6_SUPPORT@
|
||||
|
||||
/* libsndfile has ogg vorbis support */
|
||||
#cmakedefine LIBSNDFILE_HASVORBIS @LIBSNDFILE_HASVORBIS@
|
||||
|
||||
|
|
|
@ -981,9 +981,16 @@ fluid_server_socket_run (void *data)
|
|||
{
|
||||
fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data;
|
||||
fluid_socket_t client_socket;
|
||||
#ifdef IPV6
|
||||
struct sockaddr_in6 addr;
|
||||
char straddr[INET6_ADDRSTRLEN];
|
||||
#else
|
||||
struct sockaddr_in addr;
|
||||
char straddr[INET_ADDRSTRLEN];
|
||||
#endif
|
||||
socklen_t addrlen = sizeof (addr);
|
||||
int retval;
|
||||
FLUID_MEMSET((char *)&addr, 0, sizeof(addr));
|
||||
|
||||
FLUID_LOG (FLUID_DBG, "Server listening for connections");
|
||||
|
||||
|
@ -1001,8 +1008,13 @@ fluid_server_socket_run (void *data)
|
|||
server_socket->cont = 0;
|
||||
return;
|
||||
} else {
|
||||
#ifdef IPV6
|
||||
inet_ntop(AF_INET6, &addr.sin6_addr, straddr, sizeof(straddr));
|
||||
#else
|
||||
inet_ntop(AF_INET, &addr.sin_addr, straddr, sizeof(straddr));
|
||||
#endif
|
||||
retval = server_socket->func (server_socket->data, client_socket,
|
||||
inet_ntoa (addr.sin_addr)); // FIXME - inet_ntoa is not thread safe
|
||||
straddr);
|
||||
|
||||
if (retval != 0)
|
||||
fluid_socket_close(client_socket);
|
||||
|
@ -1016,10 +1028,26 @@ fluid_server_socket_t*
|
|||
new_fluid_server_socket(int port, fluid_server_func_t func, void* data)
|
||||
{
|
||||
fluid_server_socket_t* server_socket;
|
||||
#ifdef IPV6
|
||||
struct sockaddr_in6 addr;
|
||||
#else
|
||||
struct sockaddr_in addr;
|
||||
#endif
|
||||
fluid_socket_t sock;
|
||||
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
#ifdef IPV6
|
||||
sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
if (sock == INVALID_SOCKET) {
|
||||
FLUID_LOG(FLUID_ERR, "Failed to create server socket");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FLUID_MEMSET((char *)&addr, 0, sizeof(struct sockaddr_in6));
|
||||
addr.sin6_family = AF_INET6;
|
||||
addr.sin6_addr = in6addr_any;
|
||||
addr.sin6_port = htons(port);
|
||||
#else
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == INVALID_SOCKET) {
|
||||
|
@ -1031,8 +1059,8 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data)
|
|||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
if (bind(sock, (const struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
|
||||
#endif
|
||||
if (bind(sock, (const struct sockaddr *) &addr, sizeof(addr)) == SOCKET_ERROR) {
|
||||
FLUID_LOG(FLUID_ERR, "Failed to bind server socket");
|
||||
fluid_socket_close(sock);
|
||||
return NULL;
|
||||
|
@ -1108,9 +1136,16 @@ static void fluid_server_socket_run (void *data)
|
|||
{
|
||||
fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data;
|
||||
fluid_socket_t client_socket;
|
||||
#ifdef IPV6
|
||||
struct sockaddr_in6 addr;
|
||||
char straddr[INET6_ADDRSTRLEN];
|
||||
#else
|
||||
struct sockaddr_in addr;
|
||||
char straddr[INET_ADDRSTRLEN];
|
||||
#endif
|
||||
socklen_t addrlen = sizeof (addr);
|
||||
int r;
|
||||
FLUID_MEMSET((char *)&addr, 0, sizeof(addr));
|
||||
|
||||
FLUID_LOG(FLUID_DBG, "Server listening for connections");
|
||||
|
||||
|
@ -1130,8 +1165,13 @@ static void fluid_server_socket_run (void *data)
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifdef IPV6
|
||||
inet_ntop(AF_INET6, &addr.sin6_addr, straddr, sizeof(straddr));
|
||||
#else
|
||||
inet_ntop(AF_INET, &addr.sin_addr, straddr, sizeof(straddr));
|
||||
#endif
|
||||
r = server_socket->func (server_socket->data, client_socket,
|
||||
inet_ntoa (addr.sin_addr)); // FIXME - inet_ntoa is not thread safe
|
||||
straddr);
|
||||
if (r != 0)
|
||||
fluid_socket_close (client_socket);
|
||||
}
|
||||
|
@ -1144,7 +1184,12 @@ fluid_server_socket_t*
|
|||
new_fluid_server_socket(int port, fluid_server_func_t func, void* data)
|
||||
{
|
||||
fluid_server_socket_t* server_socket;
|
||||
#ifdef IPV6
|
||||
struct sockaddr_in6 addr;
|
||||
#else
|
||||
struct sockaddr_in addr;
|
||||
#endif
|
||||
|
||||
fluid_socket_t sock;
|
||||
WSADATA wsaData;
|
||||
int retval;
|
||||
|
@ -1159,6 +1204,18 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data)
|
|||
FLUID_LOG(FLUID_ERR, "Server socket creation error: WSAStartup failed: %d", retval);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef IPV6
|
||||
sock = socket (AF_INET6, SOCK_STREAM, 0);
|
||||
if (sock == INVALID_SOCKET)
|
||||
{
|
||||
FLUID_LOG (FLUID_ERR, "Failed to create server socket: %ld", WSAGetLastError ());
|
||||
WSACleanup ();
|
||||
return NULL;
|
||||
}
|
||||
addr.sin6_family = AF_INET6;
|
||||
addr.sin6_port = htons (port);
|
||||
addr.sin6_addr = in6addr_any;
|
||||
#else
|
||||
|
||||
sock = socket (AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
|
@ -1172,7 +1229,7 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data)
|
|||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons (port);
|
||||
addr.sin_addr.s_addr = htonl (INADDR_ANY);
|
||||
|
||||
#endif
|
||||
retval = bind (sock, (struct sockaddr *)&addr, sizeof (addr));
|
||||
|
||||
if (retval == SOCKET_ERROR)
|
||||
|
|
Loading…
Reference in a new issue