in pcap-cli/pkg/pcap/gopacket_engine.go [40:79]
func (p *Pcap) newPcap(ctx context.Context) (*pcap.InactiveHandle, error) {
cfg := *p.config
var err error
inactiveHandle, err := pcap.NewInactiveHandle(cfg.Iface)
if err != nil {
gopacketLogger.Printf("could not create: %v\n", err)
}
if err = inactiveHandle.SetSnapLen(cfg.Snaplen); err != nil {
gopacketLogger.Printf("could not set snap length: %v\n", err)
return nil, err
}
if err = inactiveHandle.SetPromisc(cfg.Promisc); err != nil {
gopacketLogger.Printf("could not set promisc mode: %v\n", err)
return nil, err
}
// [TODO]: make handle timeout dynamic
if err = inactiveHandle.SetTimeout(100 * time.Millisecond); err != nil {
gopacketLogger.Printf("could not set timeout: %v\n", err)
return nil, err
}
if cfg.TsType != "" {
if t, err := pcap.TimestampSourceFromString(cfg.TsType); err != nil {
gopacketLogger.Printf("Supported timestamp types: %v\n", inactiveHandle.SupportedTimestamps())
return nil, err
} else if err := inactiveHandle.SetTimestampSource(t); err != nil {
gopacketLogger.Printf("Supported timestamp types: %v\n", inactiveHandle.SupportedTimestamps())
return nil, err
}
}
p.inactiveHandle = inactiveHandle
return inactiveHandle, nil
}