mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
yeah i should have done this before, i know
This commit is contained in:
commit
0091ffdbb3
33 changed files with 25678 additions and 0 deletions
40
packets/arp.go
Normal file
40
packets/arp.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package packets
|
||||
|
||||
import (
|
||||
"github.com/google/gopacket/layers"
|
||||
"net"
|
||||
)
|
||||
|
||||
func NewARPTo(from net.IP, from_hw net.HardwareAddr, to net.IP, to_hw net.HardwareAddr, req uint16) (layers.Ethernet, layers.ARP) {
|
||||
eth := layers.Ethernet{
|
||||
SrcMAC: from_hw,
|
||||
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
||||
EthernetType: layers.EthernetTypeARP,
|
||||
}
|
||||
arp := layers.ARP{
|
||||
AddrType: layers.LinkTypeEthernet,
|
||||
Protocol: layers.EthernetTypeIPv4,
|
||||
HwAddressSize: 6,
|
||||
ProtAddressSize: 4,
|
||||
Operation: req,
|
||||
SourceHwAddress: from_hw,
|
||||
SourceProtAddress: from.To4(),
|
||||
DstHwAddress: to_hw,
|
||||
DstProtAddress: to.To4(),
|
||||
}
|
||||
|
||||
return eth, arp
|
||||
}
|
||||
func NewARP(from net.IP, from_hw net.HardwareAddr, to net.IP, req uint16) (layers.Ethernet, layers.ARP) {
|
||||
return NewARPTo(from, from_hw, to, []byte{0, 0, 0, 0, 0, 0}, req)
|
||||
}
|
||||
|
||||
func NewARPRequest(from net.IP, from_hw net.HardwareAddr, to net.IP) (error, []byte) {
|
||||
eth, arp := NewARP(from, from_hw, to, layers.ARPRequest)
|
||||
return Serialize(ð, &arp)
|
||||
}
|
||||
|
||||
func NewARPReply(from net.IP, from_hw net.HardwareAddr, to net.IP, to_hw net.HardwareAddr) (error, []byte) {
|
||||
eth, arp := NewARPTo(from, from_hw, to, to_hw, layers.ARPReply)
|
||||
return Serialize(ð, &arp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue