engine: common: add function NET_MakeSocketReuseAddr

This commit is contained in:
SNMetamorph
2026-05-17 00:49:15 +04:00
committed by Alibek Omarov
parent a60d0d142d
commit e808038fee
2 changed files with 8 additions and 1 deletions

View File

@@ -169,6 +169,12 @@ qboolean NET_MakeSocketNonBlocking( int socket_fd )
return true;
}
qboolean NET_MakeSocketReuseAddr( int socket_fd )
{
uint opt = 1;
return !NET_IsSocketError( setsockopt( socket_fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof( opt )));
}
void NET_NetadrToIP6Bytes( uint8_t *ip6, const netadr_t *adr )
{
memcpy( &ip6[0], adr->ip6_0, 2 );
@@ -1609,7 +1615,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
Con_DPrintf( S_WARN "%s: port: %d setsockopt SO_BROADCAST: %s\n", __func__, port, NET_ErrorString( ));
}
if( NET_IsSocketError( setsockopt( net_socket, SOL_SOCKET, SO_REUSEADDR, (const char *)&optval, sizeof( optval ))))
if( !NET_MakeSocketReuseAddr( net_socket ))
{
Con_DPrintf( S_WARN "%s: port: %d setsockopt SO_REUSEADDR: %s\n", __func__, port, NET_ErrorString( ));
closesocket( net_socket );

View File

@@ -77,6 +77,7 @@ void NET_NetadrToIP6Bytes( uint8_t *ip6, const netadr_t *adr );
qboolean NET_IsSocketError( int retval );
qboolean NET_IsSocketValid( int socket );
qboolean NET_MakeSocketNonBlocking( int socket_fd );
qboolean NET_MakeSocketReuseAddr( int socket_fd );
static inline qboolean NET_IsLocalAddress( netadr_t adr )
{