Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:47 2009

## 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, char *answer, int len, char *fullanswer))
| Perform DNS lookup (used by 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, char *answer, int len, char *fullanswer) | callback |
| ) |  |  |

Perform DNS lookup (used by 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

Definition at line 248 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().

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