mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-02-02 10:00:38 +01:00
Add check if IPv6 is supported by OS.
Windows implementation is complete, while POSIX implementation should be reviewed and fixed if necessary.
This commit is contained in:
parent
b74395118f
commit
c057dd971f
@ -46,6 +46,7 @@ namespace os_utils
|
||||
int openCreateSharedFile(const char* pathname, int flags);
|
||||
bool touchFile(const char* pathname);
|
||||
|
||||
bool isIPv6supported();
|
||||
} // namespace os_utils
|
||||
|
||||
#endif // INCLUDE_OS_FILE_UTILS_H
|
||||
|
@ -229,4 +229,10 @@ bool touchFile(const char* pathname)
|
||||
#endif
|
||||
}
|
||||
|
||||
// check if OS have support for IPv6 protocol
|
||||
bool isIPv6supported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace os_utils
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "firebird.h"
|
||||
|
||||
#include "../common/classes/array.h"
|
||||
#include "../common/classes/init.h"
|
||||
#include "../common/gdsassert.h"
|
||||
#include "../common/os/os_utils.h"
|
||||
@ -46,6 +47,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <aclapi.h>
|
||||
#include <Winsock2.h>
|
||||
|
||||
namespace os_utils
|
||||
{
|
||||
@ -270,4 +272,33 @@ bool touchFile(const char* pathname)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check if OS have support for IPv6 protocol
|
||||
bool isIPv6supported()
|
||||
{
|
||||
INT proto[] = {IPPROTO_TCP, 0};
|
||||
|
||||
Firebird::HalfStaticArray<char, sizeof(WSAPROTOCOL_INFO) * 4> buf;
|
||||
|
||||
DWORD len = buf.getCapacity();
|
||||
LPWSAPROTOCOL_INFO pi = (LPWSAPROTOCOL_INFO) buf.getBuffer(len);
|
||||
|
||||
int n = WSAEnumProtocols(proto, pi, &len);
|
||||
|
||||
if (n == SOCKET_ERROR && GetLastError() == WSAENOBUFS)
|
||||
{
|
||||
pi = (LPWSAPROTOCOL_INFO) buf.getBuffer(len);
|
||||
n = WSAEnumProtocols(proto, pi, &len);
|
||||
}
|
||||
|
||||
if (n == SOCKET_ERROR)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
if (pi[i].iAddressFamily == AF_INET6 && pi[i].iProtocol == IPPROTO_TCP)
|
||||
return true;
|
||||
|
||||
WSASetLastError(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace os_utils
|
||||
|
@ -111,6 +111,7 @@ const int INET_RETRY_CALL = 5;
|
||||
#include "../common/config/config.h"
|
||||
#include "../common/utils_proto.h"
|
||||
#include "../common/classes/ClumpletWriter.h"
|
||||
#include "../common/os/os_utils.h"
|
||||
|
||||
// Please review. Maybe not needed. See H_ERRNO in common.h.
|
||||
#if defined HPUX
|
||||
@ -773,9 +774,11 @@ rem_port* INET_connect(const TEXT* name,
|
||||
}
|
||||
|
||||
// Prepare hints
|
||||
const bool ipv6 = os_utils::isIPv6supported();
|
||||
|
||||
struct addrinfo gai_hints;
|
||||
memset(&gai_hints, 0, sizeof(gai_hints));
|
||||
gai_hints.ai_family = ((packet || host.hasData()) ? AF_UNSPEC : AF_INET6);
|
||||
gai_hints.ai_family = ((packet || host.hasData() || !ipv6) ? AF_UNSPEC : AF_INET6);
|
||||
gai_hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
#ifndef WIN_NT
|
||||
|
Loading…
Reference in New Issue
Block a user