I am having trouble understanding the steps in order to send an ip packet to another host on the same LAN. Most sources online that I have read and people I have talked to say that the host uses the subnet mask with the destination ip to determine if they are on the same subnet. I see how this works, but I have a few questions in regards to it.
In order to determine if it's on the same subnet, the host goes to the routing table, loops through each entry, and performs a bitwise AND on the entry's mask and the destination address of interest. This result is then compared with the same routing table entry's destination field. Whichever bits match the most throughout this process is determined as the best match. After finding the best match, it uses the entry's interface field to send out the datagram. If the best match entry has a gateway field that equals the IP of the sending host, then that tells the host that the destination of interest is on the same subnet. ARP is then used to find the MAC for the destination IP (if it isn't already in the ARP table) and the communication begins.
Is this correct? This is how it is described in TCP/IP illustrated. But yet when I talk to others and read online at some places, some people act like the host simply does a bitwise AND on the destination address with the host's subnet mask, and because that determines if it's on the same subnet, it then proceeds with ARP. That process doesn't involve the routing table at all.
Am I right in how I interpreted the author in TCP/IP illustrated or is the second approach I listed correct?