From 774acbdeb679e7119fb65517133286d1471aac43 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 14 Mar 2025 05:29:27 -0500 Subject: [PATCH 1/3] Don't print local IPs (unless /showip is used) On my machine I get 3 of these link-local addresses for each of IPv4 and IPv6. I think only 1 of each type will even work for LAN connections. So these logs seem to be of limited benefit to users since one who has enough knowledge to know which one to use would have known how to look it up anyway. Furthermore, this information can make people hesitate to post logs due to concerns that they contain sensitive information. --- src/engine/qcommon/net_ip.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index 0b26f1c920..2e35eb3841 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -1507,8 +1507,6 @@ static void NET_GetLocalAddress() } freeifaddrs( ifap ); - - Sys_ShowIP(); } } @@ -1564,8 +1562,6 @@ static void NET_GetLocalAddress() NET_AddLocalAddress( "", search->ai_addr, ( struct sockaddr * ) &mask6 ); } } - - Sys_ShowIP(); } if ( res ) From 6a99423923fb9c0b47987c7c792ef40271cff967 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 14 Mar 2025 16:18:49 -0500 Subject: [PATCH 2/3] Make /showip available in the server It was only provided in the client before. But in fact it is only relevant for server-side networking. Also migrate it to new-style command. --- src/engine/client/cl_main.cpp | 13 ------------ src/engine/qcommon/net_ip.cpp | 37 +++++++++++++++++++---------------- src/engine/qcommon/sys.h | 1 - 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/engine/client/cl_main.cpp b/src/engine/client/cl_main.cpp index 639ed7ed6d..c073c081d0 100644 --- a/src/engine/client/cl_main.cpp +++ b/src/engine/client/cl_main.cpp @@ -151,7 +151,6 @@ CGameVM cgvm; refexport_t re; void CL_CheckForResend(); -void CL_ShowIP_f(); #if defined(USE_MUMBLE) static void CL_UpdateMumble() @@ -2400,7 +2399,6 @@ void CL_Init() Cmd_AddCommand( "ping", CL_Ping_f ); Cmd_AddCommand( "serverstatus", CL_ServerStatus_f ); - Cmd_AddCommand( "showip", CL_ShowIP_f ); Cmd_AddCommand( "updatescreen", SCR_UpdateScreen ); // done. @@ -2476,7 +2474,6 @@ void CL_Shutdown() Cmd_RemoveCommand( "globalservers" ); Cmd_RemoveCommand( "ping" ); Cmd_RemoveCommand( "serverstatus" ); - Cmd_RemoveCommand( "showip" ); CL_ClearKeyBinding(); CL_ClearInput(); @@ -2496,16 +2493,6 @@ void CL_Shutdown() } -/* -================== -CL_ShowIP_f -================== -*/ -void CL_ShowIP_f() -{ - Sys_ShowIP(); -} - /* ==================== CL_GetClipboardData diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index 2e35eb3841..b7b9a76411 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -170,6 +170,7 @@ struct nip_localaddr_t struct sockaddr_storage netmask; }; +// Used for Sys_IsLANAddress static nip_localaddr_t localIP[ MAX_IPS ]; static int numIP; @@ -887,30 +888,32 @@ bool Sys_IsLANAddress( const netadr_t& adr ) return false; } -/* -================== -Sys_ShowIP -================== -*/ -void Sys_ShowIP() +class ShowIPCommand : public Cmd::StaticCmd { - int i; - char addrbuf[ NET_ADDR_STR_MAX_LEN ]; +public: + ShowIPCommand() : StaticCmd("showip", Cmd::SERVER, "show addresses of network interfaces") {} - for ( i = 0; i < numIP; i++ ) + void Run( const Cmd::Args & ) const override { - Sys_SockaddrToString( addrbuf, sizeof( addrbuf ), ( struct sockaddr * ) &localIP[ i ].addr ); + int i; + char addrbuf[ NET_ADDR_STR_MAX_LEN ]; - if ( localIP[ i ].type == netadrtype_t::NA_IP ) + for ( i = 0; i < numIP; i++ ) { - Log::Notice( "IP: %s", addrbuf ); - } - else if ( localIP[ i ].type == netadrtype_t::NA_IP6 ) - { - Log::Notice( "IP6: %s", addrbuf ); + Sys_SockaddrToString( addrbuf, sizeof( addrbuf ), ( struct sockaddr * ) &localIP[ i ].addr ); + + if ( localIP[ i ].type == netadrtype_t::NA_IP ) + { + Print( "IP: %s", addrbuf ); + } + else if ( localIP[ i ].type == netadrtype_t::NA_IP6 ) + { + Print( "IP6: %s", addrbuf ); + } } } -} +}; +static ShowIPCommand showipRegistration; //============================================================================= diff --git a/src/engine/qcommon/sys.h b/src/engine/qcommon/sys.h index a4c655a44e..47eb44bca0 100644 --- a/src/engine/qcommon/sys.h +++ b/src/engine/qcommon/sys.h @@ -43,6 +43,5 @@ bool Sys_GetPacket(netadr_t *net_from, msg_t *net_message); bool Sys_StringToAdr(const char *s, netadr_t *a, netadrtype_t family); bool Sys_IsLANAddress(const netadr_t& adr); -void Sys_ShowIP(); #endif // ENGINE_QCOMMON_SYS_H_ From fefb80d0586d4034952e88105aacaf98446696b7 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 14 Mar 2025 16:35:55 -0500 Subject: [PATCH 3/3] Move logging of hostname to /showip This is an easily overlooked bit of potentially personally identifying information. It may be the "computer's name" on personal machines. So don't log it by default. --- src/engine/qcommon/net_ip.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index b7b9a76411..286ca5845e 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -170,6 +170,8 @@ struct nip_localaddr_t struct sockaddr_storage netmask; }; +// Used to get local IP list. Saved here just to ensure /showip shows the same one that we used +static char hostname[ 256 ]; // Used for Sys_IsLANAddress static nip_localaddr_t localIP[ MAX_IPS ]; static int numIP; @@ -895,6 +897,8 @@ class ShowIPCommand : public Cmd::StaticCmd void Run( const Cmd::Args & ) const override { + Print( "Hostname: %s", hostname ); + int i; char addrbuf[ NET_ADDR_STR_MAX_LEN ]; @@ -1516,20 +1520,18 @@ static void NET_GetLocalAddress() #else static void NET_GetLocalAddress() { - char hostname[ 256 ]; struct addrinfo hint; struct addrinfo *res = nullptr; numIP = 0; - if ( gethostname( hostname, 256 ) == SOCKET_ERROR ) + if ( gethostname( hostname, sizeof( hostname ) ) == SOCKET_ERROR ) { + *hostname = '\0'; return; } - Log::Notice( "Hostname: %s", hostname ); - memset( &hint, 0, sizeof( hint ) ); hint.ai_family = AF_UNSPEC;