From 6b56e13b60ed58df559ec0b1f638cc7f00e3b7ff Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 20 Mar 2025 05:39:02 +0300 Subject: [PATCH] engine: make local ipv4 address private to net_ws, acquire local addresses with GetLocalAddress function --- engine/client/cl_game.c | 2 +- engine/common/net_ws.c | 32 +++++++++++++++++++++++++++++--- engine/common/net_ws.h | 2 ++ engine/common/netchan.h | 1 - 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index a2109de8..99abbc50 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -3410,7 +3410,7 @@ static void GAME_EXPORT NetAPI_Status( net_status_t *status ) status->latency = (connected) ? cl.frames[cl.parsecountmod].latency : 0.0; status->remote_address = cls.netchan.remote_address; status->packet_loss = packet_loss; - status->local_address = net_local; + NET_GetLocalAddress( &status->local_address, NULL ); // NetAPI doesn't know about IPv6 status->rate = rate.value; } diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index 3d6865d4..7ee4cba0 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -1791,12 +1791,12 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac /* ================ -NET_GetLocalAddress +NET_DetermineLocalAddress Returns the servers' ip address as a string. ================ */ -static void NET_GetLocalAddress( void ) +static void NET_DetermineLocalAddress( void ) { char hostname[512]; char buff[512]; @@ -1910,7 +1910,7 @@ void NET_Config( qboolean multiplayer, qboolean changeport ) // get our local address, if possible if( bFirst ) { - NET_GetLocalAddress(); + NET_DetermineLocalAddress(); bFirst = false; } } @@ -2006,6 +2006,32 @@ static void NET_ClearLagData( qboolean bClient, qboolean bServer ) if( bServer ) NET_ClearLaggedList( &net.lagdata[NS_SERVER] ); } +/* +==================== +NET_GetLocalAddress + +get local server addresses +==================== +*/ +void NET_GetLocalAddress( netadr_t *ip4, netadr_t *ip6 ) +{ + if( ip4 ) + { + if( net.allow_ip ) + *ip4 = net_local; + else + memset( ip4, 0, sizeof( *ip4 )); + } + + if( ip6 ) + { + if( net.allow_ip6 ) + *ip6 = net6_local; + else + memset( ip6, 0, sizeof( *ip6 )); + } +} + /* ==================== NET_Init diff --git a/engine/common/net_ws.h b/engine/common/net_ws.h index 4a752cbf..791bff78 100644 --- a/engine/common/net_ws.h +++ b/engine/common/net_ws.h @@ -82,6 +82,8 @@ static inline qboolean NET_IsLocalAddress( netadr_t adr ) return NET_NetadrType( &adr ) == NA_LOOPBACK; } +void NET_GetLocalAddress( netadr_t *ip4, netadr_t *ip6 ); + #if !XASH_DEDICATED int CL_GetSplitSize( void ); #endif diff --git a/engine/common/netchan.h b/engine/common/netchan.h index d79eaaaf..cf0325fc 100644 --- a/engine/common/netchan.h +++ b/engine/common/netchan.h @@ -290,7 +290,6 @@ typedef struct netchan_s } netchan_t; extern netadr_t net_from; -extern netadr_t net_local; extern sizebuf_t net_message; extern byte net_message_buffer[NET_MAX_MESSAGE]; extern convar_t sv_lan;