From ef3ab45e41b017889941ea5bb796dd502d2b5a1b Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 6 Nov 2018 16:54:34 +0000 Subject: [PATCH] Don't oversend packets fixes part of #6 --- ping.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ping.go b/ping.go index e986188..437a069 100644 --- a/ping.go +++ b/ping.go @@ -310,6 +310,9 @@ func (p *Pinger) run() { wg.Wait() return case <-interval.C: + if p.Count > 0 && p.PacketsSent >= p.Count { + continue + } err = p.sendICMP(conn) if err != nil { fmt.Println("FATAL: ", err.Error()) @@ -514,7 +517,7 @@ func (p *Pinger) sendICMP(conn *icmp.PacketConn) error { data, err := json.Marshal(IcmpData{Bytes: t, Tracker: p.Tracker}) if err != nil { - fmt.Errorf("Unable to marshal data") + return fmt.Errorf("Unable to marshal data %s", err) } body := &icmp.Echo{ ID: p.id,