diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/shared/Networking/Socket.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/server/shared/Networking/Socket.h b/src/server/shared/Networking/Socket.h index 9c3ec180b0a..059de140797 100644 --- a/src/server/shared/Networking/Socket.h +++ b/src/server/shared/Networking/Socket.h @@ -39,8 +39,33 @@ public: virtual void Start() = 0; - boost::asio::ip::address GetRemoteIpAddress() const { return _socket.remote_endpoint().address(); }; - uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); } + boost::asio::ip::address GetRemoteIpAddress() const + { + boost::system::error_code error; + auto ep = _socket.remote_endpoint(error); + + if (error) + { + TC_LOG_DEBUG("network", "Socket::GetRemoteIpAddress: errored with: %i (%s)", error.value(), error.message().c_str()); + return boost::asio::ip::address(); + } + else + return ep.address(); + } + + uint16 GetRemotePort() const + { + boost::system::error_code error; + auto ep = _socket.remote_endpoint(error); + + if (error) + { + TC_LOG_DEBUG("network", "Socket::GetRemotePort: errored with: %i (%s)", error.value(), error.message().c_str()); + return 0; + } + else + return ep.port(); + } void AsyncReadHeader() { |