From: Gunnar Beutner Date: Mon, 25 Aug 2014 06:27:19 +0000 (+0200) Subject: Implement support for ApiListener::bind_host X-Git-Tag: v2.1.0~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c7f440a73f31d8c32449a6227fa370a7238f1de;p=icinga2 Implement support for ApiListener::bind_host fixes #6998 --- diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index bea5ed224..0e133ccd4 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -102,8 +102,8 @@ void ApiListener::Start(void) } /* create the primary JSON-RPC listener */ - if (!AddListener(GetBindPort())) { - Log(LogCritical, "ApiListener", "Cannot add listener for port '" + Convert::ToString(GetBindPort()) + "'."); + if (!AddListener(GetBindHost(), GetBindPort())) { + Log(LogCritical, "ApiListener", "Cannot add listener on host '" + GetBindHost() + "' for port '" + GetBindPort() + "'."); Application::Exit(EXIT_FAILURE); } @@ -160,9 +160,10 @@ bool ApiListener::IsMaster(void) const /** * Creates a new JSON-RPC listener on the specified port. * + * @param node The host the listener should be bound to. * @param service The port to listen on. */ -bool ApiListener::AddListener(const String& service) +bool ApiListener::AddListener(const String& node, const String& service) { ObjectLock olock(this); @@ -180,9 +181,9 @@ bool ApiListener::AddListener(const String& service) TcpSocket::Ptr server = make_shared(); try { - server->Bind(service, AF_UNSPEC); - } catch(std::exception&) { - Log(LogCritical, "ApiListener", "Cannot bind tcp socket on '" + service + "'."); + server->Bind(node, service, AF_UNSPEC); + } catch (const std::exception&) { + Log(LogCritical, "ApiListener", "Cannot bind TCP socket for host '" + node + "' on port '" + service + "'."); return false; } diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 498f8af57..0b756e140 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -79,7 +79,7 @@ private: void ApiTimerHandler(void); - bool AddListener(const String& service); + bool AddListener(const String& node, const String& service); void AddConnection(const Endpoint::Ptr& endpoint); void NewClientHandler(const Socket::Ptr& client, ConnectionRole role);