L2packets: add getsockname() to net layer
sniff gameclient: add option to bind outcoming socket to some port (TeonPvP hacks)
This commit is contained in:
parent
99d453d594
commit
47d580dae8
@ -36,6 +36,24 @@ bool GameClient::PC_sniff( SOCKET scl, unsigned char *sip, unsigned short int sp
|
||||
return false;
|
||||
}
|
||||
|
||||
// TeonPVP hack
|
||||
if( g_cfg.TeonPvP_hacks )
|
||||
{
|
||||
unsigned short teon_port = 43880;
|
||||
log_error( LOG_WARNING, "TeonPvP hacks: bind to port %d\n", teon_port );
|
||||
int rr = L2PNet_bind( sg, "0.0.0.0", teon_port );
|
||||
if( rr != 0 )
|
||||
log_error( LOG_ERROR, "TeonPvP hacks: bind failed!!!!\n" );
|
||||
sockaddr_in soaddr;
|
||||
memset( &soaddr, 0, sizeof(soaddr) );
|
||||
rr = L2PNet_getsockname( (SOCKET)sg, &soaddr );
|
||||
if( rr == 0 )
|
||||
{
|
||||
log_error( LOG_OK, "TeonPvP hacks: Bound outcome socket to address %s:%d\n",
|
||||
L2PNet_inet_ntoa(soaddr.sin_addr), (int)L2PNet_ntohs(soaddr.sin_port) );
|
||||
}
|
||||
}
|
||||
|
||||
// connect to real game server
|
||||
log_error( LOG_DEBUG, "GameClient::ProcessClient_onlySniff(): Connecting to real game server %s:%d ", ssip, (int)sport );
|
||||
L2PNet_connect( sg, ssip, sport );
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
// network function pointers table
|
||||
#define l2pnet_ft_size 11
|
||||
void *l2pnet_ft[l2pnet_ft_size] = {0, 0,0,0, 0,0,0, 0,0,0, 0};
|
||||
#define l2pnet_ft_size 12
|
||||
void *l2pnet_ft[l2pnet_ft_size] = {0, 0,0,0, 0,0,0, 0,0,0, 0,0}; // winsock override function table
|
||||
CRITICAL_SECTION l2pnet_cs;
|
||||
// winsock2 functions
|
||||
HINSTANCE l2pnet_hws2_32;
|
||||
void *ws2_func[l2pnet_ft_size] = {0, 0,0,0, 0,0,0, 0,0,0, 0};
|
||||
void *ws2_func[l2pnet_ft_size] = {0, 0,0,0, 0,0,0, 0,0,0, 0,0};
|
||||
char l2pnet_static_inet_ntoa_buffer[32];
|
||||
|
||||
typedef int (__stdcall *select_func)( int, fd_set *, fd_set *, fd_set *, const struct timeval *);
|
||||
@ -19,6 +19,7 @@ typedef int (__stdcall *WSACleanup_func)(void);
|
||||
//typedef void *(__stdcall *gethostbyname_func)( const char * );
|
||||
typedef int (__stdcall *getaddrinfo_func)( const char *, const char *, void *, void * ); /* Success returns zero. Failure returns error code */
|
||||
typedef void (__stdcall *freeaddrinfo_func)( void * );
|
||||
typedef int (__stdcall *getsockname_func)( unsigned int, void *, void * );
|
||||
|
||||
//select_func select_winsock = NULL;
|
||||
|
||||
@ -57,6 +58,7 @@ int L2PNet_InitDefault()
|
||||
ws2_func[L2PFUNC_SELECT] = (void *)GetProcAddress( l2pnet_hws2_32, "select" );
|
||||
ws2_func[L2PFUNC_SOCKET] = (void *)GetProcAddress( l2pnet_hws2_32, "socket" );
|
||||
ws2_func[L2PFUNC_LISTEN] = (void *)GetProcAddress( l2pnet_hws2_32, "listen" );
|
||||
ws2_func[L2PFUNC_GETSOCKNAME] = (void *)GetProcAddress( l2pnet_hws2_32, "getsockname" );
|
||||
for( i=1; i<l2pnet_ft_size; i++ )
|
||||
{
|
||||
if( ws2_func[i] == NULL )
|
||||
@ -632,3 +634,17 @@ bool L2PNet_resolveHostname( const char *hostname, struct in_addr *pinAddr )
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int L2PNet_getsockname( unsigned int sock, struct sockaddr_in *saddr )
|
||||
{
|
||||
int ret = -1;
|
||||
int addrlen = sizeof(sockaddr_in);
|
||||
getsockname_func proxy_getsockname = (getsockname_func)l2pnet_ft[L2PFUNC_GETSOCKNAME]; // find override
|
||||
if( proxy_getsockname == NULL ) // no overrides
|
||||
proxy_getsockname = (getsockname_func)ws2_func[L2PFUNC_GETSOCKNAME]; // call original
|
||||
if( proxy_getsockname == NULL ) // still??
|
||||
return -1;
|
||||
ret = proxy_getsockname( sock, (void *)saddr, (void *)&addrlen );
|
||||
return ret;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ int L2PNet_Cleanup();
|
||||
#define L2PFUNC_SELECT 8
|
||||
#define L2PFUNC_SOCKET 9
|
||||
#define L2PFUNC_LISTEN 10
|
||||
#define L2PFUNC_GETSOCKNAME 11
|
||||
/** Overrides specified function for L2Packets network layer.\n
|
||||
* New function must have the same prototype as corresponding
|
||||
* L2PNet_* function!
|
||||
@ -192,4 +193,12 @@ int L2PNet_FD_ISSET( unsigned int sock, fd_set *set );
|
||||
*/
|
||||
bool L2PNet_resolveHostname( const char *hostname, struct in_addr *pinAddr );
|
||||
|
||||
|
||||
/** Gets local socket address.\n
|
||||
* \param sock socket
|
||||
* \param saddr output struct that receives address
|
||||
* \return 0 on success
|
||||
*/
|
||||
int L2PNet_getsockname( unsigned int sock, struct sockaddr_in *saddr );
|
||||
|
||||
#endif /* H_L2P_NET_LAYER */
|
||||
|
Loading…
Reference in New Issue
Block a user