Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 0 additions & 13 deletions src/engine/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ CGameVM cgvm;
refexport_t re;

void CL_CheckForResend();
void CL_ShowIP_f();

#if defined(USE_MUMBLE)
static void CL_UpdateMumble()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2476,7 +2474,6 @@ void CL_Shutdown()
Cmd_RemoveCommand( "globalservers" );
Cmd_RemoveCommand( "ping" );
Cmd_RemoveCommand( "serverstatus" );
Cmd_RemoveCommand( "showip" );

CL_ClearKeyBinding();
CL_ClearInput();
Expand All @@ -2496,16 +2493,6 @@ void CL_Shutdown()

}

/*
==================
CL_ShowIP_f
==================
*/
void CL_ShowIP_f()
{
Sys_ShowIP();
}

/*
====================
CL_GetClipboardData
Expand Down
51 changes: 26 additions & 25 deletions src/engine/qcommon/net_ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ 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;

Expand Down Expand Up @@ -887,30 +890,34 @@ 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 );
Print( "Hostname: %s", hostname );

if ( localIP[ i ].type == netadrtype_t::NA_IP )
{
Log::Notice( "IP: %s", addrbuf );
}
else if ( localIP[ i ].type == netadrtype_t::NA_IP6 )
int i;
char addrbuf[ NET_ADDR_STR_MAX_LEN ];

for ( i = 0; i < numIP; i++ )
{
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;

//=============================================================================

Expand Down Expand Up @@ -1507,28 +1514,24 @@ static void NET_GetLocalAddress()
}

freeifaddrs( ifap );

Sys_ShowIP();
}
}

#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;
Expand Down Expand Up @@ -1564,8 +1567,6 @@ static void NET_GetLocalAddress()
NET_AddLocalAddress( "", search->ai_addr, ( struct sockaddr * ) &mask6 );
}
}

Sys_ShowIP();
}

if ( res )
Expand Down
1 change: 0 additions & 1 deletion src/engine/qcommon/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_