简体   繁体   English

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

[英]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.请帮助解决这个问题。

I found the answer here .我在这里找到了答案。

Issue turned out to be my hard disk not mounted with sudo.问题原来是我的硬盘没有安装 sudo。 I built my tool in home folder and with setcap, I am able to sniff packets without sudo now.我在主文件夹和 setcap 中构建了我的工具,我现在可以在没有 sudo 的情况下嗅探数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM