diff options
author | Andrew Stitcher <astitcher@apache.org> | 2007-06-27 21:05:50 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2007-06-27 21:05:50 +0000 |
commit | 548abd065f91bc1f238ac98c24edf410edf10356 (patch) | |
tree | d0ee978aa1b30635ef8c215b6642b2751e695689 /cpp/src | |
parent | 9bac85e36d60df28fb6f86e3bbe9e3f46689aa04 (diff) | |
download | qpid-python-548abd065f91bc1f238ac98c24edf410edf10356.tar.gz |
Fixed missing POSIX implementation of Acceptor::getHost
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@551327 13f79535-47bb-0310-9956-ffa450edef68
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; |