Browse Source

Avoid reusing auto-allocated ports after connection close.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
d5735c631c
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      src/net/tcp.c

+ 3
- 2
src/net/tcp.c View File

@@ -160,11 +160,12 @@ tcp_dump_flags ( struct tcp_connection *tcp, unsigned int flags ) {
160 160
  */
161 161
 static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
162 162
 	struct tcp_connection *existing;
163
-	static uint16_t try_port = 1024;
163
+	static uint16_t try_port = 1023;
164 164
 
165 165
 	/* If no port specified, find the first available port */
166 166
 	if ( ! port ) {
167
-		for ( ; try_port ; try_port++ ) {
167
+		while ( try_port ) {
168
+			try_port++;
168 169
 			if ( try_port < 1024 )
169 170
 				continue;
170 171
 			if ( tcp_bind ( tcp, htons ( try_port ) ) == 0 )

Loading…
Cancel
Save