clang-format

pull/617/head
Brad House 1 year ago
parent b2ea0cd6b2
commit 4e73f1055e
  1. 49
      include/ares.h
  2. 82
      include/ares_dns_record.h
  3. 25
      src/lib/ares__buf.c
  4. 8
      src/lib/ares__buf.h
  5. 8
      src/lib/ares_dns_mapping.c
  6. 9
      src/lib/ares_dns_parse.c
  7. 20
      src/lib/ares_dns_private.h
  8. 34
      src/lib/ares_dns_record.c
  9. 2
      src/lib/ares_dns_write.c
  10. 6
      src/lib/ares_math.c
  11. 5
      src/lib/ares_private.h
  12. 19
      src/lib/ares_process.c
  13. 1
      src/lib/ares_query.c
  14. 1
      src/lib/ares_send.c
  15. 8
      src/lib/ares_strsplit.c
  16. 51
      src/tools/adig.c
  17. 7
      src/tools/ares_getopt.c
  18. 2
      src/tools/ares_getopt.h

@ -353,52 +353,52 @@ CARES_EXTERN int ares_library_init_android(jobject connectivity_manager);
CARES_EXTERN int ares_library_android_initialized(void);
#endif
CARES_EXTERN int ares_library_initialized(void);
CARES_EXTERN int ares_library_initialized(void);
CARES_EXTERN void ares_library_cleanup(void);
CARES_EXTERN void ares_library_cleanup(void);
CARES_EXTERN const char *ares_version(int *version);
CARES_EXTERN const char *ares_version(int *version);
CARES_EXTERN int ares_init(ares_channel_t **channelptr);
CARES_EXTERN int ares_init(ares_channel_t **channelptr);
CARES_EXTERN int ares_init_options(ares_channel_t **channelptr,
const struct ares_options *options,
int optmask);
CARES_EXTERN int ares_init_options(ares_channel_t **channelptr,
const struct ares_options *options,
int optmask);
CARES_EXTERN int ares_save_options(ares_channel_t *channel,
struct ares_options *options, int *optmask);
CARES_EXTERN int ares_save_options(ares_channel_t *channel,
struct ares_options *options, int *optmask);
CARES_EXTERN void ares_destroy_options(struct ares_options *options);
CARES_EXTERN void ares_destroy_options(struct ares_options *options);
CARES_EXTERN int ares_dup(ares_channel_t **dest, ares_channel_t *src);
CARES_EXTERN int ares_dup(ares_channel_t **dest, ares_channel_t *src);
CARES_EXTERN ares_status_t ares_reinit(ares_channel_t *channel);
CARES_EXTERN void ares_destroy(ares_channel_t *channel);
CARES_EXTERN void ares_destroy(ares_channel_t *channel);
CARES_EXTERN void ares_cancel(ares_channel_t *channel);
CARES_EXTERN void ares_cancel(ares_channel_t *channel);
/* These next 3 configure local binding for the out-going socket
* connection. Use these to specify source IP and/or network device
* on multi-homed systems.
*/
CARES_EXTERN void ares_set_local_ip4(ares_channel_t *channel,
unsigned int local_ip);
CARES_EXTERN void ares_set_local_ip4(ares_channel_t *channel,
unsigned int local_ip);
/* local_ip6 should be 16 bytes in length */
CARES_EXTERN void ares_set_local_ip6(ares_channel_t *channel,
const unsigned char *local_ip6);
CARES_EXTERN void ares_set_local_ip6(ares_channel_t *channel,
const unsigned char *local_ip6);
/* local_dev_name should be null terminated. */
CARES_EXTERN void ares_set_local_dev(ares_channel_t *channel,
const char *local_dev_name);
CARES_EXTERN void ares_set_local_dev(ares_channel_t *channel,
const char *local_dev_name);
CARES_EXTERN void ares_set_socket_callback(ares_channel_t *channel,
ares_sock_create_callback callback,
void *user_data);
CARES_EXTERN void ares_set_socket_callback(ares_channel_t *channel,
ares_sock_create_callback callback,
void *user_data);
CARES_EXTERN void ares_set_socket_configure_callback(
ares_channel_t *channel, ares_sock_config_callback callback, void *user_data);
CARES_EXTERN void ares_set_socket_configure_callback(
ares_channel_t *channel, ares_sock_config_callback callback, void *user_data);
CARES_EXTERN int ares_set_sortlist(ares_channel_t *channel,
const char *sortstr);
@ -519,7 +519,6 @@ struct ares_addr {
} addr;
};
struct ares_addrttl {
struct in_addr ipaddr;
int ttl;

@ -114,44 +114,44 @@ typedef enum {
/*! DNS Response Codes from server */
typedef enum {
ARES_RCODE_NOERROR = 0, /*!< Success */
ARES_RCODE_NOERROR = 0, /*!< Success */
ARES_RCODE_FORMERR = 1, /*!< Format error. The name server was unable
* to interpret the query. */
ARES_RCODE_SERVFAIL = 2, /*!< Server Failure. The name server was
* unable to process this query due to a
* problem with the nameserver */
ARES_RCODE_NXDOMAIN = 3, /*!< Name Error. Meaningful only for
* responses from an authoritative name
* server, this code signifies that the
* domain name referenced in the query does
* not exist. */
ARES_RCODE_NOTIMP = 4, /*!< Not implemented. The name server does
* not support the requested kind of
* query */
ARES_RCODE_REFUSED = 5, /*!< Refused. The name server refuses to
* perform the speciied operation for
* policy reasons. */
ARES_RCODE_YXDOMAIN = 6, /*!< RFC 2136. Some name that ought not to
* exist, does exist. */
ARES_RCODE_YXRRSET = 7, /*!< RFC 2136. Some RRset that ought to not
* exist, does exist. */
ARES_RCODE_NXRRSET = 8, /*!< RFC 2136. Some RRset that ought to exist,
* does not exist. */
ARES_RCODE_NOTAUTH = 9, /*!< RFC 2136. The server is not authoritative
* for the zone named in the Zone section.
*/
ARES_RCODE_NOTZONE = 10, /*!< RFC 2136. A name used in the Prerequisite
* or Update Section is not within the zone
* denoted by the Zone Section. */
ARES_RCODE_DSOTYPEI = 11, /*!< RFC 8409. DSO-TYPE Not implemented */
ARES_RCODE_BADSIG = 16, /*!< RFC 8945. TSIG Signature Failure */
ARES_RCODE_BADKEY = 17, /*!< RFC 8945. Key not recognized. */
ARES_RCODE_BADTIME = 18, /*!< RFC 8945. Signature out of time window. */
ARES_RCODE_BADMODE = 19, /*!< RFC 2930. Bad TKEY Mode */
ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */
ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */
ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */
ARES_RCODE_BADCOOKIE = 23, /*!< RVC 7973. Bad/missing Server Cookie */
* to interpret the query. */
ARES_RCODE_SERVFAIL = 2, /*!< Server Failure. The name server was
* unable to process this query due to a
* problem with the nameserver */
ARES_RCODE_NXDOMAIN = 3, /*!< Name Error. Meaningful only for
* responses from an authoritative name
* server, this code signifies that the
* domain name referenced in the query does
* not exist. */
ARES_RCODE_NOTIMP = 4, /*!< Not implemented. The name server does
* not support the requested kind of
* query */
ARES_RCODE_REFUSED = 5, /*!< Refused. The name server refuses to
* perform the speciied operation for
* policy reasons. */
ARES_RCODE_YXDOMAIN = 6, /*!< RFC 2136. Some name that ought not to
* exist, does exist. */
ARES_RCODE_YXRRSET = 7, /*!< RFC 2136. Some RRset that ought to not
* exist, does exist. */
ARES_RCODE_NXRRSET = 8, /*!< RFC 2136. Some RRset that ought to exist,
* does not exist. */
ARES_RCODE_NOTAUTH = 9, /*!< RFC 2136. The server is not authoritative
* for the zone named in the Zone section.
*/
ARES_RCODE_NOTZONE = 10, /*!< RFC 2136. A name used in the Prerequisite
* or Update Section is not within the zone
* denoted by the Zone Section. */
ARES_RCODE_DSOTYPEI = 11, /*!< RFC 8409. DSO-TYPE Not implemented */
ARES_RCODE_BADSIG = 16, /*!< RFC 8945. TSIG Signature Failure */
ARES_RCODE_BADKEY = 17, /*!< RFC 8945. Key not recognized. */
ARES_RCODE_BADTIME = 18, /*!< RFC 8945. Signature out of time window. */
ARES_RCODE_BADMODE = 19, /*!< RFC 2930. Bad TKEY Mode */
ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */
ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */
ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */
ARES_RCODE_BADCOOKIE = 23, /*!< RVC 7973. Bad/missing Server Cookie */
} ares_dns_rcode_t;
/*! Data types used */
@ -455,7 +455,7 @@ CARES_EXTERN const char *ares_dns_rcode_tostr(ares_dns_rcode_t rcode);
* \param[out] ptr_len Length of binary form address
* \return Pointer to start of binary address or NULL on error.
*/
CARES_EXTERN const void *ares_dns_pton(const char *ipaddr,
CARES_EXTERN const void *ares_dns_pton(const char *ipaddr,
struct ares_addr *addr, size_t *out_len);
/*! Convert an ip address into the PTR format for in-addr.arpa or in6.arpa
@ -463,7 +463,7 @@ CARES_EXTERN const void *ares_dns_pton(const char *ipaddr,
* \param[in] addr properly filled address structure
* \return String representing PTR, use ares_free_string() to free
*/
CARES_EXTERN char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
CARES_EXTERN char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
/*! The options/parameters extensions to some RRs can be somewhat opaque, this
@ -512,7 +512,7 @@ CARES_EXTERN ares_dns_datatype_t
* \return DNS Resource Record Type
*/
CARES_EXTERN ares_dns_rec_type_t
ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key);
ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key);
/*! Opaque data type representing a DNS RR (Resource Record) */
struct ares_dns_rr;
@ -680,7 +680,7 @@ CARES_EXTERN ares_status_t ares_dns_record_rr_del(ares_dns_record_t *dnsrec,
* \param[in] rr Pointer to resource record
* \return Name
*/
CARES_EXTERN const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr);
CARES_EXTERN const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr);
/*! Retrieve the resource record type
*

@ -838,7 +838,6 @@ ares_status_t ares__buf_parse_dns_str(ares__buf_t *buf, size_t remaining_len,
&len, allow_multiple);
}
ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num, size_t len)
{
size_t i;
@ -850,15 +849,16 @@ ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num, size_t len)
mod = ares__pow(10, len);
for (i=len; i>0; i--) {
for (i = len; i > 0; i--) {
size_t digit = (num % mod);
ares_status_t status;
mod /= 10;
digit /= mod;
status = ares__buf_append_byte(buf, '0' + (unsigned char)(digit & 0xFF));
if (status != ARES_SUCCESS)
mod /= 10;
digit /= mod;
status = ares__buf_append_byte(buf, '0' + (unsigned char)(digit & 0xFF));
if (status != ARES_SUCCESS) {
return status;
}
}
return ARES_SUCCESS;
}
@ -887,10 +887,9 @@ static ares_status_t ares__buf_append_str(ares__buf_t *buf, const char *str)
return ares__buf_append(buf, (const unsigned char *)str, ares_strlen(str));
}
static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf,
size_t idx,
static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf, size_t idx,
const unsigned char *data,
size_t len)
size_t len)
{
size_t i;
ares_status_t status;
@ -933,8 +932,7 @@ static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf,
if (i >= len) {
break;
}
status =
ares__buf_append_byte(buf, ares__isprint(data[i]) ? data[i] : '.');
status = ares__buf_append_byte(buf, ares__isprint(data[i]) ? data[i] : '.');
if (status != ARES_SUCCESS) {
return status;
}
@ -946,14 +944,15 @@ static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf,
ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data,
size_t len)
{
size_t i;
size_t i;
/* Each line is 16 bytes */
for (i = 0; i < len; i += 16) {
ares_status_t status;
status = ares__buf_hexdump_line(buf, i, data + i, len - i);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
}
return ARES_SUCCESS;

