library/src/network/BP-Network.cc
// generate a SOCKS5 Greeting Packet for Proxy
generate a SOCKS5 Greeting Packet for Proxy
generate a SOCKS5 Greeting Packet for Proxy
P_BP_NETWORK_PACKET_DATA BP_NetProxyCreateSOCKS5InitialNegotiation(P_BP_NETWORK_HANDLE net_handle, P_BP_NETWORK_PROXY proxy)
{
	if(!net_handle)
		return NULL;
	if(!proxy)
		return NULL;
	P_BP_NETWORK_PACKET_DATA greeting_packet = (P_BP_NETWORK_PACKET_DATA) bpcalloc(sizeof(BP_NETWORK_PACKET_DATA), 1);
	if(!greeting_packet)
		return NULL;
	P_BP_LINKL socks5_greeting = BP_CreateLinkL("socks5 greeting", BP_TRUE);
	BYTE * version_number     = (BYTE *)     tq_calloc(socks5_greeting, 1, 1, BPLN);
	BYTE * num_auth_methods_supported = (BYTE *) tq_calloc(socks5_greeting, 1, 1, BPLN);
	version_number[0] = (BYTE) 0x05;
	num_auth_methods_supported[0] = (BYTE) 0x01;
	BYTE * user_password_given = (BYTE *) NULL;
	if(proxy->user || proxy->pass)
	{
		user_password_given = (BYTE *) tq_calloc(socks5_greeting, 1, 1, BPLN);
		user_password_given[0] = (BYTE) 0x02;
	}
	else 
	{
		user_password_given = (BYTE *) tq_calloc(socks5_greeting, 1, 1, BPLN);
		user_password_given[0] = (BYTE) 0x00;
	}
	BP_LinkLFlattenRaw(socks5_greeting);
	greeting_packet->data   = (BYTE *) bpcalloc(socks5_greeting->flat_buff_n, 1);
	memcpy(greeting_packet->data, socks5_greeting->flat_buff, socks5_greeting->flat_buff_n);
	greeting_packet->data_n = socks5_greeting->flat_buff_n;
	BP_DestroyLinkL(socks5_greeting, BP_TRUE);
	return greeting_packet;
}
P_BP_NETWORK_PACKET_DATA BP_NetProxyCreateSOCKS5InitialNegotiation ( P_BP_NETWORK_HANDLE net_handle , P_BP_NETWORK_PROXY proxy ) { if ( ! net_handle ) return NULL ; if ( ! proxy ) return NULL ; P_BP_NETWORK_PACKET_DATA greeting_packet = ( P_BP_NETWORK_PACKET_DATA ) bpcalloc ( sizeof ( BP_NETWORK_PACKET_DATA ) , 1 ) ; if ( ! greeting_packet ) return NULL ; P_BP_LINKL socks5_greeting = BP_CreateLinkL ( " " , BP_TRUE ) ; BYTE * version_number = ( BYTE * ) tq_calloc ( socks5_greeting , 1 , 1 , BPLN ) ; BYTE * num_auth_methods_supported = ( BYTE * ) tq_calloc ( socks5_greeting , 1 , 1 , BPLN ) ; version_number [ 0 ] = ( BYTE ) 0x05 ; num_auth_methods_supported [ 0 ] = ( BYTE ) 0x01 ; BYTE * user_password_given = ( BYTE * ) NULL ; if ( proxy -> user || proxy -> pass ) { user_password_given = ( BYTE * ) tq_calloc ( socks5_greeting , 1 , 1 , BPLN ) ; user_password_given [ 0 ] = ( BYTE ) 0x02 ; } else { user_password_given = ( BYTE * ) tq_calloc ( socks5_greeting , 1 , 1 , BPLN ) ; user_password_given [ 0 ] = ( BYTE ) 0x00 ; } BP_LinkLFlattenRaw ( socks5_greeting ) ; greeting_packet -> data = ( BYTE * ) bpcalloc ( socks5_greeting -> flat_buff_n , 1 ) ; memcpy ( greeting_packet -> data , socks5_greeting -> flat_buff , socks5_greeting -> flat_buff_n ) ; greeting_packet -> data_n = socks5_greeting -> flat_buff_n ; BP_DestroyLinkL ( socks5_greeting , BP_TRUE ) ; return greeting_packet ; }
generate a SOCKS5 Greeting Packet for Proxy
generate a SOCKS5 Greeting Packet for Proxy
// ensure we have a handle and a proxy pointer // greeting packet // ensure we created the structure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Packet using LinkL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // LinkL is later flattened to become the packet. // create linkl for generating greeting (ez mode) // allocate one byte for version number // number of authentication methods supported // set version number (5 for socks5) // set the number of methods supported (will always be 1 pass or no-pass) // check if a username/password was provided // create space in buffer // set the buffer // no user/password set // create space in buffer // set the buffer // Flatten the tail queue to generate socks4a greeting packet // allocate space for returning buffer // copy in data // set the size in the packet // destroy the linkl // return the greeting packet