diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..eb311f8 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,6 @@ +--- +issues: + exclude-rules: + - path: _test.go + linters: + - errcheck diff --git a/cmd/ping/ping.go b/cmd/ping/ping.go index 872ed41..7505131 100644 --- a/cmd/ping/ping.go +++ b/cmd/ping/ping.go @@ -39,7 +39,7 @@ func main() { count := flag.Int("c", -1, "") privileged := flag.Bool("privileged", false, "") flag.Usage = func() { - fmt.Printf(usage) + fmt.Print(usage) } flag.Parse() @@ -59,7 +59,7 @@ func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { - for _ = range c { + for range c { pinger.Stop() } }() diff --git a/ping.go b/ping.go index c410894..53c0791 100644 --- a/ping.go +++ b/ping.go @@ -145,7 +145,6 @@ type Pinger struct { addr string ipv4 bool - size int id int sequence int // network is one of "ip", "ip4", or "ip6". @@ -309,12 +308,16 @@ func (p *Pinger) Run() { if conn = p.listen(ipv4Proto[p.protocol]); conn == nil { return } - conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true) + if conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true) != nil { + return + } } else { if conn = p.listen(ipv6Proto[p.protocol]); conn == nil { return } - conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true) + if conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true) != nil { + return + } } defer conn.Close() defer p.finish() @@ -431,7 +434,9 @@ func (p *Pinger) recvICMP( return default: bytes := make([]byte, 512) - conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100)) + if conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100)) != nil { + return + } var n, ttl int var err error if p.ipv4 {