return stats if no pkgs avail

This commit is contained in:
2024-05-05 02:13:43 +02:00
parent b44256b607
commit 3584fc1710

5
rtt.go
View File

@@ -122,6 +122,11 @@ func (cp *ContinuousPinger) Stats(dSent, dReceive int) (*PingStats, error) {
pkgsInArr++ pkgsInArr++
} }
} }
if pkgsInArr == 0 {
return ps, nil
}
ps.AvgRtt = time.Duration(sum / int64(pkgsInArr)) ps.AvgRtt = time.Duration(sum / int64(pkgsInArr))
ps.PacketLoss = math.Min(100, math.Max(100-(float64(dReceive)/float64(dSent)*100), 0)) ps.PacketLoss = math.Min(100, math.Max(100-(float64(dReceive)/float64(dSent)*100), 0))
if math.IsNaN(ps.PacketLoss) || math.IsInf(ps.PacketLoss, 0) { if math.IsNaN(ps.PacketLoss) || math.IsInf(ps.PacketLoss, 0) {