diff options
-rw-r--r-- | src/net/tcp.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/net/tcp.c b/src/net/tcp.c index 67aa39f2..88411a4d 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -174,11 +174,13 @@ tcp_dump_flags ( struct tcp_connection *tcp, unsigned int flags ) { */ static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) { struct tcp_connection *existing; - static uint16_t try_port = 1023; + uint16_t try_port; + unsigned int i; - /* If no port specified, find the first available port */ + /* If no port is specified, find an available port */ if ( ! port ) { - while ( try_port ) { + try_port = random(); + for ( i = 0 ; i < 65536 ; i++ ) { try_port++; if ( try_port < 1024 ) continue; |