From 2137a8d5ff404d76c374661dddef1ca569e88bfd Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Tue, 12 Mar 2024 22:32:05 +0100 Subject: [PATCH 1/2] added exit on end of file --- config/config.go | 1 + main.go | 1 + sniffer/sniffer.go | 7 +++++++ 3 files changed, 9 insertions(+) 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..cb8188f 100644 --- a/main.go +++ b/main.go @@ -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 From 6152c67321d3d93a5c781cf019eec434dc753415 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Tue, 12 Mar 2024 22:33:37 +0100 Subject: [PATCH 2/2] increased version --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index cb8188f..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() {