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