while creating RAW_SOCKET error like Operation not permitted

╄→尐↘猪︶ㄣ 提交于 2020-05-15 18:49:04

问题


in my android application i want to create RAW SOCKET but when i try to create it by following code it gives error like Operation not permitted.

int sd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
if(sd < 0)
{
    ortp_warning("socket() error %s",getSocketError());
    // If something wrong just exit
    //exit(-1);
}
else
{
    ortp_warning("socket() - Using SOCK_RAW socket and UDP protocol is OK.\n");
}

how can i solve it.??


回答1:


You must have root privileges to create a raw socket. It is a privileged action; run as sudo or root.




回答2:


try setting CAP_NET_RAW and cap_net_admin capability to your application. Details could be found at http://linux.die.net/man/7/capabilities

 # setcap cap_net_raw,cap_net_admin=eip APPLICATION_PATH


来源:https://stackoverflow.com/questions/27999656/while-creating-raw-socket-error-like-operation-not-permitted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!