mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-09-19 02:06:52 +08:00
add macos pacp
This commit is contained in:
36
capture/pacp_linux.go
Normal file
36
capture/pacp_linux.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user