]> granicus.if.org Git - icinga2/commitdiff
Implement support for ApiListener::bind_host
authorGunnar Beutner <gunnar@beutner.name>
Mon, 25 Aug 2014 06:27:19 +0000 (08:27 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 25 Aug 2014 06:27:19 +0000 (08:27 +0200)
fixes #6998

lib/remote/apilistener.cpp
lib/remote/apilistener.hpp

index bea5ed224ff082313c363633a09e4623c0befeb0..0e133ccd41a5129d49c0d397918a637052ec1ef0 100644 (file)
@@ -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<TcpSocket>();
 
        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;
        }
 
index 498f8af571acfeb9bd9276184bb974cc852e4f18..0b756e140cf82ca6c5a120b20afd6f24333eac8e 100644 (file)
@@ -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);