Bind on both IPv6 and IPv4 on BSD.

This commit is contained in:
Bartosz Taudul 2019-11-21 02:03:32 +01:00
parent a9cd5b331f
commit 3282360382

View File

@ -22,6 +22,7 @@
#else #else
# include <arpa/inet.h> # include <arpa/inet.h>
# include <sys/socket.h> # include <sys/socket.h>
# include <sys/param.h>
# include <netinet/in.h> # include <netinet/in.h>
# include <netdb.h> # include <netdb.h>
# include <unistd.h> # include <unistd.h>
@ -306,6 +307,9 @@ bool ListenSocket::Listen( int port, int backlog )
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
unsigned long val = 0; unsigned long val = 0;
setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) ); setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) );
#elif defined BSD
int val = 0;
setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) );
#else #else
int val = 1; int val = 1;
setsockopt( m_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof( val ) ); setsockopt( m_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof( val ) );