From 5f9dc3248bce831f898c8c40c1cdf2707efd60a7 Mon Sep 17 00:00:00 2001 From: Charlie Jonas Date: Tue, 6 Oct 2020 22:48:50 +0100 Subject: [PATCH] Ignore control message errors on Windows The x/net/ipv4 and x/net/ipv6 packages do not implement the necessary control message functionality on Microsoft Windows. This commit ignores any control message errors that are returned by the SetControlMessage function if the Go runtime is compiled for Windows. This fixes #105. Signed-off-by: Charlie Jonas --- ping.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ping.go b/ping.go index 1cc7be1..19fe1e7 100644 --- a/ping.go +++ b/ping.go @@ -51,6 +51,7 @@ import ( "math" "math/rand" "net" + "runtime" "sync" "syscall" "time" @@ -312,14 +313,14 @@ func (p *Pinger) Run() error { if conn, err = p.listen(ipv4Proto[p.protocol]); err != nil { return err } - if err = conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true); err != nil { + if err = conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true); runtime.GOOS != "windows" && err != nil { return err } } else { if conn, err = p.listen(ipv6Proto[p.protocol]); err != nil { return err } - if err = conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true); err != nil { + if err = conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true); runtime.GOOS != "windows" && err != nil { return err } }