Wed Jan 8 2020 09:50:11

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) More...
 

Detailed Description

DNS support for Asterisk.

Author
Thorsten Lockert tholo.nosp@m.@tro.nosp@m.llpho.nosp@m.ne.o.nosp@m.rg

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 259 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().

262 {
263 #ifdef HAVE_RES_NINIT
264  struct __res_state dnsstate;
265 #endif
266  unsigned char answer[MAX_SIZE];
267  int res, ret = -1;
268 
269 #ifdef HAVE_RES_NINIT
270  memset(&dnsstate, 0, sizeof(dnsstate));
271  res_ninit(&dnsstate);
272  res = res_nsearch(&dnsstate, dname, class, type, answer, sizeof(answer));
273 #else
274  ast_mutex_lock(&res_lock);
275  res_init();
276  res = res_search(dname, class, type, answer, sizeof(answer));
277 #endif
278  if (res > 0) {
279  if ((res = dns_parse_answer(context, class, type, answer, res, callback)) < 0) {
280  ast_log(LOG_WARNING, "DNS Parse error for %s\n", dname);
281  ret = -1;
282  } else if (res == 0) {
283  ast_debug(1, "No matches found in DNS for %s\n", dname);
284  ret = 0;
285  } else
286  ret = 1;
287  }
288 #ifdef HAVE_RES_NINIT
289 #ifdef HAVE_RES_NDESTROY
290  res_ndestroy(&dnsstate);
291 #else
292  res_nclose(&dnsstate);
293 #endif
294 #else
295 #ifdef HAVE_RES_CLOSE
296  res_close();
297 #endif
298  ast_mutex_unlock(&res_lock);
299 #endif
300 
301  return ret;
302 }
#define LOG_WARNING
Definition: logger.h:144
#define ast_mutex_lock(a)
Definition: lock.h:155
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static const char type[]
Definition: chan_nbs.c:57
#define MAX_SIZE
Definition: dns.c:48
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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.
Definition: dns.c:189
#define ast_mutex_unlock(a)
Definition: lock.h:156