How does the ping command really work? Specifically where does the ARP (Address Resolution Protocol) come into picture?

I was asked this question in an interview and I was not able to come up with a scenario when ARP could be used.

link|improve this question
Look into ICMP. – Mikaveli May 3 '11 at 12:40
1  
This is not a programming question. – unwind May 3 '11 at 12:41
1  
ARP is used to get the MAC address of a specific IP address. When you need to send a packet on ethernet you need the MAC address of the destination. – Ankur May 3 '11 at 12:42
feedback

migrated from stackoverflow.com May 3 '11 at 12:56

This question came from our site for professional and enthusiast programmers.

4 Answers

Ping is actually two different ICMP (Internet Control Message Protocol) packets.

To ping a host you first send a ICMP Echo Request Packet, the host will then reply with an ICMP Echo Reply.

For more information see: http://en.wikipedia.org/wiki/Ping

link|improve this answer
+1 for mention ICMP – 0verbose May 3 '11 at 12:47
feedback

Ping and ARP are different things located at different layers in the network protocol stack.

Ping is at network layer (or Internet layer - Have a look to ICMP protocol like pointed out by @ServerMonkey).

Arp protocol is at link level (a lower level). Arp protocol is designed to allow physical connection between network hardware, that is directly connected.

In TCP/IP network stack, every layer uses the layer below to forward its data, encapsulating it inside the low level protocol. Each layer is independent from the other and possibly unaware of the other levels specific details and implementations (this is not always true: see cross-layer function).

link|improve this answer
yes.but ping implementation would require some code at L2 (link layer.).does ARP come into play at Layer 2. – liv2hak May 3 '11 at 12:43
@liv2hak. no. ping implementation lay on the below link layer. – 0verbose May 3 '11 at 12:45
feedback

This is a great trick question because you have to know that ping is an ICMP Echo Request; and that ICMP msgs are carried in IP datagrams; and therefore that any ARP activity has to arise from within the IP context. Really a good question.

link|improve this answer
feedback

If you really want to understand, there is an excellent (very well written) white paper here:

http://images.globalknowledge.com/wwwimages/whitepaperpdf/WP_Mays_Ping.pdf

Here is the summary ->

Ping (Program on the application layer) ------->
Opens a 'raw' socket to IP Layer ------>
IP layer (Layer 2 on OSI) packages ICMP packet and sends it

Since there is no TCP layer in between, the Ping (program) has to monitor all the incoming ICMP packets and filter only the one's from the destination.

Hope that helps.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.