views:

171

answers:

4

An HTTP application request for www.stackoverflow.com. This message is passed to Transport layer. Transport layer adds its header and sends the packet to Internet Layer. The Internet Layer cannot see www.stackoverflow.com as it can only access the header which was appended by Transport Layer. Then how can Internet Layer decide route for this request packet.

How is the destination address field in IP header is filled, as only Application Layar and Transport Layer know about that field. (Application layer has no interaction with Internet Layer and Transport Layer mention port number in its Header.)

+1  A: 

The application layer would have already retrieved the IP address of the host from the URL via DNS. The IP address as well as other data from the Application layer are sent down to the Transport layer which packetizes the data and then send it down to the Internet layer and then it goes.

Recursion
But Internet Layer Cannot see the data part of the packet. It can only see the header attached by the Transport Layer. And in Transport Layer header there is no field which mentions the IP address of destination.
Mohit
That's because the IP addresses are in the IP header underneath TCP... see my answer.
Andrew McGregor
The IP packet holds that info with the tcp packet inside it. Think of the OSI model as those Russian dolls, where all the data above the lower level is inside that lower level. So the lowest level is working with the data from all the above levels and itself, while the highest level is only working with itself.
Recursion
+1  A: 

The application, in this case the browser, did something that ended up calling the getaddrinfo library function or something equivalent, which made the system's resolver look up the name in the DNS and return a set of IP addresses.

The application somehow chose one of those (there's standard ways to do this, but the lovely thing is how many standard ways) and used the connect system call to make the connection, which started the transport layer in the kernel working on getting a connection to that IP address.

That ends up creating IP packets with that destination address and the local address as the source, next protocol set to TCP and the SYN bit on in the TCP header. Each router on the path consults its tables and forwards the packet.

TCP magic happens, a SYN+ACK comes back, then there's a connection, over which HTTP magic happens, and the page loads.

Andrew McGregor
I suppose you did not get the question. Please see the revised question.
Mohit
The Internet does not run on the OSI model. There are a LOT of cross-layer linkages that completely scramble the nice neat OSI model. Applications DO handle IP addresses, and pass them all the way down the stack. So your assertion that there is clean isolation between the layers is simply incorrect.
Andrew McGregor
To expand on that: there is a side channel alongside the packet as it goes down the stack, so that every layer has access to everything that was passed to the system calls that caused the creation of the socket and the transmission of a particular packet, including all the IP addresses. This data is partially stored on the socket, and partially on an auxiliary structure attached to the packet itself.
Andrew McGregor
A: 

rfc791 IP - Addressing

A distinction is made between names, addresses, and routes [4]. A name indicates what we seek. An address indicates where it is. A route indicates how to get there. The internet protocol deals primarily with addresses. It is the task of higher level (i.e., host-to-host or application) protocols to make the mapping from names to addresses. The internet module maps internet addresses to local net addresses. It is the task of lower level (i.e., local net or gateways) procedures to make the mapping from local net addresses to routes. Addresses are fixed length of four octets (32 bits).

Read more: http://www.faqs.org/rfcs/rfc791.html#ixzz0buBJkVEI

It is the task of higher level (i.e., host-to-host or application) protocols to make the mapping from names to addresses ???

Tommy
I suppose you did not get the question. Please see the revised question.
Mohit
A: 

If you want to know how the actual IP header gets the address. It occurs in the Kernel, when a socket is created. In this case a TCP socket, Check out

man 7 ip

The data is not inherited from the TCP packet, though the data is included in the checksum of the TCP header.

Recursion