mirror of
https://github.com/SFML/SFML.git
synced 2024-11-29 06:41:05 +08:00
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/IpAddress.hpp>
|
||||||
#include <SFML/Network/Http.hpp>
|
#include <SFML/Network/Http.hpp>
|
||||||
#include <SFML/Network/SocketImpl.hpp>
|
#include <SFML/Network/SocketImpl.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -48,9 +49,19 @@ namespace
|
|||||||
return ip;
|
return ip;
|
||||||
|
|
||||||
// Not a valid address, try to convert it as a host name
|
// Not a valid address, try to convert it as a host name
|
||||||
hostent* host = gethostbyname(address.c_str());
|
addrinfo hints;
|
||||||
if (host)
|
std::memset(&hints, 0, sizeof(hints));
|
||||||
return reinterpret_cast<in_addr*>(host->h_addr)->s_addr;
|
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
|
// Not a valid address nor a host name
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Socket.hpp>
|
#include <SFML/Network/Socket.hpp>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
|
Loading…
Reference in New Issue
Block a user