Broadcast
Hang on, how does "A" know what "B"'s MAC address is? If we look back up to the ifconfig output, we can see the "Bcast," or Broadcast address. This is configured to be the highest IP address available on the network. As this network is 192.168.1.0 - 192.168.1.255, the broadcast address is 192.168.1.255. This is a special address. If A wants to know "B"'s MAC address, it can broadcast a packet, addressed to 192.168.1.255, using ARP, asking who has 192.168.1.2. "B" (or potentially another device on the network) will reply with "B"'s MAC address. A packet sent to the broadcast address looks like this:
Source IP | 192.168.1.1 | (A) |
---|---|---|
Source MAC | 01:C0:F2:69:31:21 | (A) |
Destination IP | 192.168.1.255 | (broadcast) |
Destination MAC | FF:FF:FF:FF:FF:FF | (broadcast) |
Data | Who has 192.168.1.2 ? Tell 192.168.1.1 |
Any machine on the network which knows the answer (but usually "B" itself) will reply with a fully-populated packet, including its own MAC address - any outgoing packet always includes the sender's IP and MAC address. This way, "A" can learn "B"'s MAC address if it needs to send it a packet.
Source IP | 192.168.1.2 | (B) |
---|---|---|
Source MAC | 0A:E1:23:28:AE:F2 | (B) |
Destination IP | 192.168.1.1 | (A) |
Destination MAC | 01:C0:F2:69:31:21 | (A) |
Data | 192.168.1.2 is 0A:E1:23:28:AE:F2 |
The network card (NIC) listens to packets sent to itself, and also to packets sent to FF:FF:FF:FF:FF:FF. In a similar way, the IP Stack will listen to packets addressed to the IP broadcast address - 192.168.1.255 in this case (so long as the MAC address matches, otherwise the packet would already have been discarded by the NIC).