Skip to content

Commit

Permalink
Avoid reusing auto-allocated ports after connection close.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brown committed Jul 13, 2007
1 parent 2ac7694 commit d5735c6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/net/tcp.c
Expand Up @@ -160,11 +160,12 @@ 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 = 1024;
static uint16_t try_port = 1023;

/* If no port specified, find the first available port */
if ( ! port ) {
for ( ; try_port ; try_port++ ) {
while ( try_port ) {
try_port++;
if ( try_port < 1024 )
continue;
if ( tcp_bind ( tcp, htons ( try_port ) ) == 0 )
Expand Down

0 comments on commit d5735c6

Please sign in to comment.