|  | @@ -174,11 +174,13 @@ tcp_dump_flags ( struct tcp_connection *tcp, unsigned int flags ) {
 | 
		
	
		
			
			| 174 | 174 |   */
 | 
		
	
		
			
			| 175 | 175 |  static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
 | 
		
	
		
			
			| 176 | 176 |  	struct tcp_connection *existing;
 | 
		
	
		
			
			| 177 |  | -	static uint16_t try_port = 1023;
 | 
		
	
		
			
			|  | 177 | +	uint16_t try_port;
 | 
		
	
		
			
			|  | 178 | +	unsigned int i;
 | 
		
	
		
			
			| 178 | 179 |  
 | 
		
	
		
			
			| 179 |  | -	/* If no port specified, find the first available port */
 | 
		
	
		
			
			|  | 180 | +	/* If no port is specified, find an available port */
 | 
		
	
		
			
			| 180 | 181 |  	if ( ! port ) {
 | 
		
	
		
			
			| 181 |  | -		while ( try_port ) {
 | 
		
	
		
			
			|  | 182 | +		try_port = random();
 | 
		
	
		
			
			|  | 183 | +		for ( i = 0 ; i < 65536 ; i++ ) {
 | 
		
	
		
			
			| 182 | 184 |  			try_port++;
 | 
		
	
		
			
			| 183 | 185 |  			if ( try_port < 1024 )
 | 
		
	
		
			
			| 184 | 186 |  				continue;
 |