Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

user mode permission denied to bind to socket

Tags:

c

sockets

ioctl

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.

like image 611
Eswar Avatar asked May 03 '11 15:05

Eswar


1 Answers

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.

like image 171
Robᵩ Avatar answered Sep 25 '22 13:09

Robᵩ