[WIP] AppleTalk listen loop
This commit is contained in:
parent
f7fa4fb688
commit
59960986c9
6 changed files with 62 additions and 0 deletions
22
atalk/raw.go
Normal file
22
atalk/raw.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package atalk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gopacket/pcap"
|
||||
)
|
||||
|
||||
// StartPcap opens an AppleTalk and AARP listening session on a network device.
|
||||
func StartPcap(device string) (*pcap.Handle, error) {
|
||||
handle, err := pcap.OpenLive(device, 4096, false, pcap.BlockForever)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("opening device %q: %w", device, err)
|
||||
}
|
||||
|
||||
if err := handle.SetBPFFilter("atalk or aarp"); err != nil {
|
||||
handle.Close()
|
||||
return nil, fmt.Errorf("setting BPF filter: %w", err)
|
||||
}
|
||||
|
||||
return handle, nil
|
||||
}
|
|
@ -35,6 +35,7 @@ type config struct {
|
|||
|
||||
// Required for routing a local EtherTalk network.
|
||||
EtherTalk struct {
|
||||
Device string `yaml:"device"`
|
||||
ZoneName string `yaml:"zone_name"`
|
||||
NetStart uint16 `yaml:"net_start"`
|
||||
NetEnd uint16 `yaml:"net_end"`
|
||||
|
|
5
go.mod
5
go.mod
|
@ -6,3 +6,8 @@ require (
|
|||
github.com/google/go-cmp v0.6.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/gopacket v1.1.19 // indirect
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
|
||||
)
|
||||
|
|
15
go.sum
15
go.sum
|
@ -1,5 +1,20 @@
|
|||
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=
|
||||
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=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
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/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=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
ethertalk:
|
||||
device: enp1s0
|
||||
zone_name: The Twilight Zone
|
||||
net_start: 100
|
||||
net_end: 100
|
||||
|
|
18
main.go
18
main.go
|
@ -29,6 +29,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.drjosh.dev/josh/jrouter/atalk"
|
||||
"gitea.drjosh.dev/josh/jrouter/aurp"
|
||||
)
|
||||
|
||||
|
@ -133,6 +134,23 @@ func main() {
|
|||
goHandler(peer)
|
||||
}
|
||||
|
||||
// AppleTalk packet loop
|
||||
go func() {
|
||||
handle, err := atalk.StartPcap(cfg.EtherTalk.Device)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't open network device for AppleTalk: %v", err)
|
||||
}
|
||||
defer handle.Close()
|
||||
|
||||
for {
|
||||
packet, _, err := handle.ReadPacketData()
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't read packet data: %v", err)
|
||||
}
|
||||
log.Printf("%x", packet)
|
||||
}
|
||||
}()
|
||||
|
||||
// Incoming packet loop
|
||||
for {
|
||||
if ctx.Err() != nil {
|
||||
|
|
Loading…
Reference in a new issue