Go to the source code of this file.
Functions | |
int | ast_get_srv (struct ast_channel *chan, char *host, int hostlen, int *port, const char *service) |
Definition in file srv.h.
int ast_get_srv | ( | struct ast_channel * | chan, | |
char * | host, | |||
int | hostlen, | |||
int * | port, | |||
const char * | service | |||
) |
chan | Ast channel | |
host | host name (return value) | |
hostlen | Length of string "host" | |
port | Port number (return value) | |
service | Service tag for SRV lookup (like "_sip._udp" or "_stun._udp" |
Definition at line 206 of file srv.c.
References ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), ast_free, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_REMOVE_HEAD, ast_search_dns(), ast_verbose(), context, srv_entry::host, srv_entry::list, option_verbose, srv_entry::port, process_weights(), srv_callback(), and VERBOSE_PREFIX_3.
Referenced by ast_get_ip_or_srv(), and create_addr().
00207 { 00208 struct srv_context context = { .entries = AST_LIST_HEAD_NOLOCK_INIT_VALUE }; 00209 struct srv_entry *current; 00210 int ret; 00211 00212 if (chan && ast_autoservice_start(chan) < 0) 00213 return -1; 00214 00215 ret = ast_search_dns(&context, service, C_IN, T_SRV, srv_callback); 00216 00217 if (context.have_weights) 00218 process_weights(&context); 00219 00220 if (chan) 00221 ret |= ast_autoservice_stop(chan); 00222 00223 /* TODO: there could be a "." entry in the returned list of 00224 answers... if so, this requires special handling */ 00225 00226 /* the list of entries will be sorted in the proper selection order 00227 already, so we just need the first one (if any) */ 00228 00229 if ((ret > 0) && (current = AST_LIST_REMOVE_HEAD(&context.entries, list))) { 00230 ast_copy_string(host, current->host, hostlen); 00231 *port = current->port; 00232 ast_free(current); 00233 if (option_verbose > 3) { 00234 ast_verbose(VERBOSE_PREFIX_3 "ast_get_srv: SRV lookup for '%s' mapped to host %s, port %d\n", 00235 service, host, *port); 00236 } 00237 } else { 00238 host[0] = '\0'; 00239 *port = -1; 00240 } 00241 00242 while ((current = AST_LIST_REMOVE_HEAD(&context.entries, list))) 00243 ast_free(current); 00244 00245 return ret; 00246 }