From dd18aa2b8633680102966f6b99b61327463561df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 24 Aug 2025 10:47:15 +0800 Subject: [PATCH] ping: Fix on android --- ping/ping.go | 4 ++-- ping/socket_unix.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ping/ping.go b/ping/ping.go index caad5f4..1f78c52 100644 --- a/ping/ping.go +++ b/ping/ping.go @@ -40,7 +40,7 @@ func Connect(privileged bool, controlFunc control.Func, destination netip.Addr) } func (c *Conn) ReadIP(buffer *buf.Buffer) error { - if c.destination.Is6() || runtime.GOOS == "linux" && !c.privileged { + if c.destination.Is6() || (runtime.GOOS == "linux" || runtime.GOOS == "android") && !c.privileged { var readMsg func(b, oob []byte) (n, oobn int, addr netip.Addr, err error) switch conn := c.conn.(type) { case *net.IPConn: @@ -163,7 +163,7 @@ func (c *Conn) ReadICMP(buffer *buf.Buffer) error { if err != nil { return err } - if c.destination.Is6() || runtime.GOOS == "linux" && !c.privileged { + if c.destination.Is6() || (runtime.GOOS == "linux" || runtime.GOOS == "android") && !c.privileged { return nil } if !c.destination.Is6() { diff --git a/ping/socket_unix.go b/ping/socket_unix.go index caf0f31..a01ef92 100644 --- a/ping/socket_unix.go +++ b/ping/socket_unix.go @@ -47,7 +47,7 @@ func connect(privileged bool, controlFunc control.Func, destination netip.Addr) return nil, E.Cause(err, "connect()") } - if destination.Is4() && runtime.GOOS == "linux" { + if destination.Is4() && (runtime.GOOS == "linux" || runtime.GOOS == "android") { //err = unix.SetsockoptInt(fd, unix.IPPROTO_IP, unix.IP_RECVTOS, 1) //if err != nil { // return nil, err