DNS Support for Asterisk. More...
#include "asterisk.h"#include "asterisk/network.h"#include <arpa/nameser.h>#include <resolv.h>#include "asterisk/channel.h"#include "asterisk/dns.h"#include "asterisk/endian.h"
Go to the source code of this file.
Data Structures | |
| struct | dn_answer |
| struct | dns_HEADER |
Defines | |
| #define | MAX_SIZE 4096 |
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)) |
| Lookup record in DNS. | |
| static int | dns_parse_answer (void *context, int class, int type, unsigned char *answer, int len, int(*callback)(void *context, unsigned char *answer, int len, unsigned char *fullanswer)) |
| Parse DNS lookup result, call callback. | |
| static int | skip_name (unsigned char *s, int len) |
DNS Support for Asterisk.
Definition in file dns.c.
| #define MAX_SIZE 4096 |
Definition at line 44 of file dns.c.
Referenced by ast_search_dns().
| 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 | ||
| ) |
Lookup record in DNS.
Perform DNS lookup (used by DNS, enum and SRV lookups)
Definition at line 255 of file dns.c.
References ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, dns_parse_answer(), LOG_WARNING, and MAX_SIZE.
Referenced by ast_get_enum(), ast_get_srv(), ast_srv_lookup(), 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
#ifdef HAVE_RES_CLOSE
res_close();
#endif
ast_mutex_unlock(&res_lock);
#endif
return ret;
}
| static int dns_parse_answer | ( | void * | context, |
| int | class, | ||
| int | type, | ||
| unsigned char * | answer, | ||
| int | len, | ||
| int(*)(void *context, unsigned char *answer, int len, unsigned char *fullanswer) | callback | ||
| ) | [static] |
Parse DNS lookup result, call callback.
Definition at line 185 of file dns.c.
References dns_HEADER::ancount, ast_log(), dn_answer::class, LOG_WARNING, dns_HEADER::qdcount, dn_answer::rtype, dn_answer::size, and skip_name().
Referenced by ast_search_dns().
{
unsigned char *fullanswer = answer;
struct dn_answer *ans;
dns_HEADER *h;
int ret = 0;
int res;
int x;
h = (dns_HEADER *)answer;
answer += sizeof(dns_HEADER);
len -= sizeof(dns_HEADER);
for (x = 0; x < ntohs(h->qdcount); x++) {
if ((res = skip_name(answer, len)) < 0) {
ast_log(LOG_WARNING, "Couldn't skip over name\n");
return -1;
}
answer += res + 4; /* Skip name and QCODE / QCLASS */
len -= res + 4;
if (len < 0) {
ast_log(LOG_WARNING, "Strange query size\n");
return -1;
}
}
for (x = 0; x < ntohs(h->ancount); x++) {
if ((res = skip_name(answer, len)) < 0) {
ast_log(LOG_WARNING, "Failed skipping name\n");
return -1;
}
answer += res;
len -= res;
ans = (struct dn_answer *)answer;
answer += sizeof(struct dn_answer);
len -= sizeof(struct dn_answer);
if (len < 0) {
ast_log(LOG_WARNING, "Strange result size\n");
return -1;
}
if (len < 0) {
ast_log(LOG_WARNING, "Length exceeds frame\n");
return -1;
}
if (ntohs(ans->class) == class && ntohs(ans->rtype) == type) {
if (callback) {
if ((res = callback(context, answer, ntohs(ans->size), fullanswer)) < 0) {
ast_log(LOG_WARNING, "Failed to parse result\n");
return -1;
}
ret = 1;
}
}
answer += ntohs(ans->size);
len -= ntohs(ans->size);
}
return ret;
}
| static int skip_name | ( | unsigned char * | s, |
| int | len | ||
| ) | [static] |
Definition at line 161 of file dns.c.
Referenced by dns_parse_answer().