Linux使用Boost Asio拒绝套接字绑定权限

Linux使用Boost Asio拒绝套接字绑定权限

问题描述:

我在绑定套接字时遇到问题,并且以用户身份运行该程序时遭到拒绝.这行代码会产生错误.

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)); 错误是

_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:权限被拒绝

what(): bind: Permission denied

但是,如果我以root身份运行,则可以正常运行.我尝试使用

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

sudo service apparmor stop
sudo ufw disable

但是我仍然有问题.我是否缺少可以拒绝渗透的东西? 我真的很想弄明白这一点,因为我不希望以root用户身份运行我的IDE和未经验证的程序.

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.

我正在运行xubuntu 13.10,并安装了所有更新.

I'm running xubuntu 13.10 with all updates installed.

在UNIX系统上,仅将第一个1024端口限制为root用户,因此,如果serverPort< 1024,您应该尝试> 1024

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