当前位置: 动力学知识库 > 问答 > 编程问答 >

c - socket() fails - errno EPERM - ubuntu

问题描述:

I'm calling socket() fron my user space application, and get an error, with errno = 1 = EPERM.

I'm not root.. Is there something else to do beside calling my application with sudo ?

this is the code :

if ((sock=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)))<0) { //error in socket() }

网友答案:

That's because the processes that are wanting to use SOCK_RAW sockets need either having the CAP_NET_RAW capability or having a UID of zero (root), from the man page :

Only processes with an effective user ID of 0 or the CAP_NET_RAW capability are allowed to open raw sockets.

分享给朋友:
您可能感兴趣的文章:
随机阅读: