mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-13 09:03:43 +02:00
Fix for GitHub issue #110 -- failure to bind IPv6 now non-fatal
This commit is contained in:
parent
1952db5069
commit
00b16f6aa6
1 changed files with 76 additions and 87 deletions
|
@ -134,15 +134,7 @@ SocketManager::SocketManager(
|
||||||
{ // bind TCP IPv6
|
{ // bind TCP IPv6
|
||||||
_tcpV6ListenSocket = ::socket(AF_INET6,SOCK_STREAM,0);
|
_tcpV6ListenSocket = ::socket(AF_INET6,SOCK_STREAM,0);
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
if (_tcpV6ListenSocket == INVALID_SOCKET) {
|
if (_tcpV6ListenSocket != INVALID_SOCKET) {
|
||||||
#else
|
|
||||||
if (_tcpV6ListenSocket <= 0) {
|
|
||||||
#endif
|
|
||||||
_closeSockets();
|
|
||||||
throw std::runtime_error("unable to create IPv6 SOCK_STREAM socket");
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
{
|
{
|
||||||
BOOL f;
|
BOOL f;
|
||||||
f = TRUE; ::setsockopt(_tcpV6ListenSocket,IPPROTO_IPV6,IPV6_V6ONLY,(const char *)&f,sizeof(f));
|
f = TRUE; ::setsockopt(_tcpV6ListenSocket,IPPROTO_IPV6,IPV6_V6ONLY,(const char *)&f,sizeof(f));
|
||||||
|
@ -151,13 +143,14 @@ SocketManager::SocketManager(
|
||||||
ioctlsocket(_tcpV6ListenSocket,FIONBIO,&iMode);
|
ioctlsocket(_tcpV6ListenSocket,FIONBIO,&iMode);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
if (_tcpV6ListenSocket > 0) {
|
||||||
{
|
{
|
||||||
int f;
|
int f;
|
||||||
f = 1; ::setsockopt(_tcpV6ListenSocket,IPPROTO_IPV6,IPV6_V6ONLY,(void *)&f,sizeof(f));
|
f = 1; ::setsockopt(_tcpV6ListenSocket,IPPROTO_IPV6,IPV6_V6ONLY,(void *)&f,sizeof(f));
|
||||||
f = 1; ::setsockopt(_tcpV6ListenSocket,SOL_SOCKET,SO_REUSEADDR,(void *)&f,sizeof(f));
|
f = 1; ::setsockopt(_tcpV6ListenSocket,SOL_SOCKET,SO_REUSEADDR,(void *)&f,sizeof(f));
|
||||||
fcntl(_tcpV6ListenSocket,F_SETFL,O_NONBLOCK);
|
fcntl(_tcpV6ListenSocket,F_SETFL,O_NONBLOCK);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // __WINDOWS__ / not __WINDOWS__
|
||||||
|
|
||||||
struct sockaddr_in6 sin6;
|
struct sockaddr_in6 sin6;
|
||||||
memset(&sin6,0,sizeof(sin6));
|
memset(&sin6,0,sizeof(sin6));
|
||||||
|
@ -176,6 +169,7 @@ SocketManager::SocketManager(
|
||||||
|
|
||||||
FD_SET(_tcpV6ListenSocket,&_readfds);
|
FD_SET(_tcpV6ListenSocket,&_readfds);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // bind TCP IPv4
|
{ // bind TCP IPv4
|
||||||
_tcpV4ListenSocket = ::socket(AF_INET,SOCK_STREAM,0);
|
_tcpV4ListenSocket = ::socket(AF_INET,SOCK_STREAM,0);
|
||||||
|
@ -229,16 +223,10 @@ SocketManager::SocketManager(
|
||||||
{ // bind UDP IPv6
|
{ // bind UDP IPv6
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
SOCKET s = ::socket(AF_INET6,SOCK_DGRAM,0);
|
SOCKET s = ::socket(AF_INET6,SOCK_DGRAM,0);
|
||||||
if (s == INVALID_SOCKET) {
|
if (s != INVALID_SOCKET) {
|
||||||
_closeSockets();
|
|
||||||
throw std::runtime_error("unable to create IPv6 SOCK_DGRAM socket");
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
int s = ::socket(AF_INET6,SOCK_DGRAM,0);
|
int s = ::socket(AF_INET6,SOCK_DGRAM,0);
|
||||||
if (s <= 0) {
|
if (s > 0) {
|
||||||
_closeSockets();
|
|
||||||
throw std::runtime_error("unable to create IPv6 SOCK_DGRAM socket");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -299,6 +287,7 @@ SocketManager::SocketManager(
|
||||||
#endif
|
#endif
|
||||||
FD_SET(s,&_readfds);
|
FD_SET(s,&_readfds);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // bind UDP IPv4
|
{ // bind UDP IPv4
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
Loading…
Add table
Reference in a new issue