go-ping / ping

ICMP Ping library for Go
MIT License
1.32k stars 344 forks source link

Negative packet loss #178

Closed Leifiel closed 3 years ago

Leifiel commented 3 years ago

Hello, I use your package for monitoring purpose, and I recently had a case where a ping request issued multiple ping reply. This resulting in a negative packet loss (-233.33333..%)

The packet calculation made here doesn't assert that the value should be >= 0, I that a wanted behaviour? https://github.com/go-ping/ping/blob/ff8be3320020b96856d3d48505bcf8926809752e/ping.go#L510

Otherwise, I'll be happy to send a PR.

L.

SuperQ commented 3 years ago

I would say the correct fix is to do somethign like sent-p.PacketsRecv-p.PacketsRecvDuplicates. This would fix the loss percent.

And yes, a PR would be appreciated.

Leifiel commented 3 years ago

After looking into it, it seems that PacketsRecv will be incremented only if the packet sequence number haven't been processed already. My worker was using a version of this module where duplicates weren't implemented.

This change isn't need from what I understand.