The ArpDetectIPConflict function takes in three arguments: nic, ip, and mac.
- nic is a string representing the name of the network interface card to be used for sending ARP packets.
- ip is a string representing the IP address to check for conflicts.
- mac is a net.HardwareAddr representing the MAC address of the host.
The function first parses the IP address and creates an ARP packet with an OperationRequest code, using the given MAC address as the sender hardware address and 0.0.0.0 as the sender protocol address. The target hardware and protocol addresses are set to 0, and the given IP address, respectively.
It then opens an ARP connection on the specified network interface card and sends out a series of probe packets to the broadcast address (ff:ff:ff:ff:ff:ff), spaced randomly between PROBE_MIN and PROBE_MAX seconds apart. If it receives a response from another host’s hardware address claiming ownership of the given IP address, it returns that hardware address as a conflict.
If no conflicts are detected, the function broadcasts a series of ARP announcements to claim ownership of the IP address, with the same MAC address as both the sender and target hardware address.