aboutsummaryrefslogtreecommitdiffstats
path: root/dns/c-ares/files/ares-config-info.patch
blob: 427acdebcd71bdd710759cc8bb5877570ee54c7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 <roam@FreeBSD.org>
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    2013-02-17 11:44:02.000000000 -0500
+++ ares_init.c 2013-05-15 13:43:31.000000000 -0400
@@ -1875,6 +1875,36 @@
 }
 #endif  /* !WIN32 & !WATT32 & !ANDROID & !__ANDROID__ */
 
+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