aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-09-14 12:46:08 +0200
committerRiccardo Spagni <ric@spagni.net>2018-09-14 12:46:08 +0200
commit20087b3a9de06295f16f128571623083194a9db5 (patch)
tree256961d8e1de47910a74e9df2ccfaa1fd7a708ba /contrib/epee/include
parentMerge pull request #4286 (diff)
parentabstract_tcp_server2: fix binding to the wrong IP (diff)
downloadmonero-20087b3a9de06295f16f128571623083194a9db5.tar.xz
Merge pull request #4307
4469b0c4 abstract_tcp_server2: fix binding to the wrong IP (moneromooo-monero) 8eab6147 epee: use the socket::bind variant which does not throw (moneromooo-monero)
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl24
1 files changed, 20 insertions, 4 deletions
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 59a126163..3a5c83017 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -1109,8 +1109,16 @@ POP_WARNINGS
sock_.open(remote_endpoint.protocol());
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{
- boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0);
- sock_.bind(local_endpoint);
+ boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(bind_ip.c_str()), 0);
+ boost::system::error_code ec;
+ sock_.bind(local_endpoint, ec);
+ if (ec)
+ {
+ MERROR("Error binding to " << bind_ip << ": " << ec.message());
+ if (sock_.is_open())
+ sock_.close();
+ return false;
+ }
}
/*
@@ -1215,8 +1223,16 @@ POP_WARNINGS
sock_.open(remote_endpoint.protocol());
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{
- boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0);
- sock_.bind(local_endpoint);
+ boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(bind_ip.c_str()), 0);
+ boost::system::error_code ec;
+ sock_.bind(local_endpoint, ec);
+ if (ec)
+ {
+ MERROR("Error binding to " << bind_ip << ": " << ec.message());
+ if (sock_.is_open())
+ sock_.close();
+ return false;
+ }
}
boost::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(io_service_));