diff --git a/include/AresHandler.h b/include/AresHandler.h index dc81504dbb..796c3912d1 100644 --- a/include/AresHandler.h +++ b/include/AresHandler.h @@ -54,6 +54,11 @@ class AresHandler return status; }; private: +#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 + static void staticCallback1(void *arg, int status, + int timeout, struct ares_addrinfo *result); +#endif + #if ARES_VERSION_MAJOR >= 1 && ARES_VERSION_MINOR >= 5 static void staticCallback(void *arg, int statusCallback, int timeouts, struct hostent *hostent); @@ -62,6 +67,9 @@ class AresHandler struct hostent *hostent); #endif void callback(int status, struct hostent *hostent); +#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 + void callback1(int status, struct ares_addrinfo *result); +#endif int index; std::string hostName; diff --git a/src/net/AresHandler.cxx b/src/net/AresHandler.cxx index d5d4f28987..46fd7fc583 100644 --- a/src/net/AresHandler.cxx +++ b/src/net/AresHandler.cxx @@ -120,10 +120,31 @@ void AresHandler::queryHost(const char *name) // launch the asynchronous query to look up this hostname status = HbNPending; + +#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 + struct ares_addrinfo_hints hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + + ares_getaddrinfo(aresChannel, name, NULL, &hints, staticCallback1, + (void *)this); +#else ares_gethostbyname(aresChannel, name, AF_INET, staticCallback, (void *)this); +#endif } +#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 +void AresHandler::staticCallback1(void *arg, int status, + int, struct ares_addrinfo *result) +{ + if (status == ARES_EDESTRUCTION) + return; + + ((AresHandler *)arg)->callback1(status, result); +} +#endif + #if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 5 void AresHandler::staticCallback(void *arg, int callbackStatus, int, struct hostent *hostent) @@ -161,6 +182,27 @@ void AresHandler::callback(int callbackStatus, struct hostent *hostent) } } +#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 +void AresHandler::callback1(int callbackStatus, struct ares_addrinfo *result) +{ + const std::lock_guard lock(callback_mutex); + + if (callbackStatus != ARES_SUCCESS) + { + logDebugMessage(1,"Player [%d] failed to resolve: error %d\n", index, + callbackStatus); + status = Failed; + } + else if (status == HbNPending) + { + memcpy(&hostAddress, + &((sockaddr_in *)result->nodes->ai_addr)->sin_addr, + sizeof(hostAddress)); + status = HbNSucceeded; + } +} +#endif + const char *AresHandler::getHostname() { if (!callback_mutex.try_lock())