Description: Add the ares_get_config() routine used by Unreal IRCd. Originally taken from the Unreal IRCd distribution, later modified by me to properly support IPv6 nameserver addresses since c-ares-1.7.1. Origin: the Unreal IRCd distribution Author: Peter Pentchev Forwarded: no Last-Update: 2010-12-19 --- ares.h.orig +++ ares.h @@ -260,6 +260,14 @@ int nsort; }; +/** Public available config (readonly) interface for ares_get_config(). */ +struct ares_config_info { + int timeout; + int tries; + int numservers; + char **servers; +}; + struct hostent; struct timeval; struct sockaddr; @@ -530,6 +538,8 @@ CARES_EXTERN int ares_get_servers(ares_channel channel, struct ares_addr_node **servers); +CARES_EXTERN int ares_get_config(struct ares_config_info *d, ares_channel c); + #ifdef __cplusplus } #endif --- ares_init.c.orig +++ ares_init.c @@ -66,6 +66,7 @@ #include #include "ares.h" #include "inet_net_pton.h" +#include "inet_ntop.h" #include "ares_library_init.h" #include "ares_nowarn.h" #include "ares_private.h" @@ -1536,6 +1537,36 @@ } #endif /* !WIN32 && !WATT32 */ +int ares_get_config(struct ares_config_info *d, ares_channel c) +{ + int i; + const char *p; + char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")]; + + memset(d, 0, sizeof(struct ares_config_info)); + + d->timeout = c->timeout; + d->tries = c->tries; + d->numservers = c->nservers; + d->servers = calloc(sizeof(char *), c->nservers); + for (i = 0; i < c->nservers; i++) + { + if (c->servers[i].addr.family == AF_INET) + p = ares_inet_ntop(c->servers[i].addr.family, + (const char *)&c->servers[i].addr.addrV4, + tmp, sizeof(tmp)); + else if (c->servers[i].addr.family == AF_INET6) + p = ares_inet_ntop(c->servers[i].addr.family, + (const char *)&c->servers[i].addr.addrV6, + tmp, sizeof(tmp)); + else + p = NULL; + d->servers[i] = p ? strdup(p) : NULL; + } + + return ARES_SUCCESS; +} + /* initialize an rc4 key. If possible a cryptographically secure random key is generated using a suitable function (for example win32's RtlGenRandom as described in