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). |
Definition in file dns.h.
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).
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().
00262 { 00263 #ifdef HAVE_RES_NINIT 00264 struct __res_state dnsstate; 00265 #endif 00266 unsigned char answer[MAX_SIZE]; 00267 int res, ret = -1; 00268 00269 #ifdef HAVE_RES_NINIT 00270 memset(&dnsstate, 0, sizeof(dnsstate)); 00271 res_ninit(&dnsstate); 00272 res = res_nsearch(&dnsstate, dname, class, type, answer, sizeof(answer)); 00273 #else 00274 ast_mutex_lock(&res_lock); 00275 res_init(); 00276 res = res_search(dname, class, type, answer, sizeof(answer)); 00277 #endif 00278 if (res > 0) { 00279 if ((res = dns_parse_answer(context, class, type, answer, res, callback)) < 0) { 00280 ast_log(LOG_WARNING, "DNS Parse error for %s\n", dname); 00281 ret = -1; 00282 } else if (res == 0) { 00283 ast_debug(1, "No matches found in DNS for %s\n", dname); 00284 ret = 0; 00285 } else 00286 ret = 1; 00287 } 00288 #ifdef HAVE_RES_NINIT 00289 #ifdef HAVE_RES_NDESTROY 00290 res_ndestroy(&dnsstate); 00291 #else 00292 res_nclose(&dnsstate); 00293 #endif 00294 #else 00295 #ifdef HAVE_RES_CLOSE 00296 res_close(); 00297 #endif 00298 ast_mutex_unlock(&res_lock); 00299 #endif 00300 00301 return ret; 00302 }