clang-format

pull/830/head
Brad House 4 months ago
parent 341b34d140
commit 5c555b7c0b
  1. 2
      include/ares.h
  2. 55
      include/ares_dns_record.h
  3. 32
      src/lib/ares__addrinfo2hostent.c
  4. 7
      src/lib/ares__close_sockets.c
  5. 1
      src/lib/ares__socket.c
  6. 1
      src/lib/ares__sortaddrinfo.c
  7. 2
      src/lib/ares_cancel.c
  8. 5
      src/lib/ares_dns_multistring.c
  9. 5
      src/lib/ares_dns_multistring.h
  10. 2
      src/lib/ares_dns_private.h
  11. 8
      src/lib/ares_dns_record.c
  12. 2
      src/lib/ares_metrics.c
  13. 6
      src/lib/ares_private.h
  14. 30
      src/lib/ares_process.c
  15. 11
      src/lib/ares_qcache.c
  16. 21
      src/lib/ares_send.c
  17. 8
      src/lib/ares_setup.h
  18. 6
      src/lib/ares_sysconfig_mac.c
  19. 13
      src/lib/ares_timeout.c
  20. 18
      src/lib/event/ares_event_configchg.c
  21. 8
      src/lib/event/ares_event_kqueue.c
  22. 2
      src/lib/event/ares_event_thread.c
  23. 3
      src/lib/inet_net_pton.c
  24. 6
      src/lib/inet_ntop.c
  25. 3
      src/lib/legacy/ares_expand_string.c
  26. 2
      src/lib/legacy/ares_parse_txt_reply.c
  27. 21
      src/lib/str/ares_str.h
  28. 2
      src/lib/util/ares__timeval.c
  29. 59
      src/tools/adig.c
  30. 3
      src/tools/ares_getopt.c
  31. 15
      src/tools/ares_getopt.h
  32. 8
      test/ares-test.h
  33. 3
      test/ares_queryloop.c
  34. 15
      test/dns-proto.h

