From 3ac625efa58d1f60f238b74cb0596e67ff382648 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 27 Dec 2012 21:14:09 +0100 Subject: Fixed issue #17. --- src/platforms/windows/windowsSocket.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/platforms/windows/windowsSocket.cpp') diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp index 72c5f0f6..13de81ee 100644 --- a/src/platforms/windows/windowsSocket.cpp +++ b/src/platforms/windows/windowsSocket.cpp @@ -189,10 +189,15 @@ const string windowsSocket::getPeerAddress() const getpeername(m_desc, reinterpret_cast (&peer), &peerLen); // Convert to numerical presentation format - char numericAddress[1024]; + char host[NI_MAXHOST + 1]; + char service[NI_MAXSERV + 1]; - if (inet_ntop(peer.sa_family, &peer, numericAddress, sizeof(numericAddress)) != NULL) - return string(numericAddress); + if (getnameinfo(reinterpret_cast (&peer), peerLen, + host, sizeof(host), service, sizeof(service), + /* flags */ NI_NUMERICHOST) == 0) + { + return string(host); + } return ""; // should not happen } -- cgit v1.2.3