WIP AppleTalk
This commit is contained in:
parent
ed877ae731
commit
62162d8c95
3 changed files with 29 additions and 5 deletions
3
go.mod
3
go.mod
|
@ -9,5 +9,6 @@ require (
|
|||
|
||||
require (
|
||||
github.com/google/gopacket v1.1.19 // indirect
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
|
||||
github.com/sfiera/multitalk v0.2.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2,6 +2,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
|
||||
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
|
||||
github.com/sfiera/multitalk v0.2.0 h1:FLLw7L6yNUTOdjMk2EgKnOwMKeu++t5zinv5qpTC2JM=
|
||||
github.com/sfiera/multitalk v0.2.0/go.mod h1:jGkgjgiyfuRMNKwfSjo/xR6b9nd10XF4smQAtApXFHc=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
|
@ -12,6 +14,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
27
main.go
27
main.go
|
@ -17,6 +17,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
|
@ -31,6 +32,7 @@ import (
|
|||
|
||||
"gitea.drjosh.dev/josh/jrouter/atalk"
|
||||
"gitea.drjosh.dev/josh/jrouter/aurp"
|
||||
"github.com/sfiera/multitalk/pkg/ethertalk"
|
||||
)
|
||||
|
||||
var hasPortRE = regexp.MustCompile(`:\d+$`)
|
||||
|
@ -136,6 +138,12 @@ func main() {
|
|||
|
||||
// AppleTalk packet loop
|
||||
go func() {
|
||||
iface, err := net.InterfaceByName(cfg.EtherTalk.Device)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't find interface named %q: %v", cfg.EtherTalk.Device, err)
|
||||
}
|
||||
localMAC := iface.HardwareAddr
|
||||
|
||||
handle, err := atalk.StartPcap(cfg.EtherTalk.Device)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't open network device for AppleTalk: %v", err)
|
||||
|
@ -143,11 +151,22 @@ func main() {
|
|||
defer handle.Close()
|
||||
|
||||
for {
|
||||
packet, _, err := handle.ReadPacketData()
|
||||
rawPkt, _, err := handle.ReadPacketData()
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't read packet data: %v", err)
|
||||
log.Fatalf("Couldn't read AppleTalk / AARP packet data: %v", err)
|
||||
}
|
||||
log.Printf("%x", packet)
|
||||
|
||||
var pkt ethertalk.Packet
|
||||
if err := ethertalk.Unmarshal(rawPkt, &pkt); err != nil {
|
||||
log.Printf("Couldn't unmarshal EtherTalk frame: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if bytes.Equal(pkt.Src[:], localMAC) {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf("Read packet %s -> %s payload %x", pkt.Src, pkt.Dst, pkt.Payload)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -157,7 +176,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
ln.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
pktbuf := make([]byte, 65536)
|
||||
pktbuf := make([]byte, 4096)
|
||||
pktlen, raddr, readErr := ln.ReadFromUDP(pktbuf)
|
||||
|
||||
var operr *net.OpError
|
||||
|
|
Loading…
Reference in a new issue