Getting raw sockets requires root privilege, and tcp/udp doesn't have it, so I need to know how to get a udp socket and fetch icmp data. The programming language is C and the OS is BSD-like.
(In other words I want to write a ping without root privilege)
You can write an UDP ping without root privileges.
When the IP_RECVERR option is enabled, all errors are stored in the socket error queue, and can be received by recvmsg (2) with the MSG_ERRQUEUE flag set.
I assume the forge&send routine is already implemented on a SOCK_DGRAM socket. Then, to access the source addresses of the ICMP messages:
UDP is an OSI layer four protocoll, so is ICMP. Thereby, you can't implement ICMP on an UDP socket since its layer four protocoll is already fixed to UDP. You can consider writing an implementation that requires the privilege to open a raw socket. Then you either give the application or your account the right capability or flip the executables SUID bit to make it run as root.
So, uh, it it was trivial to go around the requirement, do you think it would still be there?
It's meant to provide some security, so it's not super-easy to go around.
I don't think it can be done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.