1
0
mirror of https://github.com/go-ping/ping.git synced 2025-05-08 23:46:25 +00:00

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 .

Signed-off-by: Charlie Jonas <charlie@charliejonas.co.uk>
This commit is contained in:
Charlie Jonas 2020-10-06 22:48:50 +01:00
parent 4db5733515
commit 5f9dc3248b

View File

@ -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
}
}