开发者

user mode permission denied to bind to socket

开发者 https://www.devze.com 2023-03-02 04:30 出处:网络
In user mode [non-root] on a linux machine, I am trying to bind a socket by using a ioctl(iInterfaceSocket, SIOCSIFADDR, &stCommand). I am getting error 13 -> Permission denied because of user

In user mode [non-root] on a linux machine, I am trying to bind a socket by using a ioctl(iInterfaceSocket, SIOCSIFADDR, &stCommand). I am getting error 13 -> Permission denied because of user mode. If change from usermode to kernel mode everything works fine.

I need to bind the socket in user mode only. Please suggest a solution while explaining the problem above. If I missed any information please let me know and I will provide开发者_如何学JAVA more info.


You can't set the interface address unless you are root (well, technically, unless you have CAP_NET_ADMIN). See devinet.c.

The solution is to run as root. How to implement that solution, whether to make your entire program SUID, or ask the user to run it via sudo or gksudo, or whether to factor your program into two parts (root and non-root), that choice is up to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消