Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master f06721a40 -> 60f02126e


MINIFI-235: Resolve hostname ident

This closes #65

Signed-off-by: Jeremy Dyer <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/60f02126
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/60f02126
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/60f02126

Branch: refs/heads/master
Commit: 60f02126e42fd46164916375b00bdbba5e4cbfbd
Parents: f06721a
Author: Marc Parisi <[email protected]>
Authored: Wed Mar 8 20:28:48 2017 -0500
Committer: Jeremy Dyer <[email protected]>
Committed: Wed Mar 8 21:38:33 2017 -0500

----------------------------------------------------------------------
 libminifi/include/io/ClientSocket.h |  2 +-
 libminifi/src/io/ClientSocket.cpp   | 26 +++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/60f02126/libminifi/include/io/ClientSocket.h
----------------------------------------------------------------------
diff --git a/libminifi/include/io/ClientSocket.h 
b/libminifi/include/io/ClientSocket.h
index 7d3dbe2..3f8aae1 100644
--- a/libminifi/include/io/ClientSocket.h
+++ b/libminifi/include/io/ClientSocket.h
@@ -207,7 +207,7 @@ protected:
         * @param p addrinfo structure.
         * @returns fd.
         */
-       virtual int8_t createConnection(const addrinfo *p);
+       virtual int8_t createConnection(const addrinfo *p,in_addr_t &addr);
 
        /**
         * Sets socket options depending on the instance.

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/60f02126/libminifi/src/io/ClientSocket.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/io/ClientSocket.cpp 
b/libminifi/src/io/ClientSocket.cpp
index ab391a4..ebc2e44 100644
--- a/libminifi/src/io/ClientSocket.cpp
+++ b/libminifi/src/io/ClientSocket.cpp
@@ -78,7 +78,7 @@ void Socket::closeStream()
     }
 }
 
-int8_t Socket::createConnection(const addrinfo *p) {
+int8_t Socket::createConnection(const addrinfo *p,in_addr_t &addr) {
        if ((socket_file_descriptor_ = socket(p->ai_family, p->ai_socktype,
                        p->ai_protocol)) == -1) {
                logger_->log_error("error while connecting to server socket");
@@ -114,7 +114,7 @@ int8_t Socket::createConnection(const addrinfo *p) {
                }
                else
                {
-                 sa_loc->sin_addr.s_addr = 
inet_addr(requested_hostname_.c_str());
+                 sa_loc->sin_addr.s_addr = addr;
                }
                if (connect(socket_file_descriptor_, p->ai_addr, p->ai_addrlen) 
== -1) {
                          close(socket_file_descriptor_);
@@ -163,6 +163,25 @@ short Socket::initialize() {
 
        socket_file_descriptor_ = -1;
 
+       in_addr_t addr;
+         struct hostent *h;
+       #ifdef __MACH__
+         h = gethostbyname(requested_hostname_.c_str());
+       #else
+         const char *host;
+    uint16_t port;
+
+    host = requested_hostname_.c_str();
+    port = port_;
+         char buf[1024];
+         struct hostent he;
+         int hh_errno;
+         gethostbyname_r(host, &he, buf, sizeof(buf), &h, &hh_errno);
+       #endif
+
+         memcpy((char *) &addr, h->h_addr_list[0], h->h_length);
+
+
        auto p = addr_info_;
        for (; p != NULL; p = p->ai_next) {
                if (IsNullOrEmpty(canonical_hostname_)) {
@@ -170,8 +189,9 @@ short Socket::initialize() {
                                canonical_hostname_ = p->ai_canonname;
                }
 
+
                //we've successfully connected
-               if (port_ > 0 && createConnection(p) >= 0)
+               if (port_ > 0 && createConnection(p,addr) >= 0)
                {
                        return 0;
                        break;

Reply via email to