2024-04-05 13:18:22 +11:00
|
|
|
package atalk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/google/gopacket/pcap"
|
2024-04-05 14:31:36 +11:00
|
|
|
"github.com/sfiera/multitalk/pkg/ethernet"
|
2024-04-05 13:18:22 +11:00
|
|
|
)
|
|
|
|
|
2024-04-05 14:31:36 +11:00
|
|
|
var MulticastDst = ethernet.Addr{0x09, 0x00, 0x07, 0xff, 0xff, 0xff}
|
|
|
|
|
2024-04-05 13:18:22 +11:00
|
|
|
// StartPcap opens an AppleTalk and AARP listening session on a network device.
|
|
|
|
func StartPcap(device string) (*pcap.Handle, error) {
|
2024-04-05 13:27:43 +11:00
|
|
|
handle, err := pcap.OpenLive(device, 4096, true, pcap.BlockForever)
|
2024-04-05 13:18:22 +11:00
|
|
|
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
|
|
|
|
}
|