[WIP] AARP responses

This commit is contained in:
Josh Deprez 2024-04-06 16:22:12 +11:00
parent fc5b07b975
commit 345bee4979
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
2 changed files with 23 additions and 3 deletions

View file

@ -4,11 +4,8 @@ import (
"fmt" "fmt"
"github.com/google/gopacket/pcap" "github.com/google/gopacket/pcap"
"github.com/sfiera/multitalk/pkg/ethernet"
) )
var MulticastDst = ethernet.Addr{0x09, 0x00, 0x07, 0xff, 0xff, 0xff}
// StartPcap opens an AppleTalk and AARP listening session on a network device. // StartPcap opens an AppleTalk and AARP listening session on a network device.
func StartPcap(device string) (*pcap.Handle, error) { func StartPcap(device string) (*pcap.Handle, error) {
handle, err := pcap.OpenLive(device, 4096, true, pcap.BlockForever) handle, err := pcap.OpenLive(device, 4096, true, pcap.BlockForever)

23
main.go
View file

@ -202,6 +202,29 @@ func main() {
amt.Learn(aapkt.Src.Proto, aapkt.Src.Hardware) amt.Learn(aapkt.Src.Proto, aapkt.Src.Hardware)
log.Printf("AARP: Gleaned that %v -> %v", aapkt.Src.Proto, aapkt.Src.Hardware) log.Printf("AARP: Gleaned that %v -> %v", aapkt.Src.Proto, aapkt.Src.Hardware)
if aapkt.Dst.Proto != localDDPAddr {
continue
}
// Respond!
respFrame, err := ethertalk.AARP(localMAC, aarp.Response(aapkt.Src, aarp.AddrPair{
Proto: localDDPAddr,
Hardware: localMAC,
}))
if err != nil {
log.Printf("Couldn't construct AARP Response: %v", err)
continue
}
respFrame.Dst = ethFrame.Src
respFrameRaw, err := ethertalk.Marshal(*respFrame)
if err != nil {
log.Printf("Couldn't marshal AARP Response: %v", err)
continue
}
if err := handle.WritePacketData(respFrameRaw); err != nil {
log.Printf("Couldn't write packet data: %v", err)
continue
}
case aarp.ResponseOp: case aarp.ResponseOp:
log.Printf("AARP: %v is at %v", aapkt.Dst.Proto, aapkt.Dst.Hardware) log.Printf("AARP: %v is at %v", aapkt.Dst.Proto, aapkt.Dst.Hardware)
amt.Learn(aapkt.Dst.Proto, aapkt.Dst.Hardware) amt.Learn(aapkt.Dst.Proto, aapkt.Dst.Hardware)