Beispiel #1
0
/* After we send our login information, the server responds with a status code
	to say whether it succeeded or not. */
static void socks5_auth_reply(char *data, int len, proxy_info_t *info)
{
	/* Abort if it's an invalid reply. */
	if (len < 2) {
		socks5_err(info, ECONNABORTED, "Invalid reply from SOCKS5 server");
		return;
	}

	if (data[1] != 0) {
		/* Authentication failed! */
		socks5_err(info, ECONNREFUSED, "SOCKS5 authentication failed");
	}
	else {
		/* Send the connection request. */
		send_connect_request(info);
		info->status = 3;
	}
}
Beispiel #2
0
/* This parses the server's auth method reply. Basically, when we connect
	we send the server a list of authentication methods we support. Then
	the server picks one and sends it back. This procedure identifies
	which one was chosen, and then sends the proper login sequence. */
static void socks5_auth_method(char *data, int len, proxy_info_t *info)
{
	char buf[520];

	/* If it's a bad reply, abort. */
	if (len < 2) {
		socks5_err(info, ECONNABORTED, "Invalid reply from SOCKS5 server");
		return;
	}

	if (data[0] != 5) {
		socks5_err(info, ECONNABORTED, "SOCKS5 server replied with SOCKS4 protocol");
		return;
	}

	if (data[1] == 0) {
		/* No auth required. */
		send_connect_request(info);
		info->status = 3;
	}
	else if (data[1] == 2) {
		/* User/password authentication */
		int ulen, plen;
		char buf[520];

		/* Username and password can be 255 max. */
		ulen = strlen(info->username) % 255;
		plen = strlen(info->password) % 255;

		buf[0] = 1;
		buf[1] = ulen;
		memcpy(buf+2, info->username, ulen);
		buf[2+ulen] = plen;
		memcpy(buf+2+ulen+1, info->password, plen);
		sockbuf_write(info->our_idx, buf, 1+1+ulen+1+plen);
		info->status = 2;
	}
	else {
		/* We can't authenticate with this server, boo. */
		socks5_err(info, ECONNABORTED, "SOCKS5 server doesn't accept our methods of authentication");
	}
	return;
}
void handle_application_packet( void * buffer, int len , int dest_id)
{



        int send_id ;    
        int seq_n  =  0;     
        int mtu_p = 100; 
        int total_p = 0; 
	int count  = 0 ;
        int cid  = 0 ;
	int send_len = len;
	send_id = allocate_sender();
        printf("\n sender id = %d"  , send_id); 	
        send_connect_request(dest_id,send_id);
        usleep(WAIT_TIME_ACK);   
	if ( sender_buffer[send_id].response_code == CONTROL_CONNECT_ACK )
	{
                printf("\n  Connect  ack received ! " ); 
                mtu_p = sender_buffer[send_id].mtu_possible;  
                cid =  sender_buffer[send_id].connection_id; 
	        printf("\n CID = %d " , cid); 
	        printf("\n window size = %d " ,mtu_p); 	
	}
	seq_n++;
	total_p =   len / mtu_p ; 
	if ( len % mtu_p != 0 )
	{
		total_p++;
	}
	
	for ( count  = 1 ; count  <= total_p ; count++)
	{
		send_len -= mtu_p;
		if ( send_len >= 0 )
		
		{
	          
		   if ( send_data_packet_reliable( dest_id , seq_n  , cid, send_id , buffer , mtu_p ) )
		   {
		       buffer =  (char *)buffer +  mtu_p; 

		   }
		   else
		   {
		       fprintf(stderr, "\n Unable send the data packet reliably after many retry's , something terribly wrong !\n Please retry after sometime \n ");

		         
		   }
		      
		}
		else 
		{
		   if ( send_data_packet_reliable( dest_id , seq_n  , cid, send_id , buffer ,send_len+ mtu_p ) == FALSE )
		   {

		 
		       fprintf(stderr, "\n Unable send the data packet reliably after many retry's , very unreliable data path , i can't help it !\n Please retry after sometime \n ");

		   }
		         
		  
		
		}
           	seq_n++;


	}
	if ( send_fin_packet_reliable(dest_id , cid , send_id) == FALSE )
	{

	    fprintf(stderr, "\n Unable send the fin packet reliably after many retry's , very unreliable data path , can't help it !\n Please retry after sometime \n ");

	}
	
       deallocate_sender(send_id);   
       send_close_request(dest_id  ,  cid  , send_id);
           	  
               


}