From 74bb3b6a8b33da340d3f9774a0ffb36ed69a7afb Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 9 May 2016 20:54:58 -0400 Subject: [PATCH] replaced deprecated gethostbyname by getaddrinfo. Only linux was using the re-entrant version, possibly causing bugs on windows+apple --- libretroshare/src/util/rsnet.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libretroshare/src/util/rsnet.cc b/libretroshare/src/util/rsnet.cc index 894438797..0f278bbe2 100644 --- a/libretroshare/src/util/rsnet.cc +++ b/libretroshare/src/util/rsnet.cc @@ -78,6 +78,20 @@ void sockaddr_clear(struct sockaddr_in *addr) bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) { + addrinfo *info = NULL; + int res = getaddrinfo(hostname.c_str(),NULL,NULL,&info) ; + + if(res > 0) + { + std::cerr << "(EE) getaddrinfo returned error " << res << " on string \"" << hostname << "\"" << std::endl; + returned_addr.s_addr = 0 ; + } + else + returned_addr.s_addr = ((sockaddr_in*)info->ai_addr)->sin_addr.s_addr ; + + freeaddrinfo(info) ; + +#ifdef DEPRECATED_TO_REMOVE #if defined(WINDOWS_SYS) || defined(__APPLE__) || defined(__HAIKU__) hostent *result = gethostbyname(hostname.c_str()) ; #else @@ -107,6 +121,7 @@ bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) // Use contents of result. returned_addr.s_addr = *(unsigned long*) (result->h_addr); +#endif return true ; }