From 3584fc1710a3273c10910ff820bb151bd99b3e54 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sun, 5 May 2024 02:13:43 +0200 Subject: [PATCH] return stats if no pkgs avail --- rtt.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rtt.go b/rtt.go index 52bdfe5..4c0347e 100644 --- a/rtt.go +++ b/rtt.go @@ -122,6 +122,11 @@ func (cp *ContinuousPinger) Stats(dSent, dReceive int) (*PingStats, error) { pkgsInArr++ } } + + if pkgsInArr == 0 { + return ps, nil + } + ps.AvgRtt = time.Duration(sum / int64(pkgsInArr)) ps.PacketLoss = math.Min(100, math.Max(100-(float64(dReceive)/float64(dSent)*100), 0)) if math.IsNaN(ps.PacketLoss) || math.IsInf(ps.PacketLoss, 0) {