@ -95,7 +95,7 @@
#endif
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
#ifdef __cplusplus
extern "C" {

@ -157,23 +157,23 @@ typedef enum {
/*! Data types used */
typedef enum {
ARES_DATATYPE_INADDR = 1, /*!< struct in_addr * type */
ARES_DATATYPE_INADDR6 = 2, /*!< struct ares_in6_addr * type */
ARES_DATATYPE_U8 = 3, /*!< 8bit unsigned integer */
ARES_DATATYPE_U16 = 4, /*!< 16bit unsigned integer */
ARES_DATATYPE_U32 = 5, /*!< 32bit unsigned integer */
ARES_DATATYPE_NAME = 6, /*!< Null-terminated string of a domain name */
ARES_DATATYPE_STR = 7, /*!< Null-terminated string */
ARES_DATATYPE_BIN = 8, /*!< Binary data */
ARES_DATATYPE_BINP = 9, /*!< Officially defined as binary data, but likely
* printable. Guaranteed to have a NULL
* terminator for convenience (not included in
* length) */
ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN
* data. */
ARES_DATATYPE_ABINP = 11 /*!< Array of binary data, likely printable.
* Guaranteed to have a NULL terminator for
* convenience (not included in length) */
ARES_DATATYPE_INADDR = 1, /*!< struct in_addr * type */
ARES_DATATYPE_INADDR6 = 2, /*!< struct ares_in6_addr * type */
ARES_DATATYPE_U8 = 3, /*!< 8bit unsigned integer */
ARES_DATATYPE_U16 = 4, /*!< 16bit unsigned integer */
ARES_DATATYPE_U32 = 5, /*!< 32bit unsigned integer */
ARES_DATATYPE_NAME = 6, /*!< Null-terminated string of a domain name */
ARES_DATATYPE_STR = 7, /*!< Null-terminated string */
ARES_DATATYPE_BIN = 8, /*!< Binary data */
ARES_DATATYPE_BINP = 9, /*!< Officially defined as binary data, but likely
* printable. Guaranteed to have a NULL
* terminator for convenience (not included in
* length) */
ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN
* data. */
ARES_DATATYPE_ABINP = 11 /*!< Array of binary data, likely printable.
* Guaranteed to have a NULL terminator for
* convenience (not included in length) */
} ares_dns_datatype_t;
/*! Keys used for all RR Types. We take the record type and multiply by 100
@ -609,8 +609,8 @@ CARES_EXTERN unsigned short
* \param[in] id DNS query id
* \return ARES_TRUE on success, ARES_FALSE on usage error
*/
CARES_EXTERN ares_bool_t
ares_dns_record_set_id(ares_dns_record_t *dnsrec, unsigned short id);
CARES_EXTERN ares_bool_t ares_dns_record_set_id(ares_dns_record_t *dnsrec,
unsigned short id);
/*! Get the DNS Record Flags
*
@ -885,10 +885,10 @@ CARES_EXTERN ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr,
* \param[in] len Length of binary data
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
CARES_EXTERN ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
const unsigned char *val,
size_t len);
size_t len);
/*! Delete binary array value (ABINP) data for specified resource record and
* key by specified index. Can only be used on keys with datatype
@ -899,9 +899,9 @@ CARES_EXTERN ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr,
* \param[in] idx Index to delete
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr,
CARES_EXTERN ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
size_t idx);
size_t idx);
/*! Set the option for the RR
*
@ -1000,7 +1000,7 @@ CARES_EXTERN const unsigned char *
* \return count of values
*/
CARES_EXTERN size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
ares_dns_rr_key_t key);
/*! Retrieve a pointer to the binary array data from the specified index. Can
* only be used on keys with datatype ARES_DATATYPE_ABINP. If ABINP, the data
@ -1014,8 +1014,9 @@ CARES_EXTERN size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr,
* \param[out] len Length of binary data returned
* \return pointer binary data or NULL on error
*/
CARES_EXTERN const unsigned char *ares_dns_rr_get_abin(
const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, size_t idx, size_t *len);
CARES_EXTERN const unsigned char *
ares_dns_rr_get_abin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
size_t idx, size_t *len);
/*! Retrieve the number of options stored for the RR.

@ -161,16 +161,16 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
}
(*host)->h_addr_list[i] = addrs + (i * (size_t)(*host)->h_length);
if (family == AF_INET6) {
memcpy(
(*host)->h_addr_list[i],
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
(size_t)(*host)->h_length);
memcpy((*host)->h_addr_list[i],
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)
->sin6_addr),
(size_t)(*host)->h_length);
}
if (family == AF_INET) {
memcpy(
(*host)->h_addr_list[i],
&(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr),
(size_t)(*host)->h_length);
memcpy((*host)->h_addr_list[i],
&(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)
->sin_addr),
(size_t)(*host)->h_length);
}
++i;
}
@ -252,20 +252,20 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
addr6ttls[*naddrttls].ttl = next->ai_ttl;
}
memcpy(
&addr6ttls[*naddrttls].ip6addr,
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
sizeof(struct ares_in6_addr));
memcpy(&addr6ttls[*naddrttls].ip6addr,
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)
->sin6_addr),
sizeof(struct ares_in6_addr));
} else {
if (next->ai_ttl > cname_ttl) {
addrttls[*naddrttls].ttl = cname_ttl;
} else {
addrttls[*naddrttls].ttl = next->ai_ttl;
}
memcpy(
&addrttls[*naddrttls].ipaddr,
&(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr),
sizeof(struct in_addr));
memcpy(&addrttls[*naddrttls].ipaddr,
&(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)
->sin_addr),
sizeof(struct in_addr));
}
(*naddrttls)++;
}

@ -29,7 +29,7 @@
#include <assert.h>
static void ares__requeue_queries(struct server_connection *conn,
ares_status_t requeue_status)
ares_status_t requeue_status)
{
struct query *query;
ares_timeval_t now;
@ -42,7 +42,7 @@ static void ares__requeue_queries(struct server_connection *conn,
}
void ares__close_connection(struct server_connection *conn,
ares_status_t requeue_status)
ares_status_t requeue_status)
{
struct server_state *server = conn->server;
ares_channel_t *channel = server->channel;
@ -91,7 +91,6 @@ void ares__check_cleanup_conns(const ares_channel_t *channel)
/* Iterate across each server */
for (snode = ares__slist_node_first(channel->servers); snode != NULL;
snode = ares__slist_node_next(snode)) {
struct server_state *server = ares__slist_node_val(snode);
ares__llist_node_t *cnode;
@ -101,7 +100,7 @@ void ares__check_cleanup_conns(const ares_channel_t *channel)
ares__llist_node_t *next = ares__llist_node_next(cnode);
struct server_connection *conn = ares__llist_node_val(cnode);
ares_bool_t do_cleanup = ARES_FALSE;
cnode = next;
cnode = next;
/* Has connections, not eligible */
if (ares__llist_len(conn->queries_to_conn)) {

@ -56,7 +56,6 @@
#include <fcntl.h>
#include <limits.h>
ares_ssize_t ares__socket_recvfrom(ares_channel_t *channel, ares_socket_t s,
void *data, size_t data_len, int flags,
struct sockaddr *from,

@ -51,7 +51,6 @@
#include <assert.h>
#include <limits.h>
struct addrinfo_sort_elem {
struct ares_addrinfo_node *ai;
ares_bool_t has_src_addr;

@ -59,7 +59,7 @@ void ares_cancel(ares_channel_t *channel)
node = ares__llist_node_first(list_copy);
while (node != NULL) {
struct query *query;
struct query *query;
/* Cache next since this node is being deleted */
next = ares__llist_node_next(node);

@ -153,8 +153,9 @@ size_t ares__dns_multistring_cnt(const ares__dns_multistring_t *strs)
return strs->cnt;
}
const unsigned char *ares__dns_multistring_get(
const ares__dns_multistring_t *strs, size_t idx, size_t *len)
const unsigned char *
ares__dns_multistring_get(const ares__dns_multistring_t *strs, size_t idx,
size_t *len)
{
if (strs == NULL || idx >= strs->cnt || len == NULL) {
return NULL;

@ -40,8 +40,9 @@ ares_status_t ares__dns_multistring_del(ares__dns_multistring_t *strs,
ares_status_t ares__dns_multistring_add_own(ares__dns_multistring_t *strs,
unsigned char *str, size_t len);
size_t ares__dns_multistring_cnt(const ares__dns_multistring_t *strs);
const unsigned char *ares__dns_multistring_get(
const ares__dns_multistring_t *strs, size_t idx, size_t *len);
const unsigned char *
ares__dns_multistring_get(const ares__dns_multistring_t *strs, size_t idx,
size_t *len);
const unsigned char *
ares__dns_multistring_get_combined(ares__dns_multistring_t *strs,
size_t *len);

@ -26,7 +26,7 @@
#ifndef __ARES_DNS_PRIVATE_H
#define __ARES_DNS_PRIVATE_H
ares_status_t ares_dns_record_duplicate_ex(ares_dns_record_t **dest,
ares_status_t ares_dns_record_duplicate_ex(ares_dns_record_t **dest,
const ares_dns_record_t *src);
ares_bool_t ares_dns_rec_type_allow_name_compression(ares_dns_rec_type_t type);
ares_bool_t ares_dns_opcode_isvalid(ares_dns_opcode_t opcode);

@ -1623,12 +1623,12 @@ done:
return status;
}
ares_status_t ares_dns_record_duplicate_ex(ares_dns_record_t **dest,
ares_status_t ares_dns_record_duplicate_ex(ares_dns_record_t **dest,
const ares_dns_record_t *src)
{
unsigned char *data = NULL;
size_t data_len = 0;
ares_status_t status;
unsigned char *data = NULL;
size_t data_len = 0;
ares_status_t status;
if (dest == NULL || src == NULL) {
return ARES_EFORMERR;

@ -252,7 +252,7 @@ size_t ares_metrics_server_timeout(const struct server_state *server,
}
/* don't go above upper bounds */
max_timeout_ms = channel->maxtimeout?channel->maxtimeout:MAX_TIMEOUT_MS;
max_timeout_ms = channel->maxtimeout ? channel->maxtimeout : MAX_TIMEOUT_MS;
if (timeout_ms > max_timeout_ms) {
timeout_ms = max_timeout_ms;
}

@ -440,7 +440,7 @@ void ares__dnsrec_convert_cb(void *arg, ares_status_t status, size_t timeouts,
const ares_dns_record_t *dnsrec);
void ares__close_connection(struct server_connection *conn,
ares_status_t requeue_status);
ares_status_t requeue_status);
void ares__close_sockets(struct server_state *server);
void ares__check_cleanup_conns(const ares_channel_t *channel);
void ares__free_query(struct query *query);
@ -616,8 +616,8 @@ ares_status_t ares_query_nolock(ares_channel_t *channel, const char *name,
* if a channel lock is already held */
ares_status_t ares_send_nolock(ares_channel_t *channel,
const ares_dns_record_t *dnsrec,
ares_callback_dnsrec callback,
void *arg, unsigned short *qid);
ares_callback_dnsrec callback, void *arg,
unsigned short *qid);
/* Same as ares_gethostbyaddr() except does not take a channel lock. Use this
* if a channel lock is already held */

@ -61,7 +61,7 @@ static void handle_conn_error(struct server_connection *conn,
ares_bool_t critical_failure,
ares_status_t failure_status);
static ares_bool_t same_questions(const struct query *query,
static ares_bool_t same_questions(const struct query *query,
const ares_dns_record_t *arec);
static ares_bool_t same_address(const struct sockaddr *sa,
const struct ares_addr *aa);
@ -69,7 +69,6 @@ static void end_query(ares_channel_t *channel, struct server_state *server,
struct query *query, ares_status_t status,
const ares_dns_record_t *dnsrec);
static void ares__query_disassociate_from_conn(struct query *query)
{
/* If its not part of a connection, it can't be tracked for timeouts either */
@ -348,7 +347,8 @@ static void read_tcp_data(ares_channel_t *channel,
ptr = ares__buf_append_start(server->tcp_parser, &ptr_len);
if (ptr == NULL) {
handle_conn_error(conn, ARES_FALSE /* not critical to connection */, ARES_SUCCESS);
handle_conn_error(conn, ARES_FALSE /* not critical to connection */,
ARES_SUCCESS);
return; /* bail out on malloc failure. TODO: make this
function return error codes */
}
@ -629,9 +629,9 @@ static void process_timeouts(ares_channel_t *channel, const ares_timeval_t *now)
static ares_status_t rewrite_without_edns(struct query *query)
{
ares_status_t status = ARES_SUCCESS;
size_t i;
ares_bool_t found_opt_rr = ARES_FALSE;
ares_status_t status = ARES_SUCCESS;
size_t i;
ares_bool_t found_opt_rr = ARES_FALSE;
/* Find and remove the OPT RR record */
for (i = 0; i < ares_dns_record_rr_cnt(query->query, ARES_SECTION_ADDITIONAL);
@ -926,7 +926,7 @@ static struct server_state *ares__failover_server(ares_channel_t *channel)
static ares_status_t ares__append_tcpbuf(struct server_state *server,
const struct query *query)
{
ares_status_t status;
ares_status_t status;
unsigned char *qbuf = NULL;
size_t qbuf_len = 0;
@ -947,12 +947,11 @@ done:
return status;
}
static ares_status_t ares__write_udpbuf(ares_channel_t *channel,
ares_socket_t fd,
const struct query *query)
static ares_status_t ares__write_udpbuf(ares_channel_t *channel,
ares_socket_t fd,
const struct query *query)
{
ares_status_t status;
ares_status_t status;
unsigned char *qbuf = NULL;
size_t qbuf_len = 0;
@ -1222,7 +1221,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now)
return ARES_SUCCESS;
}
static ares_bool_t same_questions(const struct query *query,
static ares_bool_t same_questions(const struct query *query,
const ares_dns_record_t *arec)
{
size_t i;
@ -1299,7 +1298,8 @@ static ares_bool_t same_address(const struct sockaddr *sa,
break;
case AF_INET6:
addr1 = &aa->addr.addr6;
addr2 = &(CARES_INADDR_CAST(const struct sockaddr_in6 *, sa))->sin6_addr;
addr2 =
&(CARES_INADDR_CAST(const struct sockaddr_in6 *, sa))->sin6_addr;
if (memcmp(addr1, addr2, sizeof(aa->addr.addr6)) == 0) {
return ARES_TRUE; /* match */
}
@ -1317,7 +1317,7 @@ static void ares_detach_query(struct query *query)
ares__query_disassociate_from_conn(query);
ares__htable_szvp_remove(query->channel->queries_by_qid, query->qid);
ares__llist_node_destroy(query->node_all_queries);
query->node_all_queries = NULL;
query->node_all_queries = NULL;
}
static void end_query(ares_channel_t *channel, struct server_state *server,

@ -300,10 +300,10 @@ static unsigned int ares__qcache_soa_minimum(ares_dns_record_t *dnsrec)
}
/* On success, takes ownership of dnsrec */
static ares_status_t ares__qcache_insert(ares__qcache_t *qcache,
ares_dns_record_t *qresp,
const ares_dns_record_t *qreq,
const ares_timeval_t *now)
static ares_status_t ares__qcache_insert(ares__qcache_t *qcache,
ares_dns_record_t *qresp,
const ares_dns_record_t *qreq,
const ares_timeval_t *now)
{
ares__qcache_entry_t *entry;
unsigned int ttl;
@ -425,6 +425,5 @@ ares_status_t ares_qcache_insert(ares_channel_t *channel,
const struct query *query,
ares_dns_record_t *dnsrec)
{
return ares__qcache_insert(channel->qcache, dnsrec, query->query,
now);
return ares__qcache_insert(channel->qcache, dnsrec, query->query, now);
}

@ -43,13 +43,12 @@ static unsigned short generate_unique_qid(ares_channel_t *channel)
return id;
}
/* https://datatracker.ietf.org/doc/html/draft-vixie-dnsext-dns0x20-00 */
static ares_status_t ares_apply_dns0x20(ares_channel_t *channel,
static ares_status_t ares_apply_dns0x20(ares_channel_t *channel,
ares_dns_record_t *dnsrec)
{
ares_status_t status = ARES_SUCCESS;
const char *name = NULL;
ares_status_t status = ARES_SUCCESS;
const char *name = NULL;
char dns0x20name[256];
unsigned char randdata[256 / 8];
size_t len;
@ -72,12 +71,12 @@ static ares_status_t ares_apply_dns0x20(ares_channel_t *channel,
/* Fetch the minimum amount of random data we'd need for the string, which
* is 1 bit per byte */
total_bits = ((len + 7) / 8) * 8;
total_bits = ((len + 7) / 8) * 8;
remaining_bits = total_bits;
ares__rand_bytes(channel->rand_state, randdata, total_bits / 8);
/* Randomly apply 0x20 to name */
for (i=0; i<len; i++) {
for (i = 0; i < len; i++) {
size_t bit;
/* Only apply 0x20 to alpha characters */
@ -89,7 +88,7 @@ static ares_status_t ares_apply_dns0x20(ares_channel_t *channel,
/* coin flip */
bit = total_bits - remaining_bits;
if (randdata[bit / 8] & (1 << (bit % 8))) {
dns0x20name[i] = name[i] | 0x20; /* Set 0x20 */
dns0x20name[i] = name[i] | 0x20; /* Set 0x20 */
} else {
dns0x20name[i] = (char)(((unsigned char)name[i]) & 0xDF); /* Unset 0x20 */
}
@ -102,11 +101,10 @@ done:
return status;
}
ares_status_t ares_send_nolock(ares_channel_t *channel,
const ares_dns_record_t *dnsrec,
ares_callback_dnsrec callback,
void *arg, unsigned short *qid)
ares_callback_dnsrec callback, void *arg,
unsigned short *qid)
{
struct query *query;
ares_timeval_t now;
@ -142,7 +140,8 @@ ares_status_t ares_send_nolock(ares_channel_t *channel,
query->qid = id;
query->timeout.sec = 0;
query->timeout.usec = 0;
query->using_tcp = (channel->flags & ARES_FLAG_USEVC)?ARES_TRUE:ARES_FALSE;
query->using_tcp =
(channel->flags & ARES_FLAG_USEVC) ? ARES_TRUE : ARES_FALSE;
/* Duplicate Query */
status = ares_dns_record_duplicate_ex(&query->query, dnsrec);

@ -300,9 +300,9 @@ Error Missing_definition_of_macro_sread
write((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), (SEND_TYPE_ARG3)(z))
#elif defined(HAVE_SEND)
# if !defined(SEND_TYPE_ARG1) || \
!defined(SEND_TYPE_ARG2) || !defined(SEND_TYPE_ARG3) || \
!defined(SEND_TYPE_ARG4) || !defined(SEND_TYPE_RETV)
# if !defined(SEND_TYPE_ARG1) || !defined(SEND_TYPE_ARG2) || \
!defined(SEND_TYPE_ARG3) || !defined(SEND_TYPE_ARG4) || \
!defined(SEND_TYPE_RETV)
/* */
Error Missing_definition_of_return_and_arguments_types_of_send
/* */
@ -343,7 +343,7 @@ Error Missing_definition_of_macro_sread
#else
# define DEBUGF(x) \
do { \
} while(0)
} while (0)
#endif
/*

@ -115,11 +115,11 @@ static ares_status_t dnsinfo_init(dnsinfo_t **dnsinfo_out)
continue;
}
dnsinfo->dns_configuration_copy = (dns_config_t *(*)(void))
dnsinfo->dns_configuration_copy = (dns_config_t * (*)(void))
dlsym(dnsinfo->handle, "dns_configuration_copy");
dnsinfo->dns_configuration_free = (void (*)(dns_config_t *))
dlsym(dnsinfo->handle, "dns_configuration_free");
dnsinfo->dns_configuration_free = (void (*)(dns_config_t *))dlsym(
dnsinfo->handle, "dns_configuration_free");
if (dnsinfo->dns_configuration_copy != NULL &&
dnsinfo->dns_configuration_free != NULL) {

@ -65,7 +65,8 @@ void ares__timeval_diff(ares_timeval_t *tvdiff, const ares_timeval_t *tvstart,
}
}
static void ares_timeval_to_struct_timeval(struct timeval *tv, const ares_timeval_t *atv)
static void ares_timeval_to_struct_timeval(struct timeval *tv,
const ares_timeval_t *atv)
{
#ifdef USE_WINSOCK
tv->tv_sec = (long)atv->sec;
@ -76,15 +77,16 @@ static void ares_timeval_to_struct_timeval(struct timeval *tv, const ares_timeva
tv->tv_usec = (int)atv->usec;
}
static void struct_timeval_to_ares_timeval(ares_timeval_t *atv, const struct timeval *tv)
static void struct_timeval_to_ares_timeval(ares_timeval_t *atv,
const struct timeval *tv)
{
atv->sec = (ares_int64_t)tv->tv_sec;
atv->usec = (unsigned int)tv->tv_usec;
}
static struct timeval *ares_timeout_int(const ares_channel_t *channel,
struct timeval *maxtv,
struct timeval *tvbuf)
struct timeval *maxtv,
struct timeval *tvbuf)
{
const struct query *query;
ares__slist_node_t *node;
@ -135,8 +137,9 @@ struct timeval *ares_timeout(const ares_channel_t *channel,
{
struct timeval *rv;
if (channel == NULL || tvbuf == NULL)
if (channel == NULL || tvbuf == NULL) {
return NULL;
}
ares__channel_lock(channel);

@ -238,8 +238,7 @@ void ares_event_configchg_destroy(ares_event_configchg_t *configchg)
# ifndef __WATCOMC__
static void NETIOAPI_API_
ares_event_configchg_ip_cb(PVOID CallerContext,
PMIB_IPINTERFACE_ROW Row,
ares_event_configchg_ip_cb(PVOID CallerContext, PMIB_IPINTERFACE_ROW Row,
MIB_NOTIFICATION_TYPE NotificationType)
{
ares_event_configchg_t *configchg = CallerContext;
@ -303,9 +302,8 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
* We've also tried listening on NotifyUnicastIpAddressChange(), but
* that didn't get triggered either.
*/
if (NotifyIpInterfaceChange(
AF_UNSPEC, ares_event_configchg_ip_cb,
c, FALSE, &c->ifchg_hnd) != NO_ERROR) {
if (NotifyIpInterfaceChange(AF_UNSPEC, ares_event_configchg_ip_cb, c, FALSE,
&c->ifchg_hnd) != NO_ERROR) {
status = ARES_ESERVFAIL;
goto done;
}
@ -316,8 +314,8 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
* for changes via RegNotifyChangeKeyValue() */
if (RegOpenKeyExW(
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces", 0,
KEY_NOTIFY, &c->regip4) != ERROR_SUCCESS) {
L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces",
0, KEY_NOTIFY, &c->regip4) != ERROR_SUCCESS) {
status = ARES_ESERVFAIL;
goto done;
}
@ -472,8 +470,8 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
continue;
}
pdns_configuration_notify_key = (const char *(*)(void))
dlsym(handle, "dns_configuration_notify_key");
pdns_configuration_notify_key =
(const char *(*)(void))dlsym(handle, "dns_configuration_notify_key");
if (pdns_configuration_notify_key != NULL) {
break;
}
@ -551,7 +549,7 @@ static ares_status_t config_change_check(ares__htable_strvp_t *filestat,
{
size_t i;
const char *configfiles[5];
ares_bool_t changed = ARES_FALSE;
ares_bool_t changed = ARES_FALSE;
configfiles[0] = resolvconf_path;
configfiles[1] = "/etc/nsswitch.conf";

@ -123,11 +123,9 @@ static void ares_evsys_kqueue_enqueue(ares_evsys_kqueue_t *kq, int fd,
if (kq->nchanges > kq->nchanges_alloc) {
kq->nchanges_alloc <<= 1;
kq->changelist = ares_realloc_zero(
kq->changelist,
(kq->nchanges_alloc >> 1) * sizeof(*kq->changelist),
kq->nchanges_alloc * sizeof(*kq->changelist)
);
kq->changelist = ares_realloc_zero(
kq->changelist, (kq->nchanges_alloc >> 1) * sizeof(*kq->changelist),
kq->nchanges_alloc * sizeof(*kq->changelist));
}
EV_SET(&kq->changelist[idx], fd, filter, flags, 0, 0, 0);

@ -370,7 +370,7 @@ void ares_event_thread_destroy(ares_channel_t *channel)
ares_event_thread_destroy_int(e);
channel->sock_state_cb_data = NULL;
channel->sock_state_cb = NULL;
channel->sock_state_cb = NULL;
}
static const ares_event_sys_t *ares_event_fetch_sys(ares_evsys_t evsys)

@ -133,7 +133,8 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst,
}
bits = -1;
if (ch == '/' && ares__isascii(src[0]) && ares__isdigit(src[0]) && dst > odst) {
if (ch == '/' && ares__isascii(src[0]) && ares__isdigit(src[0]) &&
dst > odst) {
/* CIDR width specifier. Nothing can follow it. */
ch = *src++; /* Skip over the /. */
bits = 0;

@ -138,7 +138,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
if (words[i] == 0) {
if (cur.base == -1) {
cur.base = (ares_ssize_t)i;
cur.len = 1;
cur.len = 1;
} else {
cur.len++;
}
@ -166,7 +166,8 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
tp = tmp;
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
/* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= (size_t)best.base && i < ((size_t)best.base + best.len)) {
if (best.base != -1 && i >= (size_t)best.base &&
i < ((size_t)best.base + best.len)) {
if (i == (size_t)best.base) {
*tp++ = ':';
}
@ -205,4 +206,3 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
ares_strcpy(dst, tmp, size);
return dst;
}

@ -74,8 +74,7 @@ ares_status_t ares_expand_string_ex(const unsigned char *encoded,
}
start_len = ares__buf_len(buf);
status =
ares__buf_parse_dns_binstr(buf, ares__buf_len(buf), s, &len);
status = ares__buf_parse_dns_binstr(buf, ares__buf_len(buf), s, &len);
/* hrm, no way to pass back 'len' with the prototype */
if (status != ARES_SUCCESS) {
goto done;

@ -71,7 +71,7 @@ static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen,
cnt = ares_dns_rr_get_abin_cnt(rr, ARES_RR_TXT_DATA);
for (j=0; j<cnt; j++) {
for (j = 0; j < cnt; j++) {
const unsigned char *ptr;
size_t ptr_len;

@ -74,17 +74,16 @@ ares_bool_t ares__str_isprint(const char *str, size_t len);
/* We only care about ASCII rules */
#define ares__isascii(x) (((unsigned char)x) <= 127)
#define ares__isdigit(x) (((unsigned char)x) >= '0' && \
((unsigned char)x) <= '9')
#define ares__isxdigit(x) (ares__isdigit(x) || \
(((unsigned char)x) >= 'a' && \
((unsigned char)x) <= 'f') || \
(((unsigned char)x) >= 'A' && \
((unsigned char)x) <= 'F'))
#define ares__isupper(x) (((unsigned char)x) >= 'A' && \
((unsigned char)x) <= 'Z')
#define ares__islower(x) (((unsigned char)x) >= 'a' && \
((unsigned char)x) <= 'z')
#define ares__isdigit(x) \
(((unsigned char)x) >= '0' && ((unsigned char)x) <= '9')
#define ares__isxdigit(x) \
(ares__isdigit(x) || \
(((unsigned char)x) >= 'a' && ((unsigned char)x) <= 'f') || \
(((unsigned char)x) >= 'A' && ((unsigned char)x) <= 'F'))
#define ares__isupper(x) \
(((unsigned char)x) >= 'A' && ((unsigned char)x) <= 'Z')
#define ares__islower(x) \
(((unsigned char)x) >= 'a' && ((unsigned char)x) <= 'z')
#define ares__isalpha(x) (ares__islower(x) || ares__isupper(x))
#endif /* __ARES_STR_H */

@ -47,7 +47,7 @@ void ares__tvnow(ares_timeval_t *now)
/* We want to prevent overflows so we get the remainder, then multiply to
* microseconds before dividing */
now->usec = (unsigned int)(((current.QuadPart % freq.QuadPart) * 1000000) /
freq.QuadPart);
freq.QuadPart);
}
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)

@ -120,35 +120,30 @@ static void print_help(void)
printf(
"usage: adig [-h] [-d] [-f flag] [[-s server] ...] [-T|U port] [-c class]\n"
" [-t type] name ...\n\n");
printf(" -h : Display this help and exit.\n");
printf(" -d : Print some extra debugging output.\n");
printf(
" -h : Display this help and exit.\n");
printf(
" -d : Print some extra debugging output.\n");
printf(
" -f flag : Add a behavior control flag. May be specified more than once\n"
" -f flag : Add a behavior control flag. May be specified more than "
"once\n"
" to add additional flags. Possible values are:\n"
" igntc - do not retry a truncated query as TCP, just\n"
" return the truncated answer\n"
" noaliases - don't honor the HOSTALIASES environment\n"
" variable\n");
printf(
" norecurse - don't query upstream servers recursively\n"
" primary - use the first server\n"
" stayopen - don't close the communication sockets\n"
" usevc - use TCP only\n"
" edns - use EDNS\n"
" dns0x20 - enable DNS 0x20 support\n");
printf(" norecurse - don't query upstream servers recursively\n"
" primary - use the first server\n"
" stayopen - don't close the communication sockets\n"
" usevc - use TCP only\n"
" edns - use EDNS\n"
" dns0x20 - enable DNS 0x20 support\n");
printf(
" -s server : Connect to the specified DNS server, instead of the\n"
" system's default one(s). Servers are tried in round-robin,\n"
" if the previous one failed.\n");
printf(
" -T port : Connect to the specified TCP port of DNS server.\n");
printf(
" -U port : Connect to the specified UDP port of DNS server.\n");
printf(
" -c class : Set the query class. Possible values for class are:\n"
" ANY, CHAOS, HS and IN (default)\n");
printf(" -T port : Connect to the specified TCP port of DNS server.\n");
printf(" -U port : Connect to the specified UDP port of DNS server.\n");
printf(" -c class : Set the query class. Possible values for class are:\n"
" ANY, CHAOS, HS and IN (default)\n");
printf(
" -t type : Query records of the specified type. Possible values for\n"
" type are:\n"
@ -156,7 +151,7 @@ static void print_help(void)
" SOA, SRV, TXT, TLSA, URI, CAA, SVCB, HTTPS\n\n");
}
static ares_bool_t read_cmdline(int argc, const char * const * argv,
static ares_bool_t read_cmdline(int argc, const char * const *argv,
adig_config_t *config)
{
ares_getopt_state_t state;
@ -224,12 +219,13 @@ static ares_bool_t read_cmdline(int argc, const char * const * argv,
long port = strtol(state.optarg, NULL, 0);
if (port <= 0 || port > 65535) {
snprintf(config->error, sizeof(config->error), "invalid port number");
snprintf(config->error, sizeof(config->error),
"invalid port number");
return ARES_FALSE;
}
config->options.tcp_port = (unsigned short)port;
config->options.flags |= ARES_FLAG_USEVC;
config->optmask |= ARES_OPT_TCP_PORT;
config->options.tcp_port = (unsigned short)port;
config->options.flags |= ARES_FLAG_USEVC;
config->optmask |= ARES_OPT_TCP_PORT;
}
break;
@ -239,12 +235,13 @@ static ares_bool_t read_cmdline(int argc, const char * const * argv,
long port = strtol(state.optarg, NULL, 0);
if (port <= 0 || port > 65535) {
snprintf(config->error, sizeof(config->error), "invalid port number");
snprintf(config->error, sizeof(config->error),
"invalid port number");
return ARES_FALSE;
}
config->options.udp_port = (unsigned short)port;
config->options.flags |= ARES_FLAG_USEVC;
config->optmask |= ARES_OPT_UDP_PORT;
config->options.udp_port = (unsigned short)port;
config->options.flags |= ARES_FLAG_USEVC;
config->optmask |= ARES_OPT_UDP_PORT;
}
break;
@ -637,10 +634,10 @@ static void print_binp(const ares_dns_rr_t *rr, ares_dns_rr_key_t key)
static void print_abinp(const ares_dns_rr_t *rr, ares_dns_rr_key_t key)
{
size_t i;
size_t cnt = ares_dns_rr_get_abin_cnt(rr, key);
size_t i;
size_t cnt = ares_dns_rr_get_abin_cnt(rr, key);
for (i=0; i<cnt; i++) {
for (i = 0; i < cnt; i++) {
size_t len;
const unsigned char *binp = ares_dns_rr_get_abin(rr, key, i, &len);
if (i != 0) {

@ -49,7 +49,8 @@
#define BADARG (int)':'
#define EMSG ""
void ares_getopt_init(ares_getopt_state_t *state, int nargc, const char * const * nargv)
void ares_getopt_init(ares_getopt_state_t *state, int nargc,
const char * const *nargv)
{
memset(state, 0, sizeof(*state));
state->opterr = 1;

@ -34,16 +34,17 @@
typedef struct {
const char *optarg; /* argument associated with option */
int optind; /* index into parent argv vector */
int opterr; /* if error message should be printed */
int optopt; /* character checked for validity */
const char *place;
int argc;
const char *optarg; /* argument associated with option */
int optind; /* index into parent argv vector */
int opterr; /* if error message should be printed */
int optopt; /* character checked for validity */
const char *place;
int argc;
const char * const *argv;
} ares_getopt_state_t;
void ares_getopt_init(ares_getopt_state_t *state, int argc, const char * const * argv);
void ares_getopt_init(ares_getopt_state_t *state, int argc,
const char * const *argv);
int ares_getopt(ares_getopt_state_t *state, const char *ostr);
#endif /* ARES_GETOPT_H */

8
test/ares-test.h vendored

@ -85,7 +85,7 @@ extern std::vector<std::pair<int, bool>> families_modes;
extern std::vector<std::tuple<ares_evsys_t, int, bool>> evsys_families_modes;
// Hopefully a more accurate sleep than sleep_for()
void ares_sleep_time(unsigned int ms);
void ares_sleep_time(unsigned int ms);
// Process all pending work on ares-owned file descriptors, plus
// optionally the given set-of-FDs + work function.
@ -220,7 +220,6 @@ protected:
ares_channel_t *channel_;
};
// Mock DNS server to allow responses to be scripted by tests.
class MockServer {
public:
@ -236,7 +235,7 @@ public:
void SetReplyData(const std::vector<byte> &reply)
{
exact_reply_ = reply;
reply_ = nullptr;
reply_ = nullptr;
}
void SetReply(const DNSPacket *reply)
@ -251,7 +250,7 @@ public:
void SetReplyExpRequest(const DNSPacket *reply, const std::string &request)
{
expected_request_ = request;
reply_ = reply;
reply_ = reply;
}
void SetReplyQID(int qid)
@ -391,6 +390,7 @@ public:
}
void Process(unsigned int cancel_ms = 0);
private:
struct ares_options evopts_;
};

@ -156,7 +156,8 @@ int main(int argc, char *argv[])
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
printf("Attempt %u using server list: %s ...\n", (unsigned int)count, servers);
printf("Attempt %u using server list: %s ...\n", (unsigned int)count,
servers);
ares_free_string(servers);
ares_getaddrinfo(channel, argv[1], NULL, &hints, ai_callback, argv[1]);

15
test/dns-proto.h vendored

@ -36,7 +36,8 @@
#include <string>
#include <vector>
extern "C" void arestest_strtolower(char *dest, const char *src, size_t dest_size);
extern "C" void arestest_strtolower(char *dest, const char *src,
size_t dest_size);
namespace ares {
@ -90,9 +91,9 @@ struct DNSQuestion {
return data(nullptr);
}
std::string name_;
int rrtype_;
int qclass_;
std::string name_;
int rrtype_;
int qclass_;
};
struct DNSRR : public DNSQuestion {
@ -383,13 +384,13 @@ struct DNSPacket {
}
// Return the encoded packet.
std::vector<byte> data(const char *request_name) const;
std::vector<byte> data() const
std::vector<byte> data(const char *request_name) const;
std::vector<byte> data() const
{
return data(nullptr);
}
int qid_;
bool response_;
int opcode_;

Loading…
Cancel
Save