From: Guo-Fu Tseng <[email protected]> To reduce possible TCP port collision.
Signed-off-by: Guo-Fu Tseng <[email protected]> --- src/net/tcp.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/tcp.c b/src/net/tcp.c index 20bcf51..9241572 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -176,13 +176,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, try_limit = 64512; + try_port = ( currticks() % 64512 ) + 1023; /* If no port specified, find the first available port */ if ( ! port ) { - while ( try_port ) { - try_port++; - if ( try_port < 1024 ) + while ( try_limit-- ) { + while ( ++try_port < 1024 ) continue; if ( tcp_bind ( tcp, htons ( try_port ) ) == 0 ) return 0; -- 1.7.1 _______________________________________________ gPXE-devel mailing list [email protected] http://etherboot.org/mailman/listinfo/gpxe-devel
