Replaced the deprecated gethostbyname with getaddrinfo (#47)
This commit is contained in:
parent
96d0204f30
commit
34d866d4bc
@ -28,6 +28,7 @@
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
#include <SFML/Network/Http.hpp>
|
||||
#include <SFML/Network/SocketImpl.hpp>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
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<in_addr*>(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<sockaddr_in*>(result->ai_addr)->sin_addr.s_addr;
|
||||
freeaddrinfo(result);
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
|
||||
// Not a valid address nor a host name
|
||||
return 0;
|
||||
|
@ -30,6 +30,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
Loading…
Reference in New Issue
Block a user