in pcap-cli/pkg/pcap/gopacket_engine.go [222:254]
func NewPcap(config *PcapConfig) (PcapEngine, error) {
var isActive atomic.Bool
isActive.Store(false)
debug := config.Debug
if debugEnvVar, err := strconv.ParseBool(os.Getenv("PCAP_DEBUG")); err == nil {
config.Debug = debug || debugEnvVar
}
// `config.Ephemerals` is already a safe type,
// here the validation only enforces correctness of port range.
if config.Ephemerals == nil ||
config.Ephemerals.Min < pcap_min_ephemeral_port ||
config.Ephemerals.Min >= config.Ephemerals.Max {
config.Ephemerals = &PcapEphemeralPorts{
Min: PCAP_MIN_EPHEMERAL_PORT,
Max: PCAP_MAX_EPHEMERAL_PORT,
}
}
pcap := Pcap{config: config, isActive: &isActive}
if strings.EqualFold(config.Iface, anyDeviceName) {
config.Device = nil
} else {
devices, err := FindDevicesByName(&config.Iface)
if err == nil {
config.Device = devices[0]
}
}
return &pcap, nil
}