Fri Jan 31 13:16:39 2014

Asterisk developer's documentation


dns.h File Reference

DNS support for Asterisk. More...

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 
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 247 of file dns.c.

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

Referenced by ast_get_enum(), ast_get_srv(), and ast_get_txt().

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


Generated on 31 Jan 2014 for Asterisk - the Open Source PBX by  doxygen 1.6.1