Asterisk - The Open Source Telephony Project GIT-master-f36a736
Typedefs | Functions
dns_core.h File Reference

Core DNS API. More...

#include "asterisk/netsock2.h"
Include dependency graph for dns_core.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* ast_dns_resolve_callback) (const struct ast_dns_query *query)
 Callback invoked when a query completes. More...
 

Functions

void * ast_dns_query_get_data (const struct ast_dns_query *query)
 Get the user specific data of a DNS query. More...
 
const char * ast_dns_query_get_name (const struct ast_dns_query *query)
 Get the name queried in a DNS query. More...
 
struct ast_dns_resultast_dns_query_get_result (const struct ast_dns_query *query)
 Get the result information for a DNS query. More...
 
int ast_dns_query_get_rr_class (const struct ast_dns_query *query)
 Get the record resource class of a DNS query. More...
 
int ast_dns_query_get_rr_type (const struct ast_dns_query *query)
 Get the record resource type of a DNS query. More...
 
const char * ast_dns_record_get_data (const struct ast_dns_record *record)
 Retrieve the raw DNS record. More...
 
size_t ast_dns_record_get_data_size (const struct ast_dns_record *record)
 Retrieve the size of the raw DNS record. More...
 
const struct ast_dns_recordast_dns_record_get_next (const struct ast_dns_record *record)
 Get the next DNS record. More...
 
int ast_dns_record_get_rr_class (const struct ast_dns_record *record)
 Get the resource record class of a DNS record. More...
 
int ast_dns_record_get_rr_type (const struct ast_dns_record *record)
 Get the resource record type of a DNS record. More...
 
int ast_dns_record_get_ttl (const struct ast_dns_record *record)
 Get the TTL of a DNS record. More...
 
int ast_dns_resolve (const char *name, int rr_type, int rr_class, struct ast_dns_result **result)
 Synchronously resolve a DNS query. More...
 
