问题
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