diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-07-09 15:30:54 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-07-09 15:30:54 +0200 |
commit | 45fd41eb38ce9cd0c5fd14d7278514b79d7debcd (patch) | |
tree | 7c6ddcb3538c3e45a01adcab47dd4e1e1c1c2e1c /louloulibs | |
parent | ece4b4969b296a3da010fb22768348650e70962d (diff) | |
download | biboumi-45fd41eb38ce9cd0c5fd14d7278514b79d7debcd.tar.gz biboumi-45fd41eb38ce9cd0c5fd14d7278514b79d7debcd.tar.bz2 biboumi-45fd41eb38ce9cd0c5fd14d7278514b79d7debcd.tar.xz biboumi-45fd41eb38ce9cd0c5fd14d7278514b79d7debcd.zip |
Display the resolved IP in debug logs
Diffstat (limited to 'louloulibs')
-rw-r--r-- | louloulibs/network/tcp_socket_handler.cpp | 17 | ||||
-rw-r--r-- | louloulibs/network/tcp_socket_handler.hpp | 5 |
2 files changed, 22 insertions, 0 deletions
diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 04bb321..cca6cd2 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -16,6 +16,7 @@ #include <fcntl.h> #include <iostream> +#include <arpa/inet.h> #ifdef BOTAN_FOUND # include <botan/hex.h> @@ -159,6 +160,9 @@ void TCPSocketHandler::connect(const std::string& address, const std::string& po break; } } + + this->display_resolved_ip(rp); + if (::connect(this->socket, rp->ai_addr, rp->ai_addrlen) == 0 || errno == EISCONN) { @@ -343,6 +347,19 @@ void TCPSocketHandler::close() this->port.clear(); } +void TCPSocketHandler::display_resolved_ip(struct addrinfo* rp) const +{ + char buf[INET6_ADDRSTRLEN]; + if (rp->ai_family == AF_INET) + log_debug("Connecting to IP address " << ::inet_ntop(rp->ai_family, + &reinterpret_cast<sockaddr_in*>(rp->ai_addr)->sin_addr, + buf, sizeof(buf))); + else if (rp->ai_family == AF_INET6) + log_debug("Connecting to IPv6 address " << ::inet_ntop(rp->ai_family, + &reinterpret_cast<sockaddr_in6*>(rp->ai_addr)->sin6_addr, + buf, sizeof(buf))); +} + void TCPSocketHandler::send_data(std::string&& data) { #ifdef BOTAN_FOUND diff --git a/louloulibs/network/tcp_socket_handler.hpp b/louloulibs/network/tcp_socket_handler.hpp index 8069825..835c509 100644 --- a/louloulibs/network/tcp_socket_handler.hpp +++ b/louloulibs/network/tcp_socket_handler.hpp @@ -264,6 +264,11 @@ private: TCPSocketHandler& operator=(const TCPSocketHandler&) = delete; TCPSocketHandler& operator=(TCPSocketHandler&&) = delete; + /** + * Display the resolved IP, just for information purpose. + */ + void display_resolved_ip(struct addrinfo* rp) const; + #ifdef BOTAN_FOUND /** * Botan stuff to manipulate a TLS session. |