在没有sudo / root的情况下运行libpcap

时间:2020-09-21 15:02:35

标签: c++ linux root sudo libpcap

我正在使用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,我无法捕获数据包,并且具有与上面相同的权限错误。

请帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

我找到了答案here

问题出在我的硬盘上而不是sudo。我在主文件夹中构建了我的工具,并使用setcap来监听数据包,而无需使用sudo。