mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
feat: capture pcap file with PID/ProcName/bundleID
This commit is contained in:
@@ -6,6 +6,39 @@ import (
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/gidevice/pkg/libimobiledevice"
|
||||
)
|
||||
|
||||
type PcapOptions struct {
|
||||
All bool // capture all packets
|
||||
Pid int // capture packets from specific PID
|
||||
ProcName string // capture packets from specific process name
|
||||
BundleID string // convert to PID first, then capture packets from the PID
|
||||
}
|
||||
|
||||
type PcapOption func(*PcapOptions)
|
||||
|
||||
func WithPcapAll(all bool) PcapOption {
|
||||
return func(opt *PcapOptions) {
|
||||
opt.All = all
|
||||
}
|
||||
}
|
||||
|
||||
func WithPcapProcName(procName string) PcapOption {
|
||||
return func(opt *PcapOptions) {
|
||||
opt.ProcName = procName
|
||||
}
|
||||
}
|
||||
|
||||
func WithPcapPID(pid int) PcapOption {
|
||||
return func(opt *PcapOptions) {
|
||||
opt.Pid = pid
|
||||
}
|
||||
}
|
||||
|
||||
func WithPcapBundleID(bundleID string) PcapOption {
|
||||
return func(opt *PcapOptions) {
|
||||
opt.BundleID = bundleID
|
||||
}
|
||||
}
|
||||
|
||||
type pcapdClient struct {
|
||||
stop chan struct{}
|
||||
c *libimobiledevice.PcapdClient
|
||||
@@ -38,6 +71,10 @@ func (c *pcapdClient) Packet() <-chan []byte {
|
||||
close(packetCh)
|
||||
return
|
||||
}
|
||||
if raw == nil {
|
||||
// filtered packet
|
||||
continue
|
||||
}
|
||||
res, err := c.c.CreatePacket(raw)
|
||||
if err != nil {
|
||||
log.Println("failed to create packet")
|
||||
|
||||
Reference in New Issue
Block a user