I have to write a ping function to run on Linux. The language is C++, so C if fine too.
Searching on the Internet and looking at the source code for the ping
ping
needs the cap_net_raw
capability to do this without (other) superuser rights, and so does your program. Run
setcap cap_net_raw+ep your_executable_file
as root, and then normal users will be able to use the program.
You can make your program a SUID command, granting it effectively root permissions, without granting them to the executing user. For an example and explanation see here.