diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp | 33 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/Socket.cpp | 17 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/Socket.h | 2 |
3 files changed, 24 insertions, 28 deletions
diff --git a/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp b/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp index cbda216cfc..a61a66c577 100644 --- a/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp +++ b/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp @@ -18,13 +18,7 @@ * under the License. * */ -#include <iostream> - -#include <boost/assert.hpp> -#include <boost/ptr_container/ptr_vector.hpp> -#include <boost/ptr_container/ptr_deque.hpp> -#include <boost/bind.hpp> -#include <boost/scoped_ptr.hpp> +#include "EventChannelConnection.h" #include "qpid/sys/ConnectionOutputHandler.h" #include "qpid/sys/ConnectionInputHandler.h" @@ -35,7 +29,16 @@ #include "qpid/framing/AMQFrame.h" #include "qpid/Exception.h" -#include "EventChannelConnection.h" +#include <sys/socket.h> +#include <netdb.h> + +#include <boost/assert.hpp> +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/ptr_container/ptr_deque.hpp> +#include <boost/bind.hpp> +#include <boost/scoped_ptr.hpp> + +#include <iostream> namespace qpid { namespace sys { @@ -100,11 +103,19 @@ EventChannelAcceptor::EventChannelAcceptor( uint16_t EventChannelAcceptor::getPort() const { return port; // Immutable no need for lock. } + +std::string EventChannelAcceptor::getHost() const { + ::sockaddr_storage name; // big enough for any socket address + ::socklen_t namelen = sizeof(name); + if (::getsockname(listener.fd(), (::sockaddr*)&name, &namelen) < 0) + throw QPID_POSIX_ERROR(errno); -uint16_t EventChannelAcceptor::getPort() const { - return port; // Immutable no need for lock. + char dispName[NI_MAXHOST]; + if (int rc=::getnameinfo((::sockaddr*)&name, namelen, dispName, sizeof(dispName), 0, 0, NI_NUMERICHOST) != 0) + throw QPID_POSIX_ERROR(rc); + return dispName; } - + void EventChannelAcceptor::run(ConnectionInputHandlerFactory* f) { { Mutex::ScopedLock l(lock); diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp index 50cbfa7c4d..d46e7943d9 100644 --- a/cpp/src/qpid/sys/posix/Socket.cpp +++ b/cpp/src/qpid/sys/posix/Socket.cpp @@ -111,23 +111,8 @@ int Socket::listen(int port, int backlog) return ntohs(name.sin_port); } - -std::string getHost() const { - // TODO aconway 2007-06-11: Won't work for ip6 - struct sockaddr_in name; - socklen_t namelen = sizeof(name); - if (::getsockname(socket, (struct sockaddr*)&name, &namelen) < 0) - throw QPID_POSIX_ERROR(errno); - uint32_t addr = name.sin_host.s_addr; - ostringstream os; - os << uint8_t(addr >> 24) << '.' - << uint8_t(addr >> 16) << '.' - << uint8_t(addr >> 8) << '.' - << uint8_t(addr); - return os.str(); -} -int Socket::fd() +int Socket::fd() const { return socket; } diff --git a/cpp/src/qpid/sys/posix/Socket.h b/cpp/src/qpid/sys/posix/Socket.h index 614221354f..ca87104471 100644 --- a/cpp/src/qpid/sys/posix/Socket.h +++ b/cpp/src/qpid/sys/posix/Socket.h @@ -63,7 +63,7 @@ class Socket int listen(int port = 0, int backlog = 10); /** Get file descriptor */ - int fd(); + int fd() const; private: void init() const; |