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

…衆ロ難τιáo~ 提交于 2019-12-25 08:13:57

问题


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?


回答1:


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,



来源:https://stackoverflow.com/questions/9326732/do-transport-layer-tcp-and-udp-reads-inspects-ip-headers-source-ip-destinati

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!