Sumit Trehan
Sumit Trehan

Reputation: 4035

Do Transport Layer (TCP and UDP) reads/inspects IP headers (Source IP, Destination IP etc.)?

We all know that a TCP socket is identified by a four tuple entry: src ip, dest ip, src port dest port

TCP does the job of Multiplexing and Demultiplexing the Data from/to differnt processes running on the host.

In case of Demultiplexing, Destination IP information is there only in IP Headers. How come Dest IP is read by Transport Layer (TCP)?

Plz explain I m very much confused?

Upvotes: 1

Views: 302

Answers (1)

Eugen Rieck
Eugen Rieck

Reputation: 65264

What is called TCP in this context, is in reallity TCP/IP as in TCP over IP (UDP/IP is the same thing). In fact, [TC|UD]P and IP are extremly interwoven codewise in all major current socket implementations.

The socket itself works from the IP layer upward, thus it has the Destination IP info, only the socket protocol handler specialises this to TCP. So by calling

socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)

(Or its equivalents in other languages) you will create an IP socket (first parameter), that uses TCP (3rd parameter). This implies, that the socket has the IP information as well as the TCP info,

Upvotes: 2

Related Questions