diff options
author | Joshua Colp <jcolp@digium.com> | 2014-03-17 22:54:32 +0000 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2014-03-17 22:54:32 +0000 |
commit | cc40bf53173ec40a26d4eb35184dd7d39f208efc (patch) | |
tree | 9f38be9c86724ea595541fff54c7e041061f1301 /main/dns.c | |
parent | 932fb5a6e231c511a74e7a78693cdac1abad7690 (diff) |
res_pjsip: Enable PJSIP DNS client support.
This change enables DNS client support within PJSIP. System
nameservers are automatically discovered using res_init or
res_ninit. If this fails then PJSIP will resort to using
gethostbyname for resolution.
By enabling this support we gain SRV support, failover, and
weight support.
(closes issue ASTERISK-23435)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3343/
........
Merged revisions 410795 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410796 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/dns.c')
-rw-r--r-- | main/dns.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/main/dns.c b/main/dns.c index d5682758e..fb0e2acb7 100644 --- a/main/dns.c +++ b/main/dns.c @@ -296,3 +296,47 @@ int ast_search_dns(void *context, return ret; } + +struct ao2_container *ast_dns_get_nameservers(void) +{ +#ifdef HAVE_RES_NINIT + struct __res_state dnsstate; +#endif + struct __res_state *state; + struct ao2_container *nameservers; + int i; + + nameservers = ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 3); + if (!nameservers) { + return NULL; + } + +#ifdef HAVE_RES_NINIT + memset(&dnsstate, 0, sizeof(dnsstate)); + res_ninit(&dnsstate); + state = &dnsstate; +#else + ast_mutex_lock(&res_lock); + res_init(); + state = &_res; +#endif + + for (i = 0; i < state->nscount; i++) { + ast_str_container_add(nameservers, ast_inet_ntoa(state->nsaddr_list[i].sin_addr)); + } + +#ifdef HAVE_RES_NINIT +#ifdef HAVE_RES_NDESTROY + res_ndestroy(&dnsstate); +#else + res_nclose(&dnsstate); +#endif +#else +#ifdef HAVE_RES_CLOSE + res_close(); +#endif + ast_mutex_unlock(&res_lock); +#endif + + return nameservers; +}
\ No newline at end of file |