dns.h File Reference

DNS support for Asterisk. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct ao2_containerast_dns_get_nameservers (void)
 Retrieve the configured nameservers of the system.
int ast_search_dns (void *context, const char *dname, int class, int type, int(*callback)(void *context, unsigned char *answer, int len, unsigned char *fullanswer))
 Perform DNS lookup (used by DNS, enum and SRV lookups).


Detailed Description

DNS support for Asterisk.

Author:
Thorsten Lockert <tholo@trollphone.org>

Definition in file dns.h.


Function Documentation

struct ao2_container* ast_dns_get_nameservers ( void   )  [read]

Retrieve the configured nameservers of the system.

Definition at line 300 of file dns.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ast_inet_ntoa(), ast_mutex_lock, ast_mutex_unlock, ast_str_container_add(), ast_str_container_alloc_options(), NULL, and res_lock.

Referenced by system_create_resolver_and_set_nameservers().

00301 {
00302 #ifdef HAVE_RES_NINIT
00303    struct __res_state dnsstate;
00304 #endif
00305    struct __res_state *state;
00306    struct ao2_container *nameservers;
00307    int i;
00308 
00309    nameservers = ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 3);
00310    if (!nameservers) {
00311       return NULL;
00312    }
00313 
00314 #ifdef HAVE_RES_NINIT
00315    memset(&dnsstate, 0, sizeof(dnsstate));
00316    res_ninit(&dnsstate);
00317    state = &dnsstate;
00318 #else
00319    ast_mutex_lock(&res_lock);
00320    res_init();
00321    state = &_res;
00322 #endif
00323 
00324    for (i = 0; i < state->nscount; i++) {
00325       ast_str_container_add(nameservers, ast_inet_ntoa(state->nsaddr_list[i].sin_addr));
00326    }
00327 
00328 #ifdef HAVE_RES_NINIT
00329 #ifdef HAVE_RES_NDESTROY
00330    res_ndestroy(&dnsstate);
00331 #else
00332    res_nclose(&dnsstate);
00333 #endif
00334 #else
00335 #ifdef HAVE_RES_CLOSE
00336    res_close();
00337 #endif
00338    ast_mutex_unlock(&res_lock);
00339 #endif
00340 
00341    return nameservers;
00342 }

int ast_search_dns ( void *  context,
const char *  dname,
int  class,
int  type,
int(*)(void *context, unsigned char *answer, int len, unsigned char *fullanswer)  callback 
)

Perform DNS lookup (used by DNS, enum and SRV lookups).

Parameters:
context 
dname Domain name to lookup (host, SRV domain, TXT record name)
class Record Class (see "man res_search")
type Record type (see "man res_search")
callback Callback function for handling DNS result
Note:
Asterisk DNS is synchronus at this time. This means that if your DNS services does not work, Asterisk may lock while waiting for response.
Perform DNS lookup (used by DNS, enum and SRV lookups).

Note:
Asterisk DNS is synchronus at this time. This means that if your DNS does not work properly, Asterisk might not start properly or a channel may lock.

Definition at line 255 of file dns.c.

References ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, dns_parse_answer(), LOG_WARNING, MAX_SIZE, and res_lock.

Referenced by ast_get_enum(), ast_get_srv(), ast_srv_lookup(), blr_ebl(), and blr_txt().

00258 {
00259 #ifdef HAVE_RES_NINIT
00260    struct __res_state dnsstate;
00261 #endif
00262    unsigned char answer[MAX_SIZE];
00263    int res, ret = -1;
00264 
00265 #ifdef HAVE_RES_NINIT
00266    memset(&dnsstate, 0, sizeof(dnsstate));
00267    res_ninit(&dnsstate);
00268    res = res_nsearch(&dnsstate, dname, class, type, answer, sizeof(answer));
00269 #else
00270    ast_mutex_lock(&res_lock);
00271    res_init();
00272    res = res_search(dname, class, type, answer, sizeof(answer));
00273 #endif
00274    if (res > 0) {
00275       if ((res = dns_parse_answer(context, class, type, answer, res, callback)) < 0) {
00276          ast_log(LOG_WARNING, "DNS Parse error for %s\n", dname);
00277          ret = -1;
00278       } else if (res == 0) {
00279          ast_debug(1, "No matches found in DNS for %s\n", dname);
00280          ret = 0;
00281       } else
00282          ret = 1;
00283    }
00284 #ifdef HAVE_RES_NINIT
00285 #ifdef HAVE_RES_NDESTROY
00286    res_ndestroy(&dnsstate);
00287 #else
00288    res_nclose(&dnsstate);
00289 #endif
00290 #else
00291 #ifdef HAVE_RES_CLOSE
00292    res_close();
00293 #endif
00294    ast_mutex_unlock(&res_lock);
00295 #endif
00296 
00297    return ret;
00298 }


Generated on Thu Apr 16 06:30:42 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6