Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,28 @@ void CSocket::Init ( const quint16 iNewPortNumber, const quint16 iNewQosNumber,

// The IPV6_V6ONLY socket option must be false in order for the socket to listen on both protocols.
// On Linux it's false by default on most (all?) distros, but on Windows it is true by default
const uint8_t no = 0;
setsockopt ( UdpSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*) &no, sizeof ( no ) );
const int no = 0;
if ( setsockopt ( UdpSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*) &no, sizeof ( no ) ) == -1 )
{
throw CGenErr ( "setsockopt for IPV6_V6ONLY failed", "Network Error" );
}

// set the QoS
const char tos = (char) iQosNumber; // Quality of Service
setsockopt ( UdpSocket, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof ( tos ) );
const int tos = (int) iQosNumber; // Quality of Service
#if !defined( Q_OS_WIN )
if ( setsockopt ( UdpSocket, IPPROTO_IPV6, IPV6_TCLASS, (const char*) &tos, sizeof ( tos ) ) == -1 )
{
throw CGenErr ( "setsockopt for IPV6_TCLASS failed", "Network Error" );
}
#endif

#if !defined( Q_OS_DARWIN )
// set the QoS for IPv4 as well, as this is a dual-protocol socket
if ( setsockopt ( UdpSocket, IPPROTO_IP, IP_TOS, (const char*) &tos, sizeof ( tos ) ) == -1 )
{
throw CGenErr ( "setsockopt for IP_TOS failed", "Network Error" );
}
#endif

UdpSocketAddr.sa6.sin6_family = AF_INET6;
UdpSocketAddr.sa6.sin6_addr = in6addr_any;
Expand Down Expand Up @@ -147,8 +163,11 @@ void CSocket::Init ( const quint16 iNewPortNumber, const quint16 iNewQosNumber,
}

// set the QoS
const char tos = (char) iQosNumber; // Quality of Service
setsockopt ( UdpSocket, IPPROTO_IP, IP_TOS, &tos, sizeof ( tos ) );
const int tos = (int) iQosNumber; // Quality of Service
if ( setsockopt ( UdpSocket, IPPROTO_IP, IP_TOS, (const char*) &tos, sizeof ( tos ) ) == -1 )
{
throw CGenErr ( "setsockopt for IP_TOS failed", "Network Error" );
}

// preinitialize socket in address (only the port number is missing)
UdpSocketAddr.sa4.sin_family = AF_INET;
Expand Down