TCP Network Protocol – Do These 2 Packets Belong to the Same TCP Socket?

Networkprotocol-theorytcptransport-protocol

Let's say we have two packets A and B.

A: Has source-IP S1 , destination-IP D1 , source-port SP1 , destination-port DP1

B: Has source-IP S2 , destination-IP D1 , source-port SP2 , destination-port DP1

Both are TCP. Will both these packets have the same socket now?


About UDP I've read that its socket consists of the destination-IP and destination-port-number. Soo if this was done with UDP, both packets would be received by the same socket.

But this example is for TCP and here I'm not sure if it would also go through the same socket for TCP?

Best Answer

First, TCP does not care about single packets. If these are just data packets without any previous connection establishment than they will be simply dropped, no sockets involved. So I'm assuming that this is about established connections, or initial packets to establish a connection. A TCP connection is defined at least by the 4 tuple of (src-ip, src-port, dst-ip, dst-port). Since these 4 tuples are obviously different in both cases there will be different sockets needed.

About UDP I've read that its socket consists of the destination-IP and destination-port-number.

This is only true for unconnected UDP sockets. With connected UDP sockets again the 4-tuple is relevant.