LAN Hosts – Do They Know Their MAC Addresses?

arpmac address

I am trying to learn about how ARP protocol works in LANs. So, here is the physical structure of my network: enter image description here

So, when I try to ping PC3 from PC1, I expected the first packet to timeout because PC1 at first does not have the MAC address for PC3, so it should do an ARP request to get the MAC address first.

Now, when I pinged, all the packets arrived successfully!

enter image description here

My question is: Why is there no timeout? How did the packet arrive without knowing PC3's MAC address?

Best Answer

short answer: the first packet is not sent out before ARP completes. In order to send a packet, the sender (usually operating system) needs to fill out its IP and Ethernet header. Thus it cannot send a packet before MAC of P3 is known, i.e. ARP completes.

long answer:

The idea of what happens on the host is following.

  • application (ping) gets an address (this can be an IP address or host name, in the latter case there are more steps)
  • application creates an ICMP echo request packet with destination IP (i am not quite sure, but according to here application only creates an ICMP without IP header)
  • application invokes corresponding OS syscall to send the packet to the provided IP address
  • OS gets a packet and provided IP address, OS invokes its routing function to determine next hop
    • OS determines from what interface to send packet (interface can also be provided as an option for ping, at least for ping6)
    • OS constructs IP header for the packet with corresponding source and destination
    • OS determines next hop. Since the destination IP is in the same subnet, routing function determines that next hop is the same as destination IP (if it was not, OS would have determined next hop from the routing table)
  • next OS invokes its layer 2 (Ethernet) processing function for the "next hop" (here next hop is also destination IP).
    • It checks ARP table to get layer 2 addresses of next hop. If there is no entry, it starts ARP resolution. Note, the packet is not yet sent. It cannot be sent because OS cannot possibly put anything meaningful in dst mac.
    • OS waits for ARP resolution. If successful, the entry is inserted in the ARP table. OS constructs layer 2 header for the packet. Now the packet can be sent.
    • if ARP resolution fails, OS will inform the application and ping will show appropriate error message.
Related Topic