Bladeren bron

[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>
tags/v1.20.1
Guo-Fu Tseng 14 jaren geleden
bovenliggende
commit
1e7e4c9a61
1 gewijzigde bestanden met toevoegingen van 5 en 3 verwijderingen
  1. 5
    3
      src/net/tcp.c

+ 5
- 3
src/net/tcp.c Bestand weergeven

@@ -174,11 +174,13 @@ tcp_dump_flags ( struct tcp_connection *tcp, unsigned int flags ) {
174 174
  */
175 175
 static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
176 176
 	struct tcp_connection *existing;
177
-	static uint16_t try_port = 1023;
177
+	uint16_t try_port;
178
+	unsigned int i;
178 179
 
179
-	/* If no port specified, find the first available port */
180
+	/* If no port is specified, find an available port */
180 181
 	if ( ! port ) {
181
-		while ( try_port ) {
182
+		try_port = random();
183
+		for ( i = 0 ; i < 65536 ; i++ ) {
182 184
 			try_port++;
183 185
 			if ( try_port < 1024 )
184 186
 				continue;

Laden…
Annuleren
Opslaan