Merge pull request #7606 from Robyt3/Base-TOS-Error-Fix

Avoid setting `IP_TOS` on IPv6 sockets on Windows, fix incorrect error code logged in socket warnings
This commit is contained in:
heinrich5991 2023-12-08 12:28:34 +00:00 committed by GitHub
commit f9dc1f5284
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1551,14 +1551,17 @@ NETSOCKET net_udp_create(NETADDR bindaddr)
/* set broadcast */
if(setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast)) != 0)
dbg_msg("socket", "Setting BROADCAST on ipv4 failed: %d", errno);
{
dbg_msg("socket", "Setting BROADCAST on ipv4 failed: %d", net_errno());
}
{
/* set DSCP/TOS */
int iptos = 0x10 /* IPTOS_LOWDELAY */;
//int iptos = 46; /* High Priority */
if(setsockopt(socket, IPPROTO_IP, IP_TOS, (char *)&iptos, sizeof(iptos)) != 0)
dbg_msg("socket", "Setting TOS on ipv4 failed: %d", errno);
{
dbg_msg("socket", "Setting TOS on ipv4 failed: %d", net_errno());
}
}
}
}
@ -1596,15 +1599,21 @@ NETSOCKET net_udp_create(NETADDR bindaddr)
/* set broadcast */
if(setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast)) != 0)
dbg_msg("socket", "Setting BROADCAST on ipv6 failed: %d", errno);
{
dbg_msg("socket", "Setting BROADCAST on ipv6 failed: %d", net_errno());
}
// TODO: setting IP_TOS on ipv6 with setsockopt is not supported on Windows, see https://github.com/ddnet/ddnet/issues/7605
#if !defined(CONF_FAMILY_WINDOWS)
{
/* set DSCP/TOS */
int iptos = 0x10 /* IPTOS_LOWDELAY */;
//int iptos = 46; /* High Priority */
if(setsockopt(socket, IPPROTO_IP, IP_TOS, (char *)&iptos, sizeof(iptos)) != 0)
dbg_msg("socket", "Setting TOS on ipv6 failed: %d", errno);
{
dbg_msg("socket", "Setting TOS on ipv6 failed: %d", net_errno());
}
}
#endif
}
}