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
ping needs the cap_net_raw capability to do this without (other) superuser rights, and so does your program. Run
cap_net_raw
setcap cap_net_raw+ep your_executable_file
as root, and then normal users will be able to use the program.