Browse Source

[tcp] Store local port in host byte order

Every other scalar integer value in struct tcp_connection is in host
byte order; change the definition of local_port to match.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
43450342a9
1 changed files with 9 additions and 9 deletions
  1. 9
    9
      src/net/tcp.c

+ 9
- 9
src/net/tcp.c View File

37
 
37
 
38
 	/** Remote socket address */
38
 	/** Remote socket address */
39
 	struct sockaddr_tcpip peer;
39
 	struct sockaddr_tcpip peer;
40
-	/** Local port, in network byte order */
40
+	/** Local port */
41
 	unsigned int local_port;
41
 	unsigned int local_port;
42
 
42
 
43
 	/** Current TCP state */
43
 	/** Current TCP state */
166
  * Bind TCP connection to local port
166
  * Bind TCP connection to local port
167
  *
167
  *
168
  * @v tcp		TCP connection
168
  * @v tcp		TCP connection
169
- * @v port		Local port number, in network-endian order
169
+ * @v port		Local port number
170
  * @ret rc		Return status code
170
  * @ret rc		Return status code
171
  *
171
  *
172
  * If the port is 0, the connection is assigned an available port
172
  * If the port is 0, the connection is assigned an available port
182
 			try_port++;
182
 			try_port++;
183
 			if ( try_port < 1024 )
183
 			if ( try_port < 1024 )
184
 				continue;
184
 				continue;
185
-			if ( tcp_bind ( tcp, htons ( try_port ) ) == 0 )
185
+			if ( tcp_bind ( tcp, try_port ) == 0 )
186
 				return 0;
186
 				return 0;
187
 		}
187
 		}
188
 		DBGC ( tcp, "TCP %p could not bind: no free ports\n", tcp );
188
 		DBGC ( tcp, "TCP %p could not bind: no free ports\n", tcp );
193
 	list_for_each_entry ( existing, &tcp_conns, list ) {
193
 	list_for_each_entry ( existing, &tcp_conns, list ) {
194
 		if ( existing->local_port == port ) {
194
 		if ( existing->local_port == port ) {
195
 			DBGC ( tcp, "TCP %p could not bind: port %d in use\n",
195
 			DBGC ( tcp, "TCP %p could not bind: port %d in use\n",
196
-			       tcp, ntohs ( port ) );
196
+			       tcp, port );
197
 			return -EADDRINUSE;
197
 			return -EADDRINUSE;
198
 		}
198
 		}
199
 	}
199
 	}
200
 	tcp->local_port = port;
200
 	tcp->local_port = port;
201
 
201
 
202
-	DBGC ( tcp, "TCP %p bound to port %d\n", tcp, ntohs ( port ) );
202
+	DBGC ( tcp, "TCP %p bound to port %d\n", tcp, port );
203
 	return 0;
203
 	return 0;
204
 }
204
 }
205
 
205
 
235
 	memcpy ( &tcp->peer, st_peer, sizeof ( tcp->peer ) );
235
 	memcpy ( &tcp->peer, st_peer, sizeof ( tcp->peer ) );
236
 
236
 
237
 	/* Bind to local port */
237
 	/* Bind to local port */
238
-	bind_port = ( st_local ? st_local->st_port : 0 );
238
+	bind_port = ( st_local ? ntohs ( st_local->st_port ) : 0 );
239
 	if ( ( rc = tcp_bind ( tcp, bind_port ) ) != 0 )
239
 	if ( ( rc = tcp_bind ( tcp, bind_port ) ) != 0 )
240
 		goto err;
240
 		goto err;
241
 
241
 
480
 		flags |= TCP_PSH;
480
 		flags |= TCP_PSH;
481
 	tcphdr = iob_push ( iobuf, sizeof ( *tcphdr ) );
481
 	tcphdr = iob_push ( iobuf, sizeof ( *tcphdr ) );
482
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
482
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
483
-	tcphdr->src = tcp->local_port;
483
+	tcphdr->src = htons ( tcp->local_port );
484
 	tcphdr->dest = tcp->peer.st_port;
484
 	tcphdr->dest = tcp->peer.st_port;
485
 	tcphdr->seq = htonl ( tcp->snd_seq );
485
 	tcphdr->seq = htonl ( tcp->snd_seq );
486
 	tcphdr->ack = htonl ( tcp->rcv_ack );
486
 	tcphdr->ack = htonl ( tcp->rcv_ack );
612
 /**
612
 /**
613
  * Identify TCP connection by local port number
613
  * Identify TCP connection by local port number
614
  *
614
  *
615
- * @v local_port	Local port (in network-endian order)
615
+ * @v local_port	Local port
616
  * @ret tcp		TCP connection, or NULL
616
  * @ret tcp		TCP connection, or NULL
617
  */
617
  */
618
 static struct tcp_connection * tcp_demux ( unsigned int local_port ) {
618
 static struct tcp_connection * tcp_demux ( unsigned int local_port ) {
935
 	}
935
 	}
936
 	
936
 	
937
 	/* Parse parameters from header and strip header */
937
 	/* Parse parameters from header and strip header */
938
-	tcp = tcp_demux ( tcphdr->dest );
938
+	tcp = tcp_demux ( ntohs ( tcphdr->dest ) );
939
 	start_seq = seq = ntohl ( tcphdr->seq );
939
 	start_seq = seq = ntohl ( tcphdr->seq );
940
 	ack = ntohl ( tcphdr->ack );
940
 	ack = ntohl ( tcphdr->ack );
941
 	win = ntohs ( tcphdr->win );
941
 	win = ntohs ( tcphdr->win );

Loading…
Cancel
Save