jrouter/atalk/raw.go

23 lines
519 B
Go
Raw Normal View History

2024-04-05 13:18:22 +11:00
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
}