diff options
| author | Stephen D. Huston <shuston@apache.org> | 2008-10-09 15:20:49 +0000 |
|---|---|---|
| committer | Stephen D. Huston <shuston@apache.org> | 2008-10-09 15:20:49 +0000 |
| commit | 0b195851725cd2b0982d26a108e7239eca6b2052 (patch) | |
| tree | 0eeaa66dc3daa0147c92995cda6b0f014ac8c512 /cpp/src/qpid/Url.cpp | |
| parent | bfa255f4fd7a67f1433b424913515633d7e58c2f (diff) | |
| download | qpid-python-0b195851725cd2b0982d26a108e7239eca6b2052.tar.gz | |
Make Address/TcpAddress manipulation portable; extend SystemInfo functions to Windows; resolves QPID-1325
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@703179 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/Url.cpp')
| -rw-r--r-- | cpp/src/qpid/Url.cpp | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/cpp/src/qpid/Url.cpp b/cpp/src/qpid/Url.cpp index 95d6a34136..422939fdf4 100644 --- a/cpp/src/qpid/Url.cpp +++ b/cpp/src/qpid/Url.cpp @@ -19,6 +19,8 @@ #include "qpid/Url.h" #include "qpid/Exception.h" #include "qpid/Msg.h" +#include "qpid/sys/SystemInfo.h" +#include "qpid/sys/StrError.h" #include <limits.h> // NB: must be before boost/spirit headers. #include <boost/spirit.hpp> @@ -26,10 +28,6 @@ #include <sstream> -#include <sys/ioctl.h> -#include <net/if.h> -#include <unistd.h> -#include <arpa/inet.h> #include <stdio.h> #include <errno.h> @@ -45,31 +43,15 @@ std::ostream& operator<<(std::ostream& os, const TcpAddress& a) { std::istream& operator>>(std::istream&, const TcpAddress&); Url Url::getHostNameUrl(uint16_t port) { - char name[HOST_NAME_MAX]; - if (::gethostname(name, sizeof(name)) != 0) + TcpAddress address("", port); + if (!sys::SystemInfo::getLocalHostname(address)) throw InvalidUrl(QPID_MSG("Cannot get host name: " << qpid::sys::strError(errno))); - return Url(TcpAddress(name, port)); + return Url(address); } -static const string LOCALHOST("127.0.0.1"); - Url Url::getIpAddressesUrl(uint16_t port) { Url url; - int s = socket (PF_INET, SOCK_STREAM, 0); - for (int i=1;;i++) { - struct ifreq ifr; - ifr.ifr_ifindex = i; - if (::ioctl (s, SIOCGIFNAME, &ifr) < 0) - break; - /* now ifr.ifr_name is set */ - if (::ioctl (s, SIOCGIFADDR, &ifr) < 0) - continue; - struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; - string addr(inet_ntoa(sin->sin_addr)); - if (addr != LOCALHOST) - url.push_back(TcpAddress(addr, port)); - } - close (s); + sys::SystemInfo::getLocalIpAddresses(port, url); return url; } |
