ZBLOG

// https://www.ietf.org/rfc/rfc5227.txt // returns MAC of the host if the ip address is in use func ArpDetectIPConflict(nic, ip string, mac net.HardwareAddr) (net.HardwareAddr, error) { const ( probeWait = 1 * time.Second // initial rand...

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.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://sdn.0voice.com/?id=248

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?