summaryrefslogtreecommitdiffstats
path: root/src/net/tcp.c
diff options
context:
space:
mode:
authorGuo-Fu Tseng2010-07-13 18:24:01 +0200
committerMichael Brown2010-07-13 18:29:54 +0200
commit1e7e4c9a611aca0f1dbb0f64ffe15af941867f87 (patch)
treef2ae1451c50ff71d94ffe1b334ddbca3b3290458 /src/net/tcp.c
parent[tcp] Fix typos by changing ntohl() to htonl() where appropriate (diff)
downloadipxe-1e7e4c9a611aca0f1dbb0f64ffe15af941867f87.tar.gz
ipxe-1e7e4c9a611aca0f1dbb0f64ffe15af941867f87.tar.xz
ipxe-1e7e4c9a611aca0f1dbb0f64ffe15af941867f87.zip
[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.c8
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;