dns.c File Reference

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <unistd.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/dns.h>
#include "asterisk/endian.h"

Include dependency graph for dns.c:

Go to the source code of this file.

Data Structures

struct  dns_HEADER
struct  dn_answer

Defines

#define MAX_SIZE   4096

Functions

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

Variables

struct dn_answer __packed__


Define Documentation

#define MAX_SIZE   4096

Definition at line 24 of file dns.c.


Function Documentation

AST_MUTEX_DEFINE_STATIC ( res_lock   ) 

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

Definition at line 164 of file dns.c.

00167 {
00168 #ifdef HAS_RES_NINIT
00169    struct __res_state dnsstate;
00170 #endif
00171    char answer[MAX_SIZE];
00172    int res, ret = -1;
00173 
00174 #ifdef HAS_RES_NINIT
00175    res_ninit(&dnsstate);
00176    res = res_nsearch(&dnsstate, dname, class, type, answer, sizeof(answer));
00177 #else
00178    ast_mutex_lock(&res_lock);
00179    res_init();
00180    res = res_search(dname, class, type, answer, sizeof(answer));
00181 #endif
00182    if (res > 0) {
00183       if ((res = dns_parse_answer(context, class, type, answer, res, callback)) < 0) {
00184          ast_log(LOG_WARNING, "Parse error\n");
00185          ret = -1;
00186       }
00187       else if (ret == 0) {
00188          ast_log(LOG_DEBUG, "No matches found\n");
00189          ret = 0;
00190       }
00191       else
00192          ret = 1;
00193    }
00194 #ifdef HAS_RES_NINIT
00195    res_nclose(&dnsstate);
00196 #else
00197 #ifndef __APPLE__
00198    res_close();
00199 #endif
00200    ast_mutex_unlock(&res_lock);
00201 #endif
00202    return ret;
00203 }


Variable Documentation


Generated on Wed Oct 28 17:00:53 2009 for Asterisk by  doxygen 1.5.6