diff options
author | Guo-Fu Tseng <cooldavid@cooldavid.org> | 2010-07-13 17:24:01 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2010-07-13 17:29:54 +0100 |
commit | 1e7e4c9a611aca0f1dbb0f64ffe15af941867f87 (patch) | |
tree | f2ae1451c50ff71d94ffe1b334ddbca3b3290458 /src/net/tcp.c | |
parent | 73e3672468d1e71768783bb3ddccf44bc64da3e8 (diff) | |
download | ipxe-1e7e4c9a611aca0f1dbb0f64ffe15af941867f87.tar.gz |
[tcp] Randomise local TCP port
Signed-off-by: Guo-Fu Tseng <cooldavid@cooldavid.org>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/tcp.c')
-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; |