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

25
capture/pacp_macos.go Normal file
View File

@@ -0,0 +1,25 @@
// +build darwin
package capture
import (
"fmt"
"github.com/google/gopacket/pcap"
)
// in online use, we found a strange bug: pcap cost 100% core CPU and memory increase along
func initEthernetHandlerFromPacp() (handler PcapHandler) {
pcapHandler, err := pcap.OpenLive(DeviceName, 65536, false, pcap.BlockForever)
if err != nil {
panic(fmt.Sprintf("cannot open network interface %s <-- %s", DeviceName, err.Error()))
}
err = pcapHandler.SetBPFFilter(fmt.Sprintf("tcp and (port %d)", snifferPort))
if err != nil {
panic(err.Error())
}
handler = pcapHandler
return
}