ARP Request Behavior with Unknown Subnet Mask

arpsubnet

Please help me with one doubt regarding ARP requests. Based on my understanding the subnet of an IP is identified by it's Subnet Mask so consider this scenario:-

Suppose Device1 with IP- 30.129.33.225 needs to talk to a Device2 with IP- 30.113.220.62.

i)If Device1 know the Subnet Mask of Device2 IP

It calculates and finds out Device2 to be on a different subnet hence for the communication IT SENDS THE DATAGRAM(packet) to THE DEFAULT GATEWAY—NO ARP REQUESTS.

ii) If Device1 doesn't know the Subnet Mask of Device2 IP

This is my doubt. What does Device1 do? Does it send a broadcast ARP request thinking of Device2 to be on the same subnet as its?
How does any networking device calculate the subnet mask or how do they identify the subnet of an IP and decide whether to ARP or route to GATEWAY.

The scenario is important because in my case Device1 is a Network Device Discovery Appliance, it fetches IPs from the Switch MAC table/ARP Tables and then pings the IPs to find out if they are alive/exists. To my knowledge Switch MAC Table/ARP Tables does not contain Subnet Mask. Only Route Table has Subnet Mask information I believe.
So does Device1 send an ARP broadcast of the form "who has 30.113.220.62(Device2 IP)" "tell 30.129.33.225(Device1 IP)" or Device1 calculates the mask by some means and finds out Device2 to be in different network hence routes the packet to Default Gateway?

ARP REQUEST SOURCE IP:0.0.0.0

Please guide me.
Thank you

Best Answer

An ARP request is generally limited to the broadcast domain = the local subnet or segment. MAC addresses outside the local subnet are meaningless.

The only relevant question is Is the destination IP address in my own subnet = local?

If yes, ARP the destination address and send to MAC.

If no, select gateway from routing table, ARP the gateway's IP address and send to that MAC.

To find out if the destination IP address is inside your own subnet, you bitwise AND your own IP address with your network mask, resulting in your subnet address. Then you bitwise AND the destination IP address with your network mask and compare the result with your own subnet address. If both subnet addresses are identical the destination is local.

If you mean to discover the MAC address for a remote device (for whatever reason) you'll have to find (or install) a device in the appropriate subnet that can ARP the IP address and tell you the MAC.

Discovering remote devices is much harder than local ones (which you just try to ARP and when you get an answer you know it's there). You can only detect remote devices by using IP/layer 3 functions because these can be routed.

You can try to ping a device (which may choose not to answer or the echo request or reply is filtered on the way), or you can try to connect to some common port. On failure, you can analyze the ICMP reply (a device request might actively reject the connection or a router might tell you there's no one there). If you get nothing you can't be sure there's nothing there though.