简体   繁体   中英

Run libpcap without sudo/root

I am using libpcap to sniff packets and also to create raw packets in C++ in Ubuntu 18.04. These features require admin(sudo) permission. 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)

I build my application using cmake and make and I have the executable test , which I run as ./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.

Please help on this issue.

I found the answer here .

Issue turned out to be my hard disk not mounted with sudo. I built my tool in home folder and with setcap, I am able to sniff packets without sudo now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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