简体   繁体   中英

How IP address information is propagated from the TCP layer to the IP layer?

In TCP/IP model, it shows that the application layer message is sent to the TCP layer which breaks it up into segments and adds the source and destination ports to its segment headers, and then to the IP layer which encapsulates each incoming TCP segment into an IP packet and adds the source and destination IP addresses in its packet headers.

How are the source/destination IP addresses propagated to the IP layer as it just (supposedly) receives a TCP segment which only contains the source/destination ports?

Is some other metadata also sent across the layers which maintains this IP address information from the application layer to the IP layer through the TCP layer?

In general, all the layers happen to be crossed even before the packet leaves your computer. The layer point of view can be misleading because it is not in the way one would think of layers. In the fully layered point of view, you have separate layers and each layer is independent of the last. With networks, it is not really the case.

The application (layer 7) creates a socket with the socket() function. The socket function returns a pseudo file handle which is passed to the subsequent functions to establish a connection. After this, the application creates a structure which comprises the port (layer 4) used and the destination IP address (layer 3). Then, the application calls connect and the OS will encapsulate all this into a packet with the local MAC addresses (layer 2) to be used on the local network. The packet then leaves the computer on a physical medium (layer 1).

You see that the packet has crossed all layers to end up on a physical medium even before it quits your computer. The OS thus have a full context to create a proper packet to send to the router. The "application" layer can be misleading because in general it doesn't represent an actual application like a program. I would say that, in a real world scenario, the application is responsible to do everything down to layer 3 and then the OS handles layer 2 and 1 using the routing table and such.

The layer point of view is not one where layer 3 is crossed only when the packet changes network. Layer 3 is crossed when the TCP packet containing the ports is encapsulated into a packet with the destination and source IP addresses. This all happens in your computer before being encapsulated into a packet with the destination and source MAC addresses and being sent on a physical medium. The OS thus have the full context to create proper packets to send over the physical medium.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM