From 3cd98a374cde935d7056a35811e348f81e3214fe Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Thu, 28 May 2009 20:11:13 +0000 Subject: Fixes to get qpid to build with gcc4.4 with optimisation Fix for non thread safe use of inet_ntoa(). git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@779757 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/posix/SystemInfo.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid') diff --git a/cpp/src/qpid/sys/posix/SystemInfo.cpp b/cpp/src/qpid/sys/posix/SystemInfo.cpp index db3b48e6fe..f7d16c12c8 100755 --- a/cpp/src/qpid/sys/posix/SystemInfo.cpp +++ b/cpp/src/qpid/sys/posix/SystemInfo.cpp @@ -20,6 +20,8 @@ #include "qpid/sys/SystemInfo.h" +#include "check.h" + #include #include #include @@ -30,6 +32,7 @@ #include #include #include +#include #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 256 @@ -60,17 +63,20 @@ static const string LOCALHOST("127.0.0.1"); void SystemInfo::getLocalIpAddresses (uint16_t port, std::vector
&addrList) { - int s = socket (PF_INET, SOCK_STREAM, 0); + int s = ::socket(PF_INET, SOCK_STREAM, 0); for (int i=1;;i++) { - struct ifreq ifr; + ::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)); + ::sockaddr *saddr = (::sockaddr *) &ifr.ifr_addr; + char dispName[NI_MAXHOST]; + if (int rc=::getnameinfo(saddr, sizeof(ifr.ifr_addr), dispName, sizeof(dispName), 0, 0, NI_NUMERICHOST) != 0) + throw QPID_POSIX_ERROR(rc); + string addr(dispName); if (addr != LOCALHOST) addrList.push_back(TcpAddress(addr, port)); } -- cgit v1.2.1