我正在使用libpcap嗅探数据包,并在Ubuntu 18.04中使用C ++创建原始数据包。这些功能需要admin(sudo)权限。我正在检查删除依赖项的方法。
当我在不使用sudo的情况下运行代码时,出现以下错误:
pcap_open_live(): You don't have permission to capture on that device (socket: Operation not permitted)
我使用cmake和make来构建应用程序,并且具有可执行文件test
,该文件以./test
的身份运行。
我尝试了setcap cap_net_raw,cap_net_admin=eip ./test
,但是没有sudo,我无法捕获数据包,并且具有与上面相同的权限错误。
请帮助解决此问题。