Take the 2-minute tour ×
Network Engineering Stack Exchange is a question and answer site for network engineers. It's 100% free, no registration required.

This is from the book: "Computer Networking - A Top Down Approach" :

One subtle difference between a TCP socket and a UDP socket is that a TCP socket is identified by a four-tuple: (source IP address, source port number, destination IP address, destination port number). Thus, when a TCP segment arrives from the network to a host, the host uses all four values to direct (demultiplex) the segment to the appropriate socket.1

So when I look at TCP headers, such as the one below, I do not see any IP parts in the header.

TCP Header

How does TCP use IP information when passing the data to the correct socket?


1Kurose, J. F., & Ross, K. W. (2013). Computer networking: A top-down approach. Boston, Mass: Pearson.

share|improve this question

2 Answers 2

TCP header is located after the IP header, so the TCP/IP stack knows all four (and many more) values.

Those four values are used to form a unique connection ID ("socket"), which is used to recieve and send packets to/from the remote host.

share|improve this answer
    
Sorry I do not understand, TCP is after IP so in Transport Layer ( TCP layer ) when the data arrives, it does not have the IP information anymore.. The IP header is discarded already? There is only TCP header + payload? –  Koray Tugay Feb 21 at 6:35
    
The TCP/IP stack is not a ISO/OSI college theoretic model. When a packet comes to your computer, it gets parsed, first the destination mac is checked, and the info (src, dst mac, type) is stored in memory; then the IP header is checked, and the values stored, then the TCP header is checked, and those values are also stored. Your computer (kernel, stack,..) does not forget the IP header data, after it moves to the next header, so when you finish with the TCP header, you (your computers), knows all (or most) of the data from layers below. –  mulaz Feb 21 at 7:24
    
Ah thanks for the detailed information.. So a TCP socket is not "really" in the Transport layer. It uses information from all layers and a part of the OS. –  Koray Tugay Feb 21 at 9:10

In IPv4, the protocols are added onto each other. So the IP datagram header you've linked contains just, (among other things not related to this discussion) the IP addresses of the sender and receiver. TCP and UDP build "on top of" IP by adding more header information after the IP header; in that extra information lies the port numbers, (and more) for the two endpoints.

A quick google for "tcp packet header" will show you what the TCP layer adds on after the IP header.

(And the short answer to you Q "how can a TCP socket be identified by IP address?", is that it cannot be.)

share|improve this answer
    
What does "(And the short answer to you Q "how can a TCP socket be identified by IP address?", is that it cannot be.) this mean? –  Koray Tugay Feb 21 at 6:35
    
It means: A TCP socket cannot be identified by just the IP addresses of the end-points. –  Craig Constantine Feb 21 at 12:19
    
Who said it was identified by just the IP address? –  Koray Tugay Feb 22 at 6:03
    
That's the title of the OP's question: "How can a TCP socket be identified by IP address?" –  Craig Constantine Feb 22 at 12:05
    
The question says: "One subtle difference between a TCP socket and a UDP socket is that a TCP socket is identified by a four-tuple" –  Koray Tugay Feb 22 at 12:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.