ping: fix network

This commit is contained in:
wwqgtxx
2025-08-25 00:00:02 +08:00
parent 0d3df84673
commit 58f331b49e

View File

@@ -23,14 +23,14 @@ func connect(privileged bool, controlFunc control.Func, destination netip.Addr)
err error err error
) )
if destination.Is4() { if destination.Is4() {
network = "ip4:icmp" network = "ip4" // like std's netFD.ctrlNetwork
if !privileged { if !privileged {
fd, err = unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_ICMP) fd, err = unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_ICMP)
} else { } else {
fd, err = unix.Socket(unix.AF_INET, unix.SOCK_RAW, unix.IPPROTO_ICMP) fd, err = unix.Socket(unix.AF_INET, unix.SOCK_RAW, unix.IPPROTO_ICMP)
} }
} else { } else {
network = "ip6:icmp" network = "ip6" // like std's netFD.ctrlNetwork
if !privileged { if !privileged {
fd, err = unix.Socket(unix.AF_INET6, unix.SOCK_DGRAM, unix.IPPROTO_ICMPV6) fd, err = unix.Socket(unix.AF_INET6, unix.SOCK_DGRAM, unix.IPPROTO_ICMPV6)
} else { } else {