32 #include <netinet/in.h> 33 #include <arpa/nameser.h> 48 const char *end_of_record;
51 char host[NI_MAXHOST] =
"";
57 end_of_record = ptr + size;
61 if (ptr >= end_of_record) {
67 if (ptr >= end_of_record) {
73 if (ptr >= end_of_record) {
82 host_size = dn_expand((
unsigned char *)query->
result->
answer,
83 (
unsigned char *) end_of_record, (
unsigned char *) ptr, host,
sizeof(host) - 1);
89 if (!strcmp(host,
".")) {
93 host_len = strlen(host) + 1;
94 srv =
ast_calloc(1,
sizeof(*srv) + size + host_len);
154 unsigned int random_weight;
162 if (weight_sum == 0) {
167 random_weight = 1 + (
unsigned int) ((
float) weight_sum * (
ast_random() / ((float) RAND_MAX + 1.0)));
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
char data[0]
Additional data.
char * data_ptr
pointer to record-specific data.
int dns_parse_short(unsigned char *cur, uint16_t *val)
Parse a 16-bit unsigned value from a DNS record.
unsigned short port
The port in the SRV record.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
unsigned short ast_dns_srv_get_priority(const struct ast_dns_record *record)
Get the priority from an SRV record.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
long int ast_random(void)
struct ast_dns_record generic
Generic DNS record information.
A set of macros to manage forward-linked lists.
#define AST_LIST_MOVE_CURRENT(newhead, field)
Move the current list entry to another list.
char data[0]
The raw DNS record.
The result of a DNS query.
const char * ast_dns_srv_get_host(const struct ast_dns_record *record)
Get the hostname from an SRV record.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
unsigned short ast_dns_srv_get_weight(const struct ast_dns_record *record)
Get the weight from an SRV record.
struct ast_dns_result * result
Result of the DNS query.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Internal DNS structure definitions.
#define ast_calloc(num, len)
A wrapper for calloc()
unsigned short weight
The weight of the SRV record.
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
const char * host
The hostname in the SRV record.
struct ast_dns_record * dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size)
Allocate and parse a DNS SRV record.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
unsigned int weight_sum
The running weight sum.
char * dns_find_record(const char *record, size_t record_size, const char *response, size_t response_size)
Find the location of a DNS record within the entire DNS answer.
size_t answer_size
The size of the raw DNS answer.
DNS SRV Record Parsing API.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
void dns_srv_sort(struct ast_dns_result *result)
Sort the SRV records on a result.
int ast_dns_record_get_rr_type(const struct ast_dns_record *record)
Get the resource record type of a DNS record.
const char * answer
The raw DNS answer.
struct ast_dns_result::dns_records records
unsigned short ast_dns_srv_get_port(const struct ast_dns_record *record)
Get the port from an SRV record.
unsigned short priority
The priority of the SRV record.
#define AST_LIST_APPEND_LIST(head, list, field)
Appends a whole list to the tail of a list.