Doubt in networklayer

baker123

Junior Member
Mar 21, 2014
2
0
0
Guys am not sure it is the right section to ask , just one doubt

How network layer adds destination IP address to its header , the transport protocol header does NOT contain anything about the IP address (or host name). So, from where does the layer 3 brings the destination IP address?

my understanding in TCP/IP layer is

1: Data---> Transport layer [App layer to transport layer]
2:TCPheader+ data --> Network layer [transport to network layer]

In third stage , IP header is attaching to data , and the IP address of destinaion is putting in to IP header

but my doubt is from where the network layer, is getting the destination address...?
 

Gryz

Golden Member
Aug 28, 2010
1,551
204
106
This is how it works.

Users types a hostname. (Or an URL, which contains a hostname. Or a raw IP address).
Software does a gethostbyname() library call.
This is a library call that uses the Domain Name System to resolve hostnames to IP-addresses.
Software finds the IP address that belongs to the hostname.
Software opens a socket. This is kinda like a filedescriptor that does not point to a file, but points to a socket on another machine. The two sockets are connected via a TCP-connection.

So basically the network layer is told what the destination address is by the transport layer. Not inside the TCP segment. But through the API that lies between the network layer and the transport layer.
 

baker123

Junior Member
Mar 21, 2014
2
0
0
great , now i am getting to it ..

but my understanding was , from transport to network layer , the only data that passing is TCPheader+data , and in this IP address is not available though.
 

Gryz

Golden Member
Aug 28, 2010
1,551
204
106
great , now i am getting to it ..

but my understanding was , from transport to network layer , the only data that passing is TCPheader+data , and in this IP address is not available though.

First of all, both the TCP and IP software/module/driver live inside the kernel. In most OSs. So we don't even know exactly what is going on there.

But it's not so hard to imagine. Before the user can pass data to TCP, and before TCP can pass data to IP, there needs to be a connection established. Or, if you only look at the local side, there needs to be a socket created.

When the socket (aka connection) is initialized before usage, the remote IP address is given (by the application) in the connect(3) library call.
http://linux.die.net/man/3/connect

If you want to understand how this works, best is to write a simple C program yourself. Write 2 different programs. One that creates a socket, listens to it, and copies all incoming data to standard output. Then write a second program, that opens a socket, connects to another machine, and then reads all data from standard input, and copies it into the socket.

You start the 2 programs on different machines. You type on one machine, and see your words show up on the other machine. It's not very hard (if you've done a little programming before, and if you have access to 2 linux/unix machines somewhere). Should take you 1 or 2 afternoons to figure it out. But once your code is working, I guarantee you understand very well how this all works.
 

alkemyst

No Lifer
Feb 13, 2001
83,967
19
81
With encapsulation and decapsulation all the 'data' is there. Only some of it is relevant to the forwarder.
 

VulgarDisplay

Diamond Member
Apr 3, 2009
6,193
2
76
I think you are looking at combinations of different things to get the destination address in your layer three header. If your transport layer is requesting a connection it will likely send out a broadcast and waiting for a reply to determine the destination IP address before sending out the data. If its requesting a connection based on a domain it will use a DNS to find the destination IP. From layer 3 to layer 2 ARP is used to find the MAC address for the layer 2 frame.

I'm s learning everything so hopefully others will correct any mistakes in my post.
 

SecurityTheatre

Senior member
Aug 14, 2011
672
0
0
The transport layer (Layer 4) does not care about addresses. It just doesn't. It is designed to manage host connectivity, delivery of data, reliability and some other things. It just assumes that the packet will be delivered to the correct address. This is what TCP/UDP/ICMP does. It handles sequence IDs and uses destination/source ports.

The network layer (Layer 3) worries about the source/destination addresses and delivery, but does not care what the content is, except for a flag that specifies the general type of frame. This is what IP/IPX does. It uses IP addresses.

The data-link layer (Layer 2) does not care about the destination. It only cares about the next hop. It has no idea what the data is, nor what the destination is. It only knows that it must deliver to a specific device on the local LAN. This is the what Ethernet MAC does. It uses a MAC address.
 

Gryz

Golden Member
Aug 28, 2010
1,551
204
106
The transport layer (Layer 4) does not care about addresses. It just doesn't.
Except that TCP does need to know the layer-3 IP addresses. It uses them when computing the TCP-checksum for every segment. Nitpicking, I know. But the separation between layers isn't as clear in TCP/IP as it could have been.

Besides, I don't think the OP was asking about these things. If I understood correctly, he just didn't seem to realize that in a software stack, there is more data being passed around between layers in the stack, than just the user data.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |