Linux denies permission on socket bind using boost

2020-07-11 09:18发布

问题:

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.

回答1:

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