add macos pacp

This commit is contained in:
xiaobiao
2022-01-07 11:39:28 +08:00
parent b0e0d6a73d
commit 2818338476
3 changed files with 69 additions and 56 deletions

36
capture/pacp_linux.go Normal file
View File

@@ -0,0 +1,36 @@
// +build linux
package capture
func initEthernetHandlerFromPacp() (handler PcapHandler) {
pcapgoHandler, err := pcapgo.NewEthernetHandle(DeviceName)
if err != nil {
panic(fmt.Sprintf("cannot open network interface %s <-- %s", DeviceName, err.Error()))
}
// set BPFFilter
pcapBPF, err := pcap.CompileBPFFilter(
layers.LinkTypeEthernet, 65535, fmt.Sprintf("tcp and (port %d)", snifferPort))
if err != nil {
panic(err.Error())
}
bpfIns := []bpf.RawInstruction{}
for _, ins := range pcapBPF {
bpfIn := bpf.RawInstruction{
Op: ins.Code,
Jt: ins.Jt,
Jf: ins.Jf,
K: ins.K,
}
bpfIns = append(bpfIns, bpfIn)
}
err = pcapgoHandler.SetBPF(bpfIns)
if err != nil {
panic(err.Error())
}
_ = pcapgoHandler.SetCaptureLength(65536)
handler = pcapgoHandler
return
}