struct ast_dns_query_activeast_dns_resolve_async (const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
 Asynchronously resolve a DNS query. More...
 
int ast_dns_resolve_cancel (struct ast_dns_query_active *active)
 Cancel an asynchronous DNS resolution. More...
 
int ast_dns_resolve_ipv6_and_ipv4 (struct ast_sockaddr *address, const char *host, const char *port)
 Synchronously resolves host to an AAAA or A record. More...
 
void ast_dns_result_free (struct ast_dns_result *result)
 Free the DNS result information. More...
 
const char * ast_dns_result_get_answer (const struct ast_dns_result *result)
 Get the raw DNS answer from a DNS result. More...
 
unsigned int ast_dns_result_get_bogus (const struct ast_dns_result *result)
 Get whether the result is bogus or not. More...
 
const char * ast_dns_result_get_canonical (const struct ast_dns_result *result)
 Get the canonical name of the result. More...
 
int ast_dns_result_get_lowest_ttl (const struct ast_dns_result *result)
 Retrieve the lowest TTL from a result. More...
 
unsigned int ast_dns_result_get_rcode (const struct ast_dns_result *result)
 Get the error rcode of a DN result. More...
 
const struct ast_dns_recordast_dns_result_get_records (const struct ast_dns_result *result)
 Get the first record of a DNS Result. More...
 
unsigned int ast_dns_result_get_secure (const struct ast_dns_result *result)
 Get whether the result is secure or not. More...
 

Detailed Description

Core DNS API.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file dns_core.h.

Typedef Documentation

◆ ast_dns_resolve_callback

typedef void(* ast_dns_resolve_callback) (const struct ast_dns_query *query)

Callback invoked when a query completes.

Parameters
queryThe DNS query that was invoked

Definition at line 171 of file dns_core.h.

Function Documentation

◆ ast_dns_query_get_data()

void * ast_dns_query_get_data ( const struct ast_dns_query query)

Get the user specific data of a DNS query.

Parameters
queryThe DNS query
Returns
the user specific data
Note
The reference count of the data is NOT incremented on return

Definition at line 72 of file dns_core.c.

73{
74 return query->user_data;
75}
void * user_data
User-specific data.
Definition: dns_internal.h:141

References ast_dns_query::user_data.

Referenced by async_callback(), dns_query_recurring_resolution_callback(), dns_query_set_callback(), dns_synchronous_resolve_callback(), query_set_cancel(), query_set_resolve(), recurring_cancel(), recurring_resolve(), and resolution_thread().

◆ ast_dns_query_get_name()

const char * ast_dns_query_get_name ( const struct ast_dns_query query)

Get the name queried in a DNS query.

Parameters
queryThe DNS query
Returns
the name queried

Definition at line 57 of file dns_core.c.

58{
59 return query->name;
60}
char name[0]
The name of what is being resolved.
Definition: dns_internal.h:153

References ast_dns_query::name.

Referenced by dns_system_resolver_process_query(), dns_system_resolver_resolve(), dns_system_resolver_set_response(), query_set_test(), unbound_resolver_callback(), and unbound_resolver_resolve().

◆ ast_dns_query_get_result()

struct ast_dns_result * ast_dns_query_get_result ( const struct ast_dns_query query)

Get the result information for a DNS query.

Parameters
queryThe DNS query
Returns
the DNS result information
Note
The result is NOT ao2 allocated

Definition at line 77 of file dns_core.c.

78{
79 return query->result;
80}
struct ast_dns_result * result
Result of the DNS query.
Definition: dns_internal.h:147

References ast_dns_query::result.

Referenced by ast_dns_resolve_ipv6_and_ipv4(), AST_TEST_DEFINE(), dns_query_recurring_resolution_callback(), dns_system_resolver_set_response(), and test_results().

◆ ast_dns_query_get_rr_class()

int ast_dns_query_get_rr_class ( const struct ast_dns_query query)

Get the record resource class of a DNS query.

Parameters
queryThe DNS query
Returns
the record resource class

Definition at line 67 of file dns_core.c.

68{
69 return query->rr_class;
70}
int rr_class
Resource record class.
Definition: dns_internal.h:151

References ast_dns_query::rr_class.

Referenced by dns_system_resolver_add_record(), dns_system_resolver_process_query(), query_set_test(), and unbound_resolver_resolve().

◆ ast_dns_query_get_rr_type()

int ast_dns_query_get_rr_type ( const struct ast_dns_query query)

Get the record resource type of a DNS query.

Parameters
queryThe DNS query
Returns
the record resource type

Definition at line 62 of file dns_core.c.

63{
64 return query->rr_type;
65}
int rr_type
Resource record type.
Definition: dns_internal.h:149

References ast_dns_query::rr_type.

Referenced by ast_dns_resolver_completed(), dns_system_resolver_add_record(), dns_system_resolver_process_query(), query_set_test(), and unbound_resolver_resolve().

◆ ast_dns_record_get_data()

const char * ast_dns_record_get_data ( const struct ast_dns_record record)

Retrieve the raw DNS record.

Parameters
recordThe DNS record
Returns
the raw DNS record

Definition at line 160 of file dns_core.c.

161{
162 return record->data_ptr;
163}
char * data_ptr
pointer to record-specific data.
Definition: dns_internal.h:58

References ast_dns_record::data_ptr.

Referenced by ast_dns_resolve_ipv6_and_ipv4(), ast_dns_txt_get_strings(), and test_record().

◆ ast_dns_record_get_data_size()

size_t ast_dns_record_get_data_size ( const struct ast_dns_record record)

Retrieve the size of the raw DNS record.

Parameters
recordThe DNS record
Returns
the size of the raw DNS record

Definition at line 165 of file dns_core.c.

166{
167 return record->data_len;
168}
size_t data_len
The size of the raw DNS record.
Definition: dns_internal.h:47

References ast_dns_record::data_len.

Referenced by ast_dns_resolve_ipv6_and_ipv4(), and ast_dns_txt_get_strings().

◆ ast_dns_record_get_next()

const struct ast_dns_record * ast_dns_record_get_next ( const struct ast_dns_record record)

Get the next DNS record.

Parameters
recordThe current DNS record
Returns
the next DNS record

Definition at line 170 of file dns_core.c.

171{
172 return AST_LIST_NEXT(record, list);
173}
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439

References AST_LIST_NEXT, and ast_dns_record::list.

Referenced by ast_dns_resolve_ipv6_and_ipv4(), ast_dns_result_get_lowest_ttl(), AST_TEST_DEFINE(), and nominal_test().

◆ ast_dns_record_get_rr_class()

int ast_dns_record_get_rr_class ( const struct ast_dns_record record)

Get the resource record class of a DNS record.

Parameters
recordThe DNS record
Returns
the resource record class

Definition at line 150 of file dns_core.c.

151{
152 return record->rr_class;
153}
int rr_class
Resource record class.
Definition: dns_internal.h:43

References ast_dns_record::rr_class.

Referenced by test_record().

◆ ast_dns_record_get_rr_type()

int ast_dns_record_get_rr_type ( const struct ast_dns_record record)

◆ ast_dns_record_get_ttl()

int ast_dns_record_get_ttl ( const struct ast_dns_record record)

Get the TTL of a DNS record.

Parameters
recordThe DNS record
Returns
the TTL

Definition at line 155 of file dns_core.c.

156{
157 return record->ttl;
158}
int ttl
Time-to-live of the record.
Definition: dns_internal.h:45

References ast_dns_record::ttl.

Referenced by ast_dns_result_get_lowest_ttl(), and test_record().

◆ ast_dns_resolve()

int ast_dns_resolve ( const char *  name,
int  rr_type,
int  rr_class,
struct ast_dns_result **  result 
)

Synchronously resolve a DNS query.

Parameters
nameThe name of what to resolve
rr_typeResource record type
rr_classResource record class
resultA pointer to hold the DNS result
Return values
0success - query was completed and result is available
-1failure

Definition at line 314 of file dns_core.c.

315{
316 struct dns_synchronous_resolve *synchronous;
317 struct ast_dns_query_active *active;
318
319 if (ast_strlen_zero(name)) {
320 ast_log(LOG_WARNING, "Could not perform synchronous resolution, no name provided\n");
321 return -1;
322 } else if (rr_type > 65536) {
323 ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
324 name, rr_type);
325 return -1;
326 } else if (rr_type < 0) {
327 ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', invalid resource record type '%d'\n",
328 name, rr_type);
329 return -1;
330 } else if (rr_class > 65536) {
331 ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
332 name, rr_class);
333 return -1;
334 } else if (rr_class < 0) {
335 ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', invalid resource class '%d'\n",
336 name, rr_class);
337 return -1;
338 } else if (!result) {
339 ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', no result pointer provided for storing results\n",
340 name);
341 return -1;
342 }
343
345 if (!synchronous) {
346 return -1;
347 }
348
349 ast_mutex_init(&synchronous->lock);
350 ast_cond_init(&synchronous->cond, NULL);
351
352 active = ast_dns_resolve_async(name, rr_type, rr_class, dns_synchronous_resolve_callback, synchronous);
353 if (active) {
354 /* Wait for resolution to complete */
355 ast_mutex_lock(&synchronous->lock);
356 while (!synchronous->completed) {
357 ast_cond_wait(&synchronous->cond, &synchronous->lock);
358 }
359 ast_mutex_unlock(&synchronous->lock);
360 ao2_ref(active, -1);
361 }
362
363 *result = synchronous->result;
364 ao2_ref(synchronous, -1);
365
366 return *result ? 0 : -1;
367}
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
static PGresult * result
Definition: cel_pgsql.c:84
static void dns_synchronous_resolve_callback(const struct ast_dns_query *query)
Callback used to implement synchronous resolution.
Definition: dns_core.c:301
struct ast_dns_query_active * ast_dns_resolve_async(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
Asynchronously resolve a DNS query.
Definition: dns_core.c:247
static void dns_synchronous_resolve_destroy(void *data)
Destructor for synchronous resolution structure.
Definition: dns_core.c:290
static const char name[]
Definition: format_mp3.c:68
#define LOG_WARNING
#define ast_cond_wait(cond, mutex)
Definition: lock.h:205
#define ast_cond_init(cond, attr)
Definition: lock.h:201
#define ast_mutex_init(pmutex)
Definition: lock.h:186
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
An active DNS query.
Definition: dns_internal.h:201
Structure used for signaling back for synchronous resolution completion.
Definition: dns_core.c:278
ast_cond_t cond
Condition used for signaling.
Definition: dns_core.c:282
struct ast_dns_result * result
The result from the query.
Definition: dns_core.c:286
ast_mutex_t lock
Lock used for signaling.
Definition: dns_core.c:280
unsigned int completed
Whether the query has completed.
Definition: dns_core.c:284

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_cond_init, ast_cond_wait, ast_dns_resolve_async(), ast_log, ast_mutex_init, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), dns_synchronous_resolve::completed, dns_synchronous_resolve::cond, dns_synchronous_resolve_callback(), dns_synchronous_resolve_destroy(), dns_synchronous_resolve::lock, LOG_WARNING, name, NULL, result, and dns_synchronous_resolve::result.

