Opening RAW sockets in linux without being superuser

前端 未结 2 1078
余生分开走
余生分开走 2021-02-11 02:22

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-11 02:50

    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.

提交回复
热议问题