Thu Apr 28 2011 16:57:09

Asterisk developer's documentation


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

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

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
dnameDomain name to lookup (host, SRV domain, TXT record name)
classRecord Class (see "man res_search")
typeRecord type (see "man res_search")
callbackCallback 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(), blr_ebl(), and blr_txt().

{
#ifdef HAVE_RES_NINIT
   struct __res_state dnsstate;
#endif
   unsigned char answer[MAX_SIZE];
   int res, ret = -1;

#ifdef HAVE_RES_NINIT
   memset(&dnsstate, 0, sizeof(dnsstate));
   res_ninit(&dnsstate);
   res = res_nsearch(&dnsstate, dname, class, type, answer, sizeof(answer));
#else
   ast_mutex_lock(&res_lock);
   res_init();
   res = res_search(dname, class, type, answer, sizeof(answer));
#endif
   if (res > 0) {
      if ((res = dns_parse_answer(context, class, type, answer, res, callback)) < 0) {
         ast_log(LOG_WARNING, "DNS Parse error for %s\n", dname);
         ret = -1;
      } else if (res == 0) {
         ast_debug(1, "No matches found in DNS for %s\n", dname);
         ret = 0;
      } else
         ret = 1;
   }
#ifdef HAVE_RES_NINIT
#ifdef HAVE_RES_NDESTROY
   res_ndestroy(&dnsstate);
#else
   res_nclose(&dnsstate);
#endif
#else
#ifndef __APPLE__
   res_close();
#endif
   ast_mutex_unlock(&res_lock);
#endif

   return ret;
}