Referenced by AST_TEST_DEFINE(), invalid_record_test(), nominal_test(), and off_nominal_test().

◆ ast_dns_resolve_async()

struct ast_dns_query_active * ast_dns_resolve_async ( const char *  name,
int  rr_type,
int  rr_class,
ast_dns_resolve_callback  callback,
void *  data 
)

Asynchronously resolve a DNS query.

Parameters
nameThe name of what to resolve
rr_typeResource record type
rr_classResource record class
callbackThe callback to invoke upon completion
dataUser data to make available on the query
Return values
non-NULLsuccess - query has been sent for resolution
NULLfailure
Note
The result passed to the callback does not need to be freed
The user data MUST be an ao2 object
This function increments the reference count of the user data, it does NOT steal
The active query must be released upon completion or cancellation using ao2_ref

Definition at line 247 of file dns_core.c.

248{
249 struct ast_dns_query_active *active;
250
252 if (!active) {
253 return NULL;
254 }
255
256 active->query = dns_query_alloc(name, rr_type, rr_class, callback, data);
257 if (!active->query) {
258 ao2_ref(active, -1);
259 return NULL;
260 }
261
262 if (active->query->resolver->resolve(active->query)) {
263 ast_log(LOG_ERROR, "Resolver '%s' returned an error when resolving '%s' of class '%d' and type '%d'\n",
264 active->query->resolver->name, name, rr_class, rr_type);
265 ao2_ref(active, -1);
266 return NULL;
267 }
268
269 return active;
270}
struct ast_dns_query * dns_query_alloc(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
Allocate a DNS query (but do not start resolution)
Definition: dns_core.c:193
static void dns_query_active_destroy(void *data)
Destructor for an active DNS query.
Definition: dns_core.c:176
#define LOG_ERROR
struct ast_dns_query * query
The underlying DNS query.
Definition: dns_internal.h:203
struct ast_dns_resolver * resolver
The resolver in use for this query.
Definition: dns_internal.h:143
const char * name
The name of the resolver implementation.
Definition: dns_resolver.h:34
int(* resolve)(struct ast_dns_query *query)
Perform resolution of a DNS query.
Definition: dns_resolver.h:45

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_log, dns_query_active_destroy(), dns_query_alloc(), LOG_ERROR, name, ast_dns_resolver::name, NULL, ast_dns_query_active::query, ast_dns_resolver::resolve, and ast_dns_query::resolver.

Referenced by ast_dns_resolve(), ast_dns_resolve_recurring(), AST_TEST_DEFINE(), and dns_query_recurring_scheduled_callback().

◆ ast_dns_resolve_cancel()

int ast_dns_resolve_cancel ( struct ast_dns_query_active active)

Cancel an asynchronous DNS resolution.

Parameters
activeThe active DNS query returned from ast_dns_resolve_async
Return values
0success
-1failure
Note
If successfully cancelled the callback will not be invoked

Definition at line 272 of file dns_core.c.

273{
274 return active->query->resolver->cancel(active->query);
275}
int(* cancel)(struct ast_dns_query *query)
Cancel resolution of a DNS query.
Definition: dns_resolver.h:48

References ast_dns_resolver::cancel, ast_dns_query_active::query, and ast_dns_query::resolver.

Referenced by ast_dns_resolve_recurring_cancel(), and AST_TEST_DEFINE().

◆ ast_dns_resolve_ipv6_and_ipv4()

int ast_dns_resolve_ipv6_and_ipv4 ( struct ast_sockaddr address,
const char *  host,
const char *  port 
)

Synchronously resolves host to an AAAA or A record.

Since
16.6.0
Parameters
addressA pointer to an ast_sockaddr structure to receive the IPv6 or IPv4 address
hostThe hostname to resolve
port(optional) A port to parse into the final ast_sockaddr structure
Return values
0success - query was completed and result is available
-1failure
Note
This function makes parallel queries for both AAAA and A records for the host. The first returned AAAA record (if any) is used and if not found, the first A record is used.
Warning
This function is synchronous and will block until records are returned or an error occurs.

Definition at line 369 of file dns_core.c.

370{
372 int i;
373 int rc;
374
375 if (!queries) {
376 ast_log(LOG_ERROR, "Couldn't allocate DNS query structure\n");
377 return -1;
378 }
379 rc = ast_dns_query_set_add(queries, host, ns_t_aaaa, ns_c_in);
380 if (rc != 0) {
381 ast_log(LOG_ERROR, "Couldn't add 'AAAA' DNS query for '%s'\n", host);
382 return -1;
383 }
384 rc = ast_dns_query_set_add(queries, host, ns_t_a, ns_c_in);
385 if (rc != 0) {
386 ast_log(LOG_ERROR, "Couldn't add 'A' DNS query for '%s'\n", host);
387 return -1;
388 }
390 if (rc != 0) {
391 ast_log(LOG_ERROR, "Query set resolve failure for '%s'\n", host);
392 return -1;
393 }
394 for (i = 0; i < ast_dns_query_set_num_queries(queries); ++i) {
395 struct ast_dns_query *query = ast_dns_query_set_get(queries, i);
397 const struct ast_dns_record *record;
398 in_port_t in_port = 0;
399
400 if (!ast_strlen_zero(port)) {
401 in_port = htons(atoi(port));
402 }
403
404 for (record = ast_dns_result_get_records(result); record; record = ast_dns_record_get_next(record)) {
405 size_t data_size = ast_dns_record_get_data_size(record);
406 const unsigned char *data = (unsigned char *)ast_dns_record_get_data(record);
408
409 if (rr_type == ns_t_aaaa && data_size == 16) {
410 struct sockaddr_in6 sin6 = { 0, };
411
412 sin6.sin6_port = in_port;
413 memcpy(&sin6.sin6_addr, data, data_size);
414 sin6.sin6_family = AF_INET6;
415 memcpy(&address->ss, &sin6, sizeof(sin6));
416 address->len = sizeof(sin6);
417
418 return 0;
419 } else if (rr_type == ns_t_a && data_size == 4) {
420 struct sockaddr_in sin4 = { 0, };
421
422 sin4.sin_port = in_port;
423 memcpy(&sin4.sin_addr, data, data_size);
424 sin4.sin_family = AF_INET;
425 memcpy(&address->ss, &sin4, sizeof(sin4));
426 address->len = sizeof(sin4);
427
428 return 0;
429 } else {
430 ast_debug(3, "Unrecognized rr_type '%u' or data_size '%zu' from DNS query for host '%s'\n",
431 rr_type, data_size, host);
432 continue;
433 }
434 }
435 }
436
437 return -1;
438}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
const struct ast_dns_record * ast_dns_record_get_next(const struct ast_dns_record *record)
Get the next DNS record.
Definition: dns_core.c:170
const char * ast_dns_record_get_data(const struct ast_dns_record *record)
Retrieve the raw DNS record.
Definition: dns_core.c:160
const struct ast_dns_record * ast_dns_result_get_records(const struct ast_dns_result *result)
Get the first record of a DNS Result.
Definition: dns_core.c:102
struct ast_dns_result * ast_dns_query_get_result(const struct ast_dns_query *query)
Get the result information for a DNS query.
Definition: dns_core.c:77
int ast_dns_record_get_rr_type(const struct ast_dns_record *record)
Get the resource record type of a DNS record.
Definition: dns_core.c:145
size_t ast_dns_record_get_data_size(const struct ast_dns_record *record)
Retrieve the size of the raw DNS record.
Definition: dns_core.c:165
struct ast_dns_query * ast_dns_query_set_get(const struct ast_dns_query_set *query_set, unsigned int index)
Retrieve a query from a query set.
struct ast_dns_query_set * ast_dns_query_set_create(void)
Create a query set to hold queries.
Definition: dns_query_set.c:60
size_t ast_dns_query_set_num_queries(const struct ast_dns_query_set *query_set)
Retrieve the number of queries in a query set.
int ast_dns_query_set_add(struct ast_dns_query_set *query_set, const char *name, int rr_type, int rr_class)
Add a query to a query set.
int ast_query_set_resolve(struct ast_dns_query_set *query_set)
Synchronously resolve queries in a query set.
char * address
Definition: f2c.h:59
#define ast_debug(level,...)
Log a DEBUG message.
A set of DNS queries.
Definition: dns_internal.h:185
A DNS query.
Definition: dns_internal.h:137
For AST_LIST.
Definition: dns_internal.h:39
char data[0]
The raw DNS record.
Definition: dns_internal.h:60
The result of a DNS query.
Definition: dns_internal.h:117
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ao2_cleanup, ast_debug, ast_dns_query_get_result(), ast_dns_query_set_add(), ast_dns_query_set_create(), ast_dns_query_set_get(), ast_dns_query_set_num_queries(), ast_dns_record_get_data(), ast_dns_record_get_data_size(), ast_dns_record_get_next(), ast_dns_record_get_rr_type(), ast_dns_result_get_records(), ast_log, ast_query_set_resolve(), ast_strlen_zero(), ast_dns_record::data, LOG_ERROR, RAII_VAR, result, and ast_dns_record::rr_type.

Referenced by unicast_rtp_request().

◆ ast_dns_result_free()

void ast_dns_result_free ( struct ast_dns_result result)

Free the DNS result information.

Parameters
resultThe DNS result

Definition at line 130 of file dns_core.c.

131{
132 struct ast_dns_record *record;
133
134 if (!result) {
135 return;
136 }
137
138 while ((record = AST_LIST_REMOVE_HEAD(&result->records, list))) {
139 ast_free(record);
140 }
141
143}
#define ast_free(a)
Definition: astmm.h:180
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
struct ast_dns_record::@215 list
Linked list information.

References ast_free, AST_LIST_REMOVE_HEAD, ast_dns_record::list, and result.

Referenced by ast_dns_resolver_set_result(), AST_TEST_DEFINE(), dns_query_destroy(), invalid_record_test(), nominal_test(), and off_nominal_test().

◆ ast_dns_result_get_answer()

const char * ast_dns_result_get_answer ( const struct ast_dns_result result)

Get the raw DNS answer from a DNS result.

Parameters
resultThe DNS result
Returns
The DNS result

Definition at line 107 of file dns_core.c.

108{
109 return result->answer;
110}

References result.

Referenced by test_results().

◆ ast_dns_result_get_bogus()

unsigned int ast_dns_result_get_bogus ( const struct ast_dns_result result)

Get whether the result is bogus or not.

Parameters
resultThe DNS result
Returns
whether the result is bogus or not

Definition at line 87 of file dns_core.c.

88{
89 return result->bogus;
90}

References result.

Referenced by test_results().

◆ ast_dns_result_get_canonical()

const char * ast_dns_result_get_canonical ( const struct ast_dns_result result)

Get the canonical name of the result.

Parameters
resultThe DNS result
Returns
the canonical name

Definition at line 97 of file dns_core.c.

98{
99 return result->canonical;
100}

References result.

Referenced by test_results().

◆ ast_dns_result_get_lowest_ttl()

int ast_dns_result_get_lowest_ttl ( const struct ast_dns_result result)

Retrieve the lowest TTL from a result.

Parameters
resultThe DNS result
Returns
the lowest TTL
Note
If no records exist this function will return a TTL of 0

Definition at line 112 of file dns_core.c.

113{
114 int ttl = 0;
115 const struct ast_dns_record *record;
116
117 if (ast_dns_result_get_rcode(result) == NXDOMAIN) {
118 return 0;
119 }
120
121 for (record = ast_dns_result_get_records(result); record; record = ast_dns_record_get_next(record)) {
122 if (!ttl || (ast_dns_record_get_ttl(record) && (ast_dns_record_get_ttl(record) < ttl))) {
123 ttl = ast_dns_record_get_ttl(record);
124 }
125 }
126
127 return ttl;
128}
int ast_dns_record_get_ttl(const struct ast_dns_record *record)
Get the TTL of a DNS record.
Definition: dns_core.c:155
unsigned int ast_dns_result_get_rcode(const struct ast_dns_result *result)
Get the error rcode of a DN result.
Definition: dns_core.c:92

References ast_dns_record_get_next(), ast_dns_record_get_ttl(), ast_dns_result_get_rcode(), ast_dns_result_get_records(), result, and ast_dns_record::ttl.

Referenced by dns_query_recurring_resolution_callback().

◆ ast_dns_result_get_rcode()

unsigned int ast_dns_result_get_rcode ( const struct ast_dns_result result)

Get the error rcode of a DN result.

Parameters
resultThe DNS result
Returns
the DNS rcode

Definition at line 92 of file dns_core.c.

93{
94 return result->rcode;
95}

References result.

Referenced by ast_dns_result_get_lowest_ttl(), and test_results().

◆ ast_dns_result_get_records()

const struct ast_dns_record * ast_dns_result_get_records ( const struct ast_dns_result result)

Get the first record of a DNS Result.

Parameters
resultThe DNS result
Returns
first DNS record

Definition at line 102 of file dns_core.c.

103{
104 return AST_LIST_FIRST(&result->records);
105}
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421

References AST_LIST_FIRST, and result.

Referenced by ast_dns_resolve_ipv6_and_ipv4(), ast_dns_result_get_lowest_ttl(), AST_TEST_DEFINE(), invalid_record_test(), nominal_test(), and off_nominal_test().

◆ ast_dns_result_get_secure()

unsigned int ast_dns_result_get_secure ( const struct ast_dns_result result)

Get whether the result is secure or not.

Parameters
resultThe DNS result
Returns
whether the result is secure or not

Definition at line 82 of file dns_core.c.

83{
84 return result->secure;
85}

References result.

Referenced by test_results().