arp基本实现 创建一个网卡对象并绑定到ip1 网卡收到一个arp报文 链路层分发给arp网络端实现 arp到本地缓存中查找 该网卡是否绑定过目标ip地址ip1 没有直接放弃 有就新建一个源与目标逆置并添加了该网卡MAC的arp报文 并包装给链路层

This commit is contained in:
impact-eintr
2022-11-26 18:52:11 +08:00
parent 20b5b3415a
commit d9c0633bf5
12 changed files with 556 additions and 33 deletions

View File

@@ -65,6 +65,12 @@ func (a ARP) SetIPv4OverEthernet() {
a[5] = uint8(IPv4AddressSize)
}
// HardwareAddressSender从报文中得到arp发送方的硬件地址
func (a ARP) HardwareAddressSender() []byte {
const s = 8
return a[s : s+6]
}
// ProtocolAddressSender从报文中得到arp发送方的协议地址为ipv4地址
func (a ARP) ProtocolAddressSender() []byte {
const s = 8 + 6 // 8 是arp的协议头部 6是本机MAC