From 34d866d4bc647b31678169da4b1a2f0891e0e176 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Fri, 21 Jun 2013 19:25:06 +0200 Subject: [PATCH] Replaced the deprecated gethostbyname with getaddrinfo (#47) --- src/SFML/Network/IpAddress.cpp | 17 ++++++++++++++--- src/SFML/Network/Win32/SocketImpl.hpp | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 346c4964c..c4efabafa 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace @@ -48,9 +49,19 @@ namespace return ip; // Not a valid address, try to convert it as a host name - hostent* host = gethostbyname(address.c_str()); - if (host) - return reinterpret_cast(host->h_addr)->s_addr; + addrinfo hints; + std::memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + addrinfo* result = NULL; + if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) + { + if (result) + { + ip = reinterpret_cast(result->ai_addr)->sin_addr.s_addr; + freeaddrinfo(result); + return ip; + } + } // Not a valid address nor a host name return 0; diff --git a/src/SFML/Network/Win32/SocketImpl.hpp b/src/SFML/Network/Win32/SocketImpl.hpp index 430d14b23..7d4162c64 100644 --- a/src/SFML/Network/Win32/SocketImpl.hpp +++ b/src/SFML/Network/Win32/SocketImpl.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include namespace sf