Network: Add support for dual-stack sockets

This commit is contained in:
Lynix
2018-04-01 20:48:50 +02:00
parent 600bfc3ee6
commit 715729fc02
10 changed files with 75 additions and 11 deletions

View File

@@ -809,8 +809,27 @@ namespace Nz
{
NazaraAssert(handle != InvalidHandle, "Invalid handle");
bool option = broadcasting;
if (setsockopt(handle, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
int option = broadcasting;
if (setsockopt(handle, IPPROTO_IPV6, SO_BROADCAST, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
{
if (error)
*error = TranslateErrnoToResolveError(GetLastErrorCode());
return false; //< Error
}
if (error)
*error = SocketError_NoError;
return true;
}
bool SocketImpl::SetIPv6Only(SocketHandle handle, bool ipv6Only, SocketError* error)
{
NazaraAssert(handle != InvalidHandle, "Invalid handle");
int option = broadcasting;
if (setsockopt(handle, SOL_SOCKET, IPV6_V6ONLY, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
{
if (error)
*error = TranslateErrnoToResolveError(GetLastErrorCode());

View File

@@ -72,6 +72,7 @@ namespace Nz
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
static bool SetBroadcasting(SocketHandle handle, bool broadcasting, SocketError* error = nullptr);
static bool SetIPv6Only(SocketHandle handle, bool ipv6only, SocketError* error = nullptr);
static bool SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error = nullptr);
static bool SetNoDelay(SocketHandle handle, bool nodelay, SocketError* error = nullptr);
static bool SetReceiveBufferSize(SocketHandle handle, std::size_t size, SocketError* error = nullptr);