Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux denies permission on socket bind using boost asio

Tags:

c++

linux

sockets

I'm having a problem binding a socket and I get permision denied when running the program as a user. this line of code generates an error.

_acceptor = new boost::asio::ip::tcp::acceptor(io, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), serverPort)); the error is

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'

what(): bind: Permission denied

However, if I run as root it works fine. I've tried disabling apparmor and firewall with

sudo service apparmor stop
sudo ufw disable

but I still have the problem. Am I missing something that could deny permision? I'd really like to figure this out as I don't like running my IDE and an unproven program as root.

I'm running xubuntu 13.10 with all updates installed.

like image 622
Robert Reinhart Avatar asked Dec 29 '13 13:12

Robert Reinhart


1 Answers

On unix systems, the first 1024 port are restricted to the root user only so if serverPort < 1024 you should try something > 1024

like image 101
rmonjo Avatar answered Sep 27 '22 17:09

rmonjo