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 200 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_verb, chan, context, srv_entry::host, srv_entry::list, srv_entry::port, process_weights(), and srv_callback().
Referenced by ast_get_ip_or_srv(), and create_addr().
00201 { 00202 struct srv_context context = { .entries = AST_LIST_HEAD_NOLOCK_INIT_VALUE }; 00203 struct srv_entry *current; 00204 int ret; 00205 00206 if (chan && ast_autoservice_start(chan) < 0) 00207 return -1; 00208 00209 ret = ast_search_dns(&context, service, C_IN, T_SRV, srv_callback); 00210 00211 if (context.have_weights) 00212 process_weights(&context); 00213 00214 if (chan) 00215 ret |= ast_autoservice_stop(chan); 00216 00217 /* TODO: there could be a "." entry in the returned list of 00218 answers... if so, this requires special handling */ 00219 00220 /* the list of entries will be sorted in the proper selection order 00221 already, so we just need the first one (if any) */ 00222 00223 if ((ret > 0) && (current = AST_LIST_REMOVE_HEAD(&context.entries, list))) { 00224 ast_copy_string(host, current->host, hostlen); 00225 *port = current->port; 00226 ast_free(current); 00227 ast_verb(4, "ast_get_srv: SRV lookup for '%s' mapped to host %s, port %d\n", 00228 service, host, *port); 00229 } else { 00230 host[0] = '\0'; 00231 *port = -1; 00232 } 00233 00234 while ((current = AST_LIST_REMOVE_HEAD(&context.entries, list))) 00235 ast_free(current); 00236 00237 return ret; 00238 }