Open isedev opened 4 years ago
I’m pretty sure you need to run your process as root to bind to ICMP.
ping is usually setuid for this reason, https://askubuntu.com/questions/789938/why-do-mount-ping-and-su-have-a-sticky-bit-set
Have you tried building your program and running it as root (note, don’t use go run, that won’t give the correct results)
Apologies for the late replay.
As far as I am aware, Linux supports two ways of performing ICMP echo/reply:
And it does works. When commenting out the socket bind code above, I am able to perform pings as non-root. The issue I think is that the UDP ICMP socket does not support binding.
I see from the x/net/listen_posix.go code that it does try to support the non-root feature since it explicitly distinguishes between "ip4" and "udp4" networks (the latter being in AF_INET family).
Ping @mikioh
@isedev At least of Go 1.17.5 and the current version of go-ping, this works correctly as an unprivileged user. I tested the example code under Darwin and Linux successfully.
Give it another try?
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes (tested against go1.14.4)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The following simple test program fails with "bind: permission denied" on Linux 5.0.16-100.fc28.x86_64.
The ping library used above depends on golang.org/x/net/icmp.
Not sure if this is relevant or not, but the system where the above was tested uses a bridge interface with an IP address configured and the physical network interface is attached to the bridge:
What did you expect to see?
What did you see instead?
Making the following change to x/net/icmp/listen_posix.go results in expected behaviour:
Using "0.0.0.0" or "" as source address makes no difference.