@ -113,8 +113,8 @@ ares_status_t ares__buf_append_be32(ares__buf_t *buf, unsigned int u32);
* \param[in] len Length to output, use 0 for no padding
* \return ARES_SUCCESS on succeess
*/
ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num,
size_t len);
ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num,
size_t len);
/*! Append a number in ASCII hexidecimal form.
*
@ -123,8 +123,8 @@ ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num,
* \param[in] len Length to output, use 0 for no padding
* \return ARES_SUCCESS on succeess
*/
ares_status_t ares__buf_append_num_hex(ares__buf_t *buf, size_t num,
size_t len);
ares_status_t ares__buf_append_num_hex(ares__buf_t *buf, size_t num,
size_t len);
/*! Sets the current buffer length. This *may* be used if there is a need to
* override a prior position in the buffer, such as if there is a length

@ -503,10 +503,10 @@ static const ares_dns_rr_key_t rr_naptr_keys[] = {
ARES_RR_NAPTR_ORDER, ARES_RR_NAPTR_PREFERENCE, ARES_RR_NAPTR_FLAGS,
ARES_RR_NAPTR_SERVICES, ARES_RR_NAPTR_REGEXP, ARES_RR_NAPTR_REPLACEMENT
};
static const ares_dns_rr_key_t rr_opt_keys[] = {
ARES_RR_OPT_UDP_SIZE, ARES_RR_OPT_VERSION, ARES_RR_OPT_FLAGS,
ARES_RR_OPT_OPTIONS
};
static const ares_dns_rr_key_t rr_opt_keys[] = { ARES_RR_OPT_UDP_SIZE,
ARES_RR_OPT_VERSION,
ARES_RR_OPT_FLAGS,
ARES_RR_OPT_OPTIONS };
static const ares_dns_rr_key_t rr_tlsa_keys[] = { ARES_RR_TLSA_CERT_USAGE,
ARES_RR_TLSA_SELECTOR,
ARES_RR_TLSA_MATCH,

@ -62,12 +62,9 @@ static ares_status_t ares_dns_parse_and_set_dns_name(ares__buf_t *buf,
return ARES_SUCCESS;
}
static ares_status_t ares_dns_parse_and_set_dns_str(ares__buf_t *buf,
size_t max_len,
ares_bool_t allow_multiple,
ares_dns_rr_t *rr,
ares_dns_rr_key_t key,
ares_bool_t blank_allowed)
static ares_status_t ares_dns_parse_and_set_dns_str(
ares__buf_t *buf, size_t max_len, ares_bool_t allow_multiple,
ares_dns_rr_t *rr, ares_dns_rr_key_t key, ares_bool_t blank_allowed)
{
ares_status_t status;
char *str = NULL;

@ -45,7 +45,7 @@ ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
unsigned char *val, size_t val_len);
ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t cnt);
ares_bool_t ares_dns_has_opt_rr(const ares_dns_record_t *rec);
ares_bool_t ares_dns_has_opt_rr(const ares_dns_record_t *rec);
struct ares_dns_qd {
char *name;
@ -128,11 +128,11 @@ typedef struct {
} ares__dns_options_t;
typedef struct {
unsigned short udp_size; /*!< taken from class */
unsigned char version; /*!< taken from bits 8-16 of ttl */
unsigned short flags; /*!< Flags, remaining 16 bits, though only
* 1 currently defined */
ares__dns_options_t *options; /*!< Attribute/Value pairs */
unsigned short udp_size; /*!< taken from class */
unsigned char version; /*!< taken from bits 8-16 of ttl */
unsigned short flags; /*!< Flags, remaining 16 bits, though only
* 1 currently defined */
ares__dns_options_t *options; /*!< Attribute/Value pairs */
} ares__dns_opt_t;
typedef struct {
@ -202,10 +202,10 @@ struct ares_dns_rr {
/*! DNS data structure */
struct ares_dns_record {
unsigned short id; /*!< DNS query id */
unsigned short flags; /*!< One or more ares_dns_flags_t */
ares_dns_opcode_t opcode; /*!< DNS Opcode */
ares_dns_rcode_t rcode; /*!< DNS RCODE */
unsigned short id; /*!< DNS query id */
unsigned short flags; /*!< One or more ares_dns_flags_t */
ares_dns_opcode_t opcode; /*!< DNS Opcode */
ares_dns_rcode_t rcode; /*!< DNS RCODE */
unsigned short raw_rcode; /*!< Raw rcode, used to ultimately form real
* rcode after reading OPT record if it
* exists */

@ -499,8 +499,9 @@ ares_dns_rr_t *ares_dns_record_rr_get(ares_dns_record_t *dnsrec,
return &rr_ptr[idx];
}
static const ares_dns_rr_t *ares_dns_record_rr_get_const(const ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t idx)
static const ares_dns_rr_t *
ares_dns_record_rr_get_const(const ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t idx)
{
return ares_dns_record_rr_get((void *)((size_t)dnsrec), sect, idx);
}
@ -1236,12 +1237,14 @@ char *ares_dns_addr_to_ptr(const struct ares_addr *addr)
ares_status_t status;
static const unsigned char hexbytes[] = "0123456789abcdef";
if (addr->family != AF_INET && addr->family != AF_INET6)
if (addr->family != AF_INET && addr->family != AF_INET6) {
goto fail;
}
buf = ares__buf_create();
if (buf == NULL)
if (buf == NULL) {
goto fail;
}
if (addr->family == AF_INET) {
ptr = (const unsigned char *)&addr->addr.addr4;
@ -1251,30 +1254,34 @@ char *ares_dns_addr_to_ptr(const struct ares_addr *addr)
ptr_len = 16;
}
for (i=ptr_len; i>0; i--) {
for (i = ptr_len; i > 0; i--) {
if (addr->family == AF_INET) {
status = ares__buf_append_num_dec(buf, (size_t)ptr[i-1], 0);
status = ares__buf_append_num_dec(buf, (size_t)ptr[i - 1], 0);
} else {
unsigned char c;
c = ptr[i-1] & 0xF;
c = ptr[i - 1] & 0xF;
status = ares__buf_append_byte(buf, hexbytes[c]);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto fail;
}
status = ares__buf_append_byte(buf, '.');
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto fail;
}
c = (ptr[i-1] >> 4) & 0xF;
c = (ptr[i - 1] >> 4) & 0xF;
status = ares__buf_append_byte(buf, hexbytes[c]);
}
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto fail;
}
status = ares__buf_append_byte(buf, '.');
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto fail;
}
}
if (addr->family == AF_INET) {
@ -1282,8 +1289,9 @@ char *ares_dns_addr_to_ptr(const struct ares_addr *addr)
} else {
status = ares__buf_append(buf, (const unsigned char *)"ip6.arpa", 8);
}
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto fail;
}
return ares__buf_finish_str(buf, NULL);

