| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
DNS SRV Record Lookup Support for Asterisk. More...
#include "asterisk.h"#include <netinet/in.h>#include <arpa/nameser.h>#include <resolv.h>#include "asterisk/channel.h"#include "asterisk/srv.h"#include "asterisk/dns.h"#include "asterisk/utils.h"#include "asterisk/linkedlists.h"
Go to the source code of this file.
| Data Structures | |
| struct | srv_context | 
| struct | srv_context::srv_entries | 
| struct | srv_entry | 
| Functions | |
| int | ast_get_srv (struct ast_channel *chan, char *host, int hostlen, int *port, const char *service) | 
| Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup. | |
| void | ast_srv_cleanup (struct srv_context **context) | 
| Cleanup resources associated with ast_srv_lookup. | |
| int | ast_srv_get_nth_record (struct srv_context *context, int record_num, const char **host, unsigned short *port, unsigned short *priority, unsigned short *weight) | 
| Retrieve details from a specific SRV record. | |
| unsigned int | ast_srv_get_record_count (struct srv_context *context) | 
| Get the number of records for a given SRV context. | |
| int | ast_srv_lookup (struct srv_context **context, const char *service, const char **host, unsigned short *port) | 
| Retrieve set of SRV lookups, in order. | |
| static int | parse_srv (unsigned char *answer, int len, unsigned char *msg, struct srv_entry **result) | 
| static void | process_weights (struct srv_context *context) | 
| static int | srv_callback (void *context, unsigned char *answer, int len, unsigned char *fullanswer) | 
DNS SRV Record Lookup Support for Asterisk.
Definition in file srv.c.
| int ast_get_srv | ( | struct ast_channel * | chan, | 
| char * | host, | ||
| int | hostlen, | ||
| int * | port, | ||
| const char * | service | ||
| ) | 
Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup.
Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.
| 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 260 of file srv.c.
References ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), ast_debug, ast_free, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_REMOVE_HEAD, ast_search_dns(), current, srv_entry::host, srv_entry::list, srv_entry::port, process_weights(), service, and srv_callback().
Referenced by ast_get_ip_or_srv_with_preference().
| void ast_srv_cleanup | ( | struct srv_context ** | context | ) | 
Cleanup resources associated with ast_srv_lookup.
| context | Pointer passed into ast_srv_lookup | 
Definition at line 248 of file srv.c.
References ast_srv_lookup(), srv_entry::host, NULL, and srv_entry::port.
Referenced by ip_identify_match_srv_lookup(), launch_ha_netscript(), srds_destroy_cb(), and srv_datastore_setup().
| int ast_srv_get_nth_record | ( | struct srv_context * | context, | 
| int | record_num, | ||
| const char ** | host, | ||
| unsigned short * | port, | ||
| unsigned short * | priority, | ||
| unsigned short * | weight | ||
| ) | 
Retrieve details from a specific SRV record.
After calling ast_srv_lookup, the srv_context will contain the data from several records. You can retrieve the data of a specific one by asking for a specific record number. The records are sorted based on priority and secondarily based on weight. See RFC 2782 for the exact sorting rules.
| context | The context returned by ast_srv_lookup | |
| record_num | The 1-indexed record number to retrieve | |
| [out] | host | The host portion of the record | 
| [out] | port | The port portion of the record | 
| [out] | priority | The priority portion of the record | 
| [out] | weight | The weight portion of the record | 
| -1 | Failed to retrieve information. Likely due to an out of range record_num | 
| 0 | Success | 
Definition at line 309 of file srv.c.
References AST_LIST_TRAVERSE, srv_entry::host, srv_entry::list, srv_entry::port, priority, srv_entry::priority, weight, and srv_entry::weight.
Referenced by srv_result_read().
| unsigned int ast_srv_get_record_count | ( | struct srv_context * | context | ) | 
Get the number of records for a given SRV context.
This is meant to be used after calling ast_srv_lookup, so that one may retrieve the number of records returned during a specific SRV lookup.
| context | The context returned by ast_srv_lookup | 
Definition at line 304 of file srv.c.
Referenced by srv_result_read().
| int ast_srv_lookup | ( | struct srv_context ** | context, | 
| const char * | service, | ||
| const char ** | host, | ||
| unsigned short * | port | ||
| ) | 
Retrieve set of SRV lookups, in order.
| [in] | context | A pointer in which to hold the result | 
| [in] | service | The service name to look up | 
| [out] | host | Result host | 
| [out] | port | Associated TCP portnum | 
| -1 | Query failed | 
| 0 | Result exists in host and port | 
| 1 | No more results | 
Definition at line 202 of file srv.c.
References ast_calloc, ast_free, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_NEXT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_search_dns(), srv_entry::host, srv_entry::list, NULL, srv_entry::port, process_weights(), service, and srv_callback().
Referenced by ast_srv_cleanup(), ip_identify_match_srv_lookup(), launch_ha_netscript(), and srv_datastore_setup().
| 
 | static | 
Definition at line 72 of file srv.c.
References answer(), ast_calloc, ast_log, srv_entry::host, len(), LOG_WARNING, srv_entry::port, priority, srv_entry::priority, result, weight, and srv_entry::weight.
Referenced by srv_callback().
| 
 | static | 
Definition at line 150 of file srv.c.
References AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_MOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_random(), current, and srv_entry::priority.
Referenced by ast_get_srv(), and ast_srv_lookup().
| 
 | static | 
Definition at line 113 of file srv.c.
References answer(), AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, c, current, len(), srv_entry::list, NULL, parse_srv(), srv_entry::priority, and srv_entry::weight.
Referenced by ast_get_srv(), and ast_srv_lookup().