Reputation: 259
As far as I know, TCP needs four values to do the TCP multiplexing on client side and demultiplexing on server side:
The port numbers are part of the TCP header, but the IP-addresses aren't part of the TCP header, they belong to the IP header.
Questions:
How does the TCP-implementation on each host side get informed about the necessary IP-Adresses?
When creating a TCP-Socket Socket mySocket = new Socket(remoteIPNr,remotePortNr)
one is specifying the remote IP address. But this happens on the application layer. So how does the socket transport that remote-IP-address to the transport layer? Furthermore, how does TCP get informed about the source-IP-address?
Upvotes: 0
Views: 1273
Reputation: 310979
how does the socket transport that remote-IP-address to the transport layer?
It gets to the transport layer the same way any system call parameter gets into the kernel. That's what system call parameters are for. There's no mystery here just because it's an IP address. The same applies to the target port number, for example.
If you're asking how does TCP get to see the IP header, you are assuming wrongly that it can't. It can.
Furthermore, how does TCP get informed about the source-IP-address?
The source IP address is either defined by the application in a bind()
call or else supplied by default by TCP when you issue connect():
The IP routing tables are consulted to determine which local IP address is the cheapest route to the target address, and that address becomes the source address of the socket.
And for the next question you didn't ask, about the source port, either a source port was specified by the application in a bind()
call or else the system finds a free port number and uses that as the source port.
Upvotes: 1