diff --git a/config/config.go b/config/config.go index d71b04c..3986459 100644 --- a/config/config.go +++ b/config/config.go @@ -56,6 +56,7 @@ type InterfacesConfig struct { ReadSpeed bool `config:"top_speed"` OneAtATime bool `config:"one_at_a_time"` Loop int `config:"loop"` + EOFExit bool `config:"eof_exit"` FanoutID uint `config:"fanout_id"` FanoutWorker int `config:"fanout_worker"` CustomBPF string `config:"custom_bpf"` diff --git a/main.go b/main.go index d6b963c..1e83bc6 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "github.com/sipcapture/heplify/sniffer" ) -const version = "heplify 1.66.1" +const version = "heplify 1.66.2" func createFlags() { @@ -82,6 +82,7 @@ func createFlags() { flag.IntVar(&ifaceConfig.RotationTime, "rt", 60, "Pcap rotation time in minutes") flag.BoolVar(&config.Cfg.Zip, "zf", false, "Enable pcap compression") flag.IntVar(&ifaceConfig.Loop, "lp", 1, "Loop count over ReadFile. Use 0 to loop forever") + flag.BoolVar(&ifaceConfig.EOFExit, "eof-exit", false, "Exit on EOF of ReadFile") flag.BoolVar(&ifaceConfig.ReadSpeed, "rs", false, "Use packet timestamps with maximum pcap read speed") flag.StringVar(&ifaceConfig.PortRange, "pr", "5060-5090", "Portrange to capture SIP") flag.BoolVar(&sys, "sl", false, "Log to syslog") diff --git a/sniffer/sniffer.go b/sniffer/sniffer.go index 5150110..fea49f5 100644 --- a/sniffer/sniffer.go +++ b/sniffer/sniffer.go @@ -458,7 +458,14 @@ LOOP: } if err == io.EOF { + logp.Debug("sniffer", "End of file") + + if sniffer.config.EOFExit { + sniffer.Close() + os.Exit(0) + } + loopCount++ if sniffer.config.Loop > 0 && loopCount > sniffer.config.Loop { // Give the publish goroutine 200 ms to flush