]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[tcp] Randomise local TCP port
authorGuo-Fu Tseng <cooldavid@cooldavid.org>
Tue, 13 Jul 2010 16:24:01 +0000 (17:24 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 13 Jul 2010 16:29:54 +0000 (17:29 +0100)
Signed-off-by: Guo-Fu Tseng <cooldavid@cooldavid.org>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/tcp.c

index 67aa39f213e2e1f1b3c64666342c7c3859b97915..88411a4d71a4f3877174acda295ec21cb0d33391 100644 (file)
@@ -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;