Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added exit on end of file #280

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/sipcapture/heplify/sniffer"
)

const version = "heplify 1.66.1"
const version = "heplify 1.66.2"

func createFlags() {

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions sniffer/sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading