Tony
Tony

Reputation: 816

How does layer 3 (network layer) recognize the IP address?

Layer 2 (Ethernet layer) recognizes the MAC address using ARP protocol. It sends a question to the whole network asking: "Which MAC address has the IP x?". That's how it recognizes the destination MAC address.

But how does Layer 3 (IP layer) knows the IP address? It is not passed to it from the transport layer (layer 4). Only the port number is passed.

I hope I am specific. Thanks in advance.

Upvotes: 3

Views: 3286

Answers (3)

user207421
user207421

Reputation: 310911

But how does Layer 3 (IP layer) knows the IP address? It is not passed to it from the transport layer (layer 4). Only the port number is passed.

This isn't correct. Both TCP or UDP have an explicit bind() operation which does indeed pass an IP address. TCP also has an explicit connect() operation which also passes an IP address, and an implicit bind() operation where the source IP address is computed from the unicast IP routing tables.

Upvotes: 2

nitishch
nitishch

Reputation: 130

Every layer provides an interface to the layer above. It is through this interface that layer4 sends layer3, the destination IP address. layer5 (Application Layer) sends the destination IP address it wants to talk to, to layer4 which in turn sends it to layer3. Layer3 includes this in the IP packet and passes this packet to the layer2 (along with other things like MAC address of the destination etc..)

It is like giving arguments when you call a function. Suppose the interface provided by layer3 is send_packet(), layer4 calls it, may be, like send_packet(srcIP, destIP)

Upvotes: 2

Gerald P. Wright
Gerald P. Wright

Reputation: 796

There are two IP addresses associated with a packet, the sending (also know as source) IP and destination IP.

Sending IP - The sending IP is trivial, it is a configuration parameter of the network interface by which the packet will be transmitted. It is configured either statically or more typically in modern networks through DHCP.

Destination IP - The destination IP can be slightly more complex depending upon whether the destination computer is local or remote to the sending computer. In this case, remote means that the destination computer is not located in the same subnet as the source computer.

For remote destinations DNS servers are used for name<->IP resolution. DNS is what allows humans to use our strength, names such as www.espn.com, while computer can use their strength, bit representation of IP addresses such as 10.5.0.1. DNS resolution can be configured many different ways, but basically boils down to examining local cache to see if a prior resolution exists, and if not querying one or more DNS servers to resolve the request.

If the destination machine is local, on the same subnet, then ARP/RARP is used for MAC<->IP translation. Once again a cache is checked first, in this case the ARP cache, before creating a new ARP request (and thereby using network bandwidth).

I hope this helps.

Upvotes: 3

Related Questions