[英]Run libpcap without sudo/root
I am using libpcap to sniff packets and also to create raw packets in C++ in Ubuntu 18.04.我正在使用 libpcap 嗅探数据包,并在 Ubuntu 18.04 的 C++ 中创建原始数据包。 These features require admin(sudo) permission.
这些功能需要管理员(sudo)权限。 I am checking for a way to remove the dependency.
我正在寻找一种方法来消除依赖性。
When I run my code without sudo, I get the following error: pcap_open_live(): You don't have permission to capture on that device (socket: Operation not permitted)
当我在没有 sudo 的情况下运行我的代码时,我收到以下错误:
pcap_open_live(): You don't have permission to capture on that device (socket: Operation not permitted)
I build my application using cmake and make and I have the executable test
, which I run as ./test
.我使用 cmake 和 make 构建我的应用程序,并且我有可执行文件
test
,我将其作为./test
运行。
I have tried setcap cap.net_raw,cap.net_admin=eip./test
, but without sudo, I am unable to capture packets, with the same permission error as above.我已经尝试过
setcap cap.net_raw,cap.net_admin=eip./test
,但是没有 sudo,我无法捕获数据包,并出现与上述相同的权限错误。
Please help on this issue.请帮助解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.