I need to write a ping function to work on Linux. The language is C ++, so C is great too.
Searching the Internet and searching for the source code for the ping command, it turns out that I have to create a raw socket:
icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
If I run my application without root, the socket function returns -1 , i.e. The socket was not created successfully. If I run it as root, everything works fine.
Now the ping command creates a raw socket, and I can run it without root privileges .
My question is: how can I give my application all the permissions necessary to create a raw socket that is not executed by the superuser?
source share