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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With