@ -99,7 +99,7 @@ static ares_status_t ares_dns_write_header(const ares_dns_record_t *dnsrec,
} else {
rcode = (unsigned short)(dnsrec->rcode & 0xF);
}
u16 |= rcode;
u16 |= rcode;
status = ares__buf_append_be16(buf, u16);
if (status != ARES_SUCCESS) {

@ -92,8 +92,9 @@ size_t ares__count_digits(size_t n)
for (digits = 0; n > 0; digits++) {
n /= 10;
}
if (digits == 0)
if (digits == 0) {
digits = 1;
}
return digits;
}
@ -105,8 +106,9 @@ size_t ares__count_hexdigits(size_t n)
for (digits = 0; n > 0; digits++) {
n /= 16;
}
if (digits == 0)
if (digits == 0) {
digits = 1;
}
return digits;
}

@ -252,7 +252,7 @@ struct ares_channeldata {
size_t timeout; /* in milliseconds */
size_t tries;
size_t ndots;
size_t maxtimeout; /* in milliseconds */
size_t maxtimeout; /* in milliseconds */
ares_bool_t rotate;
unsigned short udp_port; /* stored in network order */
unsigned short tcp_port; /* stored in network order */
@ -277,7 +277,8 @@ struct ares_channeldata {
* failures, followed by the configuration order if failures are equal. */
ares__slist_t *servers;
/* random state to use when generating new ids and generating retry penalties */
/* random state to use when generating new ids and generating retry penalties
*/
ares_rand_state *rand_state;
/* All active queries in a single list */

@ -688,8 +688,8 @@ static ares_status_t process_answer(ares_channel_t *channel,
*/
if (!(channel->flags & ARES_FLAG_NOCHECKRESP)) {
ares_dns_rcode_t rcode = ares_dns_record_get_rcode(rdnsrec);
if (rcode == ARES_RCODE_SERVFAIL ||
rcode == ARES_RCODE_NOTIMP || rcode == ARES_RCODE_REFUSED) {
if (rcode == ARES_RCODE_SERVFAIL || rcode == ARES_RCODE_NOTIMP ||
rcode == ARES_RCODE_REFUSED) {
switch (rcode) {
case ARES_RCODE_SERVFAIL:
query->error_status = ARES_ESERVFAIL;
@ -811,8 +811,9 @@ static size_t ares__calc_query_timeout(struct query *query)
timeplus <<= rounds;
}
if (channel->maxtimeout && timeplus > channel->maxtimeout)
if (channel->maxtimeout && timeplus > channel->maxtimeout) {
timeplus = channel->maxtimeout;
}
/* Add some jitter to the retry timeout.
*
@ -820,21 +821,23 @@ static size_t ares__calc_query_timeout(struct query *query)
* simultaneously from multiple hosts and DNS server throttle these requests.
* Adding randomness allows to avoid synchronisation of retries.
*
* Value of timeplus adjusted randomly to the range [0.5 * timeplus, timeplus].
* Value of timeplus adjusted randomly to the range [0.5 * timeplus,
* timeplus].
*/
if (rounds > 0) {
unsigned short r;
float delta_multiplier;
float delta_multiplier;
ares__rand_bytes(channel->rand_state, (unsigned char *)&r, sizeof(r));
delta_multiplier = ((float)r / USHRT_MAX) * 0.5f;
timeplus -= (size_t)((float)timeplus * delta_multiplier);
delta_multiplier = ((float)r / USHRT_MAX) * 0.5f;
timeplus -= (size_t)((float)timeplus * delta_multiplier);
}
/* We want explicitly guarantee that timeplus is greater or equal to timeout
* specified in channel options. */
if (timeplus < channel->timeout)
if (timeplus < channel->timeout) {
timeplus = channel->timeout;
}
return timeplus;
}

@ -45,7 +45,6 @@ struct qquery {
static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf,
int alen);
ares_status_t ares_query_qid(ares_channel_t *channel, const char *name,
int dnsclass, int type, ares_callback callback,
void *arg, unsigned short *qid)

@ -37,7 +37,6 @@
#include "ares_dns.h"
#include "ares_private.h"
static unsigned short generate_unique_qid(ares_channel_t *channel)
{
unsigned short id;

@ -51,14 +51,16 @@ char **ares__strsplit_duplicate(char **elms, size_t num_elm)
size_t i;
char **out;
if (elms == NULL || num_elm == 0)
if (elms == NULL || num_elm == 0) {
return NULL;
}
out = ares_malloc_zero(sizeof(*elms) * num_elm);
if (out == NULL)
if (out == NULL) {
return NULL;
}
for (i=0; i<num_elm; i++) {
for (i = 0; i < num_elm; i++) {
out[i] = ares_strdup(elms[i]);
if (out[i] == NULL) {
ares__strsplit_free(out, num_elm);

@ -146,7 +146,8 @@ 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 **argv, adig_config_t *config)
static ares_bool_t read_cmdline(int argc, const char **argv,
adig_config_t *config)
{
ares_getopt_state_t state;
int c;
@ -193,8 +194,8 @@ static ares_bool_t read_cmdline(int argc, const char **argv, adig_config_t *conf
case 'c':
if (!ares_dns_class_fromstr(&config->qclass, state.optarg)) {
snprintf(config->error, sizeof(config->error), "unrecognized class %s",
state.optarg);
snprintf(config->error, sizeof(config->error),
"unrecognized class %s", state.optarg);
return ARES_FALSE;
}
break;
@ -213,9 +214,10 @@ static ares_bool_t read_cmdline(int argc, const char **argv, adig_config_t *conf
snprintf(config->error, sizeof(config->error), "invalid port number");
return ARES_FALSE;
}
config->options.tcp_port = (unsigned short)strtol(state.optarg, NULL, 0);
config->options.flags |= ARES_FLAG_USEVC;
config->optmask |= ARES_OPT_TCP_PORT;
config->options.tcp_port =
(unsigned short)strtol(state.optarg, NULL, 0);
config->options.flags |= ARES_FLAG_USEVC;
config->optmask |= ARES_OPT_TCP_PORT;
break;
case 'U':
@ -224,17 +226,20 @@ static ares_bool_t read_cmdline(int argc, const char **argv, adig_config_t *conf
snprintf(config->error, sizeof(config->error), "invalid port number");
return ARES_FALSE;
}
config->options.udp_port = (unsigned short)strtol(state.optarg, NULL, 0);
config->optmask |= ARES_OPT_UDP_PORT;
config->options.udp_port =
(unsigned short)strtol(state.optarg, NULL, 0);
config->optmask |= ARES_OPT_UDP_PORT;
break;
case ':':
snprintf(config->error, sizeof(config->error), "%c requires an argument", state.optopt);
snprintf(config->error, sizeof(config->error),
"%c requires an argument", state.optopt);
return ARES_FALSE;
case '?':
default:
snprintf(config->error, sizeof(config->error), "unrecognized option: %c", state.optopt);
snprintf(config->error, sizeof(config->error),
"unrecognized option: %c", state.optopt);
return ARES_FALSE;
}
}
@ -296,10 +301,13 @@ static void print_question(const ares_dns_record_t *dnsrec)
ares_dns_rec_type_t qtype;
ares_dns_class_t qclass;
size_t len;
if (ares_dns_record_query_get(dnsrec, i, &name, &qtype, &qclass) != ARES_SUCCESS)
if (ares_dns_record_query_get(dnsrec, i, &name, &qtype, &qclass) !=
ARES_SUCCESS) {
return;
if (name == NULL)
}
if (name == NULL) {
return;
}
len = strlen(name);
printf(";%s.\t", name);
if (len + 1 < 24) {
@ -377,13 +385,13 @@ static void print_opt_u16_list(const unsigned char *val, size_t val_len)
return;
}
for (i = 0; i < val_len; i += 2) {
unsigned short u16 = 0;
unsigned short u16 = 0;
unsigned short c;
/* Jumping over backwards to try to avoid odd compiler warnings */
c = (unsigned short)val[i];
u16 |= (unsigned short)((c << 8) & 0xFFFF);
c = (unsigned short)val[i+1];
u16 |= c;
c = (unsigned short)val[i];
u16 |= (unsigned short)((c << 8) & 0xFFFF);
c = (unsigned short)val[i + 1];
u16 |= c;
if (i != 0) {
printf(",");
}
@ -620,8 +628,9 @@ static void print_rr(const ares_dns_rr_t *rr)
const ares_dns_rr_key_t *keys = ares_dns_rr_get_keys(rtype, &keys_cnt);
size_t i;
if (name == NULL)
if (name == NULL) {
return;
}
len = strlen(name);
@ -767,8 +776,8 @@ static ares_status_t enqueue_query(ares_channel_t *channel,
const adig_config_t *config,
const char *name)
{
ares_dns_record_t *dnsrec = NULL;
ares_dns_rr_t *rr = NULL;
ares_dns_record_t *dnsrec = NULL;
ares_dns_rr_t *rr = NULL;
ares_status_t status;
unsigned char *buf = NULL;
size_t buf_len = 0;
@ -871,7 +880,7 @@ int main(int argc, char **argv)
ares_status_t status;
adig_config_t config;
int i;
int rv = 0;
int rv = 0;
#ifdef USE_WINSOCK
WORD wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);

@ -65,7 +65,7 @@ void ares_getopt_init(ares_getopt_state_t *state, int nargc, const char **nargv)
*/
int ares_getopt(ares_getopt_state_t *state, const char *ostr)
{
const char *oli; /* option letter list index */
const char *oli; /* option letter list index */
/* update scanning pointer */
if (!*state->place) {
@ -101,7 +101,8 @@ int ares_getopt(ares_getopt_state_t *state, const char *ostr)
++state->optind;
}
if (state->opterr) {
(void)fprintf(stderr, "%s: illegal option -- %c\n", __FILE__, state->optopt);
(void)fprintf(stderr, "%s: illegal option -- %c\n", __FILE__,
state->optopt);
}
return BADCH;
}
@ -114,7 +115,7 @@ int ares_getopt(ares_getopt_state_t *state, const char *ostr)
}
} else {
/* need an argument */
if (*state->place) { /* no white space */
if (*state->place) { /* no white space */
state->optarg = state->place;
} else if (state->argc <= ++state->optind) { /* no arg */
state->place = EMSG;

@ -44,6 +44,6 @@ typedef struct {
} ares_getopt_state_t;
void ares_getopt_init(ares_getopt_state_t *state, int argc, const char **argv);
int ares_getopt(ares_getopt_state_t *state, const char *ostr);
int ares_getopt(ares_getopt_state_t *state, const char *ostr);
#endif /* ARES_GETOPT_H */

Loading…
Cancel
Save