ares_status_t enum for status codes (#567)

The list of possible error codes in c-ares was a #define list. This not only doesn't provide for any sort of type safety but it also lacks clarification on what a function may return or what it takes, as an int could be an ares status, a boolean, or possibly even a length in the current code.

We are not changing any public APIs as though the C standard states the underlying size and type of an enum is int, there are compiler attributes to override this as well as compiler flags like -fshort-enums. GCC in particular is known to expand an enum's width based on the data values (e.g., it can emit a 64bit integer enum).

All internal usages should be changed by this PR, but of course, there may be some I missed.

Fix By: Brad House (@bradh352)
pull/569/head
Brad House 1 year ago committed by GitHub
parent 125c8a1684
commit 973023b4b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 71
      include/ares.h
  2. 12
      src/lib/ares__addrinfo2hostent.c
  3. 44
      src/lib/ares__addrinfo_localhost.c
  4. 27
      src/lib/ares__buf.c
  5. 20
      src/lib/ares__buf.h
  6. 4
      src/lib/ares__get_hostent.c
  7. 11
      src/lib/ares__parse_into_addrinfo.c
  8. 2
      src/lib/ares__read_line.c
  9. 12
      src/lib/ares__readaddrinfo.c
  10. 3
      src/lib/ares__sortaddrinfo.c
  11. 19
      src/lib/ares_expand_name.c
  12. 16
      src/lib/ares_getaddrinfo.c
  13. 12
      src/lib/ares_gethostbyaddr.c
  14. 10
      src/lib/ares_gethostbyname.c
  15. 83
      src/lib/ares_init.c
  16. 10
      src/lib/ares_options.c
  17. 2
      src/lib/ares_parse_a_reply.c
  18. 2
      src/lib/ares_parse_aaaa_reply.c
  19. 3
      src/lib/ares_parse_caa_reply.c
  20. 3
      src/lib/ares_parse_mx_reply.c
  21. 3
      src/lib/ares_parse_naptr_reply.c
  22. 3
      src/lib/ares_parse_ns_reply.c
  23. 3
      src/lib/ares_parse_ptr_reply.c
  24. 3
      src/lib/ares_parse_soa_reply.c
  25. 3
      src/lib/ares_parse_srv_reply.c
  26. 3
      src/lib/ares_parse_txt_reply.c
  27. 3
      src/lib/ares_parse_uri_reply.c
  28. 87
      src/lib/ares_private.h
  29. 40
      src/lib/ares_process.c
  30. 9
      src/lib/ares_query.c
  31. 10
      src/lib/ares_search.c
  32. 4
      src/lib/ares_send.c
  33. 88
      src/lib/ares_strerror.c
  34. 2
      test/ares-test-internal.cc

@ -112,48 +112,51 @@ extern "C" {
#endif
#define ARES_SUCCESS 0
/* Server error codes (ARES_ENODATA indicates no relevant answer) */
#define ARES_ENODATA 1
#define ARES_EFORMERR 2
#define ARES_ESERVFAIL 3
#define ARES_ENOTFOUND 4
#define ARES_ENOTIMP 5
#define ARES_EREFUSED 6
/* Locally generated error codes */
#define ARES_EBADQUERY 7
#define ARES_EBADNAME 8
#define ARES_EBADFAMILY 9
#define ARES_EBADRESP 10
#define ARES_ECONNREFUSED 11
#define ARES_ETIMEOUT 12
#define ARES_EOF 13
#define ARES_EFILE 14
#define ARES_ENOMEM 15
#define ARES_EDESTRUCTION 16
#define ARES_EBADSTR 17
typedef enum {
ARES_SUCCESS = 0,
/* Server error codes (ARES_ENODATA indicates no relevant answer) */
ARES_ENODATA = 1,
ARES_EFORMERR = 2,
ARES_ESERVFAIL = 3,
ARES_ENOTFOUND = 4,
ARES_ENOTIMP = 5,
ARES_EREFUSED = 6,
/* Locally generated error codes */
ARES_EBADQUERY = 7,
ARES_EBADNAME = 8,
ARES_EBADFAMILY = 9,
ARES_EBADRESP = 10,
ARES_ECONNREFUSED = 11,
ARES_ETIMEOUT = 12,
ARES_EOF = 13,
ARES_EFILE = 14,
ARES_ENOMEM = 15,
ARES_EDESTRUCTION = 16,
ARES_EBADSTR = 17,
/* ares_getnameinfo error codes */
#define ARES_EBADFLAGS 18
ARES_EBADFLAGS = 18,
/* ares_getaddrinfo error codes */
#define ARES_ENONAME 19
#define ARES_EBADHINTS 20
ARES_ENONAME = 19,
ARES_EBADHINTS = 20,
/* Uninitialized library error code */
#define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
/* Uninitialized library error code */
ARES_ENOTINITIALIZED = 21, /* introduced in 1.7.0 */
/* ares_library_init error codes */
#define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
#define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
/* ares_library_init error codes */
ARES_ELOADIPHLPAPI = 22, /* introduced in 1.7.0 */
ARES_EADDRGETNETWORKPARAMS = 23, /* introduced in 1.7.0 */
/* More error codes */
#define ARES_ECANCELLED 24 /* introduced in 1.7.0 */
/* More error codes */
ARES_ECANCELLED = 24, /* introduced in 1.7.0 */
/* More ares_getaddrinfo error codes */
ARES_ESERVICE = 25 /* introduced in 1.?.0 */
} ares_status_t;
/* More ares_getaddrinfo error codes */
#define ARES_ESERVICE 25 /* introduced in 1.?.0 */
/* Flag values */
#define ARES_FLAG_USEVC (1 << 0)

@ -54,8 +54,8 @@
#include "ares_inet_net_pton.h"
#include "ares_private.h"
int ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
struct hostent **host)
ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
struct hostent **host)
{
struct ares_addrinfo_node *next;
struct ares_addrinfo_cname *next_cname;
@ -205,9 +205,11 @@ enomem:
}
int ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
int req_naddrttls, struct ares_addrttl *addrttls,
struct ares_addr6ttl *addr6ttls, int *naddrttls)
ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
int req_naddrttls,
struct ares_addrttl *addrttls,
struct ares_addr6ttl *addr6ttls,
int *naddrttls)
{
struct ares_addrinfo_node *next;
struct ares_addrinfo_cname *next_cname;

@ -47,11 +47,11 @@
#include "ares_nowarn.h"
#include "ares_private.h"
int ares_append_ai_node(int aftype,
unsigned short port,
int ttl,
const void *adata,
struct ares_addrinfo_node **nodes)
ares_status_t ares_append_ai_node(int aftype,
unsigned short port,
int ttl,
const void *adata,
struct ares_addrinfo_node **nodes)
{
struct ares_addrinfo_node *node;
@ -107,11 +107,11 @@ int ares_append_ai_node(int aftype,
}
static int ares__default_loopback_addrs(int aftype,
unsigned short port,
struct ares_addrinfo_node **nodes)
static ares_status_t ares__default_loopback_addrs(int aftype,
unsigned short port,
struct ares_addrinfo_node **nodes)
{
int status = ARES_SUCCESS;
ares_status_t status = ARES_SUCCESS;
if (aftype == AF_UNSPEC || aftype == AF_INET6)
{
@ -139,14 +139,14 @@ static int ares__default_loopback_addrs(int aftype,
}
static int ares__system_loopback_addrs(int aftype,
unsigned short port,
struct ares_addrinfo_node **nodes)
static ares_status_t ares__system_loopback_addrs(int aftype,
unsigned short port,
struct ares_addrinfo_node **nodes)
{
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && !defined(__WATCOMC__)
PMIB_UNICASTIPADDRESS_TABLE table;
unsigned int i;
int status;
ares_status_t status;
*nodes = NULL;
@ -209,13 +209,13 @@ fail:
}
int ares__addrinfo_localhost(const char *name,
unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai)
ares_status_t ares__addrinfo_localhost(const char *name,
unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai)
{
struct ares_addrinfo_node *nodes = NULL;
int result;
ares_status_t status;
/* Validate family */
switch (hints->ai_family) {
@ -233,16 +233,16 @@ int ares__addrinfo_localhost(const char *name,
goto enomem;
}
result = ares__system_loopback_addrs(hints->ai_family, port, &nodes);
status = ares__system_loopback_addrs(hints->ai_family, port, &nodes);
if (result == ARES_ENOTFOUND)
if (status == ARES_ENOTFOUND)
{
result = ares__default_loopback_addrs(hints->ai_family, port, &nodes);
status = ares__default_loopback_addrs(hints->ai_family, port, &nodes);
}
ares__addrinfo_cat_nodes(&ai->nodes, nodes);
return result;
return status;
enomem:
ares__freeaddrinfo_nodes(nodes);

@ -129,7 +129,8 @@ static void ares__buf_reclaim(ares__buf_t *buf)
}
static int ares__buf_ensure_space(ares__buf_t *buf, size_t needed_size)
static ares_status_t ares__buf_ensure_space(ares__buf_t *buf,
size_t needed_size)
{
size_t remaining_size;
size_t alloc_size;
@ -182,10 +183,10 @@ static int ares__buf_ensure_space(ares__buf_t *buf, size_t needed_size)
}
int ares__buf_append(ares__buf_t *buf, const unsigned char *data,
size_t data_len)
ares_status_t ares__buf_append(ares__buf_t *buf, const unsigned char *data,
size_t data_len)
{
int status;
ares_status_t status;
if (data == NULL || data_len == 0)
return ARES_EFORMERR;
@ -202,7 +203,7 @@ int ares__buf_append(ares__buf_t *buf, const unsigned char *data,
unsigned char *ares__buf_append_start(ares__buf_t *buf, size_t *len)
{
int status;
ares_status_t status;
if (len == NULL || *len == 0)
return NULL;
@ -268,7 +269,7 @@ void ares__buf_tag(ares__buf_t *buf)
}
int ares__buf_tag_rollback(ares__buf_t *buf)
ares_status_t ares__buf_tag_rollback(ares__buf_t *buf)
{
if (buf == NULL || buf->tag_offset == SIZE_MAX)
return ARES_EFORMERR;
@ -279,7 +280,7 @@ int ares__buf_tag_rollback(ares__buf_t *buf)
}
int ares__buf_tag_clear(ares__buf_t *buf)
ares_status_t ares__buf_tag_clear(ares__buf_t *buf)
{
if (buf == NULL || buf->tag_offset == SIZE_MAX)
return ARES_EFORMERR;
@ -312,7 +313,7 @@ static const unsigned char *ares__buf_fetch(const ares__buf_t *buf, size_t *len)
}
int ares__buf_consume(ares__buf_t *buf, size_t len)
ares_status_t ares__buf_consume(ares__buf_t *buf, size_t len)
{
size_t remaining_len;
@ -326,7 +327,7 @@ int ares__buf_consume(ares__buf_t *buf, size_t len)
}
int ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16)
ares_status_t ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16)
{
size_t remaining_len;
const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
@ -340,8 +341,8 @@ int ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16)
}
int ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
size_t len)
ares_status_t ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
size_t len)
{
size_t remaining_len;
const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
@ -442,8 +443,8 @@ done:
}
int ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
size_t data_len)
ares_status_t ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
size_t data_len)
{
size_t remaining_len = 0;
const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);

@ -73,8 +73,8 @@ void ares__buf_destroy(ares__buf_t *buf);
* \param[in] data_len Length of data to copy to buffer object.
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_append(ares__buf_t *buf, const unsigned char *data,
size_t data_len);
ares_status_t ares__buf_append(ares__buf_t *buf, const unsigned char *data,
size_t data_len);
/*! Start a dynamic append operation that returns a buffer suitable for
@ -140,7 +140,7 @@ void ares__buf_tag(ares__buf_t *buf);
* \param[in] buf Initialized buffer object
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_tag_rollback(ares__buf_t *buf);
ares_status_t ares__buf_tag_rollback(ares__buf_t *buf);
/*! Clear the tagged position without rolling back. You should do this any
* time a tag is no longer needed as future append operations can reclaim
@ -149,7 +149,7 @@ int ares__buf_tag_rollback(ares__buf_t *buf);
* \param[in] buf Initialized buffer object
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_tag_clear(ares__buf_t *buf);
ares_status_t ares__buf_tag_clear(ares__buf_t *buf);
/*! Fetch the buffer and length of data starting from the tagged position up
* to the _current_ position. It will not unset the tagged position. The
@ -168,7 +168,7 @@ const unsigned char *ares__buf_tag_fetch(const ares__buf_t *buf, size_t *len);
* \param[in] len Length to consume
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_consume(ares__buf_t *buf, size_t len);
ares_status_t ares__buf_consume(ares__buf_t *buf, size_t len);
/*! Fetch a 16bit Big Endian number from the buffer.
*
@ -176,7 +176,7 @@ int ares__buf_consume(ares__buf_t *buf, size_t len);
* \param[out] u16 Buffer to hold 16bit integer
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16);
ares_status_t ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16);
/*! Fetch the requested number of bytes into the provided buffer
*
@ -185,8 +185,8 @@ int ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16);
* \param[in] len Requested number of bytes (must be > 0)
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
size_t len);
ares_status_t ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
size_t len);
/*! Consume whitespace characters (0x09, 0x0B, 0x0C, 0x0D, 0x20, and optionally
* 0x0A).
@ -224,8 +224,8 @@ size_t ares__buf_consume_line(ares__buf_t *buf, int include_linefeed);
* \param[in] data_len Length of data to compare.
* \return ARES_SUCCESS or one of the c-ares error codes
*/
int ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
size_t data_len);
ares_status_t ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
size_t data_len);
/*! Size of unprocessed remaining data length

@ -42,11 +42,11 @@
#include "ares_nowarn.h"
#include "ares_private.h"
int ares__get_hostent(FILE *fp, int family, struct hostent **host)
ares_status_t ares__get_hostent(FILE *fp, int family, struct hostent **host)
{
char *line = NULL, *p, *q, **alias;
char *txtaddr, *txthost, *txtalias;
int status;
ares_status_t status;
size_t addrlen, linesize, naliases;
struct ares_addr addr;
struct hostent *hostent = NULL;

@ -49,13 +49,14 @@
#include "ares_dns.h"
#include "ares_private.h"
int ares__parse_into_addrinfo(const unsigned char *abuf,
int alen, int cname_only_is_enodata,
unsigned short port,
struct ares_addrinfo *ai)
ares_status_t ares__parse_into_addrinfo(const unsigned char *abuf,
int alen, int cname_only_is_enodata,
unsigned short port,
struct ares_addrinfo *ai)
{
unsigned int qdcount, ancount;
int status, i, rr_type, rr_class, rr_len, rr_ttl;
ares_status_t status;
int i, rr_type, rr_class, rr_len, rr_ttl;
int got_a = 0, got_aaaa = 0, got_cname = 0;
long len;
const unsigned char *aptr;

@ -39,7 +39,7 @@
* appropriate. The initial value of *buf should be NULL. After the
* calling routine is done reading lines, it should free *buf.
*/
int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
ares_status_t ares__read_line(FILE *fp, char **buf, size_t *bufsize)
{
char *newbuf;
size_t offset = 0;

@ -43,17 +43,17 @@
#define MAX_ALIASES 40
int ares__readaddrinfo(FILE *fp,
const char *name,
unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai)
ares_status_t ares__readaddrinfo(FILE *fp,
const char *name,
unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai)
{
char *line = NULL, *p, *q;
char *txtaddr, *txthost, *txtalias;
char *aliases[MAX_ALIASES];
unsigned int i, alias_count;
int status = ARES_SUCCESS;
ares_status_t status = ARES_SUCCESS;
size_t linesize;
struct ares_addrinfo_cname *cname = NULL, *cnames = NULL;
struct ares_addrinfo_node *nodes = NULL;

@ -450,7 +450,8 @@ static int find_src_addr(ares_channel channel,
* Sort the linked list starting at sentinel->ai_next in RFC6724 order.
* Will leave the list unchanged if an error occurs.
*/
int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sentinel)
ares_status_t ares__sortaddrinfo(ares_channel channel,
struct ares_addrinfo_node *list_sentinel)
{
struct ares_addrinfo_node *cur;
int nelem = 0, i;

@ -126,10 +126,10 @@ static int is_hostnamech(int ch)
* and will return error.
*/
int ares__expand_name_validated(const unsigned char *encoded,
const unsigned char *abuf,
int alen, char **s, long *enclen,
int is_hostname)
ares_status_t ares__expand_name_validated(const unsigned char *encoded,
const unsigned char *abuf,
int alen, char **s, long *enclen,
int is_hostname)
{
int len, indir = 0;
char *q;
@ -310,12 +310,13 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
/* Like ares_expand_name_validated but returns EBADRESP in case of invalid
* input. */
int ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf, int alen,
char **s, long *enclen, int is_hostname)
ares_status_t ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf,
int alen, char **s, long *enclen,
int is_hostname)
{
int status = ares__expand_name_validated(encoded, abuf, alen, s, enclen,
is_hostname);
ares_status_t status = ares__expand_name_validated(encoded, abuf, alen, s,
enclen, is_hostname);
if (status == ARES_EBADNAME)
status = ARES_EBADRESP;
return status;

@ -298,7 +298,7 @@ static int fake_addrinfo(const char *name,
void *arg)
{
struct ares_addrinfo_cname *cname;
int status = ARES_SUCCESS;
ares_status_t status = ARES_SUCCESS;
int result = 0;
int family = hints->ai_family;
if (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC)
@ -385,7 +385,7 @@ static int fake_addrinfo(const char *name,
return 1;
}
static void end_hquery(struct host_query *hquery, int status)
static void end_hquery(struct host_query *hquery, ares_status_t status)
{
struct ares_addrinfo_node sentinel;
struct ares_addrinfo_node *next;
@ -440,11 +440,11 @@ static int is_localhost(const char *name)
return 0;
}
static int file_lookup(struct host_query *hquery)
static ares_status_t file_lookup(struct host_query *hquery)
{
FILE *fp;
int error;
int status;
ares_status_t status;
char *path_hosts = NULL;
if (hquery->hints.ai_flags & ARES_AI_ENVHOSTS)
@ -542,7 +542,7 @@ static int file_lookup(struct host_query *hquery)
return status;
}
static void next_lookup(struct host_query *hquery, int status)
static void next_lookup(struct host_query *hquery, ares_status_t status)
{
switch (*hquery->remaining_lookups)
{
@ -601,7 +601,7 @@ static void host_callback(void *arg, int status, int timeouts,
unsigned char *abuf, int alen)
{
struct host_query *hquery = (struct host_query*)arg;
int addinfostatus = ARES_SUCCESS;
ares_status_t addinfostatus = ARES_SUCCESS;
unsigned short qid = 0;
hquery->timeouts += timeouts;
hquery->remaining--;
@ -654,7 +654,7 @@ void ares_getaddrinfo(ares_channel channel,
int family;
struct ares_addrinfo *ai;
char *alias_name = NULL;
int status;
ares_status_t status;
if (!hints)
{
@ -776,7 +776,7 @@ static int next_dns_lookup(struct host_query *hquery)
{
char *s = NULL;
int is_s_allocated = 0;
int status;
ares_status_t status;
/* if next_domain == -1 and as_is_first is true, try hquery->name */
if (hquery->next_domain == -1)

@ -62,9 +62,9 @@ struct addr_query {
static void next_lookup(struct addr_query *aquery);
static void addr_callback(void *arg, int status, int timeouts,
unsigned char *abuf, int alen);
static void end_aquery(struct addr_query *aquery, int status,
static void end_aquery(struct addr_query *aquery, ares_status_t status,
struct hostent *host);
static int file_lookup(struct ares_addr *addr, struct hostent **host);
static ares_status_t file_lookup(struct ares_addr *addr, struct hostent **host);
static void ptr_rr_name(char *name, int name_size, const struct ares_addr *addr);
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
@ -109,7 +109,7 @@ static void next_lookup(struct addr_query *aquery)
{
const char *p;
char name[128];
int status;
ares_status_t status;
struct hostent *host;
for (p = aquery->remaining_lookups; *p; p++)
@ -169,7 +169,7 @@ static void addr_callback(void *arg, int status, int timeouts,
next_lookup(aquery);
}
static void end_aquery(struct addr_query *aquery, int status,
static void end_aquery(struct addr_query *aquery, ares_status_t status,
struct hostent *host)
{
aquery->callback(aquery->arg, status, aquery->timeouts, host);
@ -178,10 +178,10 @@ static void end_aquery(struct addr_query *aquery, int status,
ares_free(aquery);
}
static int file_lookup(struct ares_addr *addr, struct hostent **host)
static ares_status_t file_lookup(struct ares_addr *addr, struct hostent **host)
{
FILE *fp;
int status;
ares_status_t status;
int error;
#ifdef WIN32

@ -231,14 +231,15 @@ static int get6_address_index(const struct ares_in6_addr *addr,
static int file_lookup(const char *name, int family, struct hostent **host);
static ares_status_t file_lookup(const char *name, int family,
struct hostent **host);
/* I really have no idea why this is exposed as a public function, but since
* it is, we can't kill this legacy function. */
int ares_gethostbyname_file(ares_channel channel, const char *name,
int family, struct hostent **host)
{
int result;
ares_status_t result;
/* We only take the channel to ensure that ares_init() been called. */
if(channel == NULL)
@ -261,11 +262,12 @@ int ares_gethostbyname_file(ares_channel channel, const char *name,
return result;
}
static int file_lookup(const char *name, int family, struct hostent **host)
static ares_status_t file_lookup(const char *name, int family,
struct hostent **host)
{
FILE *fp;
char **alias;
int status;
ares_status_t status;
int error;
#ifdef WIN32

@ -72,33 +72,33 @@
#endif
static int init_by_options(ares_channel channel,
const struct ares_options *options,
int optmask);
static int init_by_environment(ares_channel channel);
static int init_by_resolv_conf(ares_channel channel);
static int init_by_defaults(ares_channel channel);
static ares_status_t init_by_options(ares_channel channel,
const struct ares_options *options,
int optmask);
static ares_status_t init_by_environment(ares_channel channel);
static ares_status_t init_by_resolv_conf(ares_channel channel);
static ares_status_t init_by_defaults(ares_channel channel);
#ifndef WATT32
static int config_nameserver(struct server_state **servers, int *nservers,
const char *str);
static ares_status_t config_nameserver(struct server_state **servers,
int *nservers, const char *str);
#endif
static int set_search(ares_channel channel, const char *str);
static int set_options(ares_channel channel, const char *str);
static ares_status_t set_search(ares_channel channel, const char *str);
static ares_status_t set_options(ares_channel channel, const char *str);
static const char *try_option(const char *p, const char *q, const char *opt);
static int config_sortlist(struct apattern **sortlist, int *nsort,
const char *str);
static ares_status_t config_sortlist(struct apattern **sortlist, int *nsort,
const char *str);
static int sortlist_alloc(struct apattern **sortlist, int *nsort,
struct apattern *pat);
static int ip_addr(const char *s, ares_ssize_t len, struct in_addr *addr);
static void natural_mask(struct apattern *pat);
#if !defined(WIN32) && !defined(WATT32) && \
!defined(ANDROID) && !defined(__ANDROID__) && !defined(CARES_USE_LIBRESOLV)
static int config_domain(ares_channel channel, char *str);
static int config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *altbindch,
const char *filech);
static ares_status_t config_domain(ares_channel channel, char *str);
static ares_status_t config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *altbindch,
const char *filech);
static char *try_config(char *s, const char *opt, char scc);
#endif
@ -135,7 +135,7 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
int optmask)
{
ares_channel channel;
int status = ARES_SUCCESS;
ares_status_t status = ARES_SUCCESS;
if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
@ -281,7 +281,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
struct ares_options opts;
struct ares_addr_port_node *servers;
int non_v4_default_port = 0;
int i, rc;
int i;
ares_status_t rc;
int optmask;
*dest = NULL; /* in case of failure return NULL explicitly */
@ -469,9 +470,9 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
return ARES_SUCCESS;
}
static int init_by_options(ares_channel channel,
const struct ares_options *options,
int optmask)
static ares_status_t init_by_options(ares_channel channel,
const struct ares_options *options,
int optmask)
{
int i;
@ -599,10 +600,10 @@ static int init_by_options(ares_channel channel,
return ARES_SUCCESS;
}
static int init_by_environment(ares_channel channel)
static ares_status_t init_by_environment(ares_channel channel)
{
const char *localdomain, *res_options;
int status;
ares_status_t status;
localdomain = getenv("LOCALDOMAIN");
if (localdomain && channel->ndomains == -1)
@ -1142,13 +1143,14 @@ static int get_SuffixList_Windows(char **outptr)
#endif
static int init_by_resolv_conf(ares_channel channel)
static ares_status_t init_by_resolv_conf(ares_channel channel)
{
#if !defined(ANDROID) && !defined(__ANDROID__) && !defined(WATT32) && \
!defined(CARES_USE_LIBRESOLV)
char *line = NULL;
#endif
int status = -1, nservers = 0, nsort = 0;
ares_status_t status = ARES_EOF;
int nservers = 0, nsort = 0;
struct server_state *servers = NULL;
struct apattern *sortlist = NULL;
@ -1603,10 +1605,10 @@ static int init_by_resolv_conf(ares_channel channel)
return ARES_SUCCESS;
}
static int init_by_defaults(ares_channel channel)
static ares_status_t init_by_defaults(ares_channel channel)
{
char *hostname = NULL;
int rc = ARES_SUCCESS;
ares_status_t rc = ARES_SUCCESS;
#ifdef HAVE_GETHOSTNAME
char *dot;
#endif
@ -1763,7 +1765,7 @@ static int init_by_defaults(ares_channel channel)
#if !defined(WIN32) && !defined(WATT32) && \
!defined(ANDROID) && !defined(__ANDROID__) && !defined(CARES_USE_LIBRESOLV)
static int config_domain(ares_channel channel, char *str)
static ares_status_t config_domain(ares_channel channel, char *str)
{
char *q;
@ -1783,9 +1785,9 @@ static int config_domain(ares_channel channel, char *str)
# define vqualifier
#endif
static int config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *altbindch,
const char *filech)
static ares_status_t config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *altbindch,
const char *filech)
{
char lookups[3], *l;
const char *vqualifier p;
@ -1897,8 +1899,9 @@ static int ares_ipv6_server_blacklisted(const unsigned char ipaddr[16])
*
* Returns an error code on failure, else ARES_SUCCESS
*/
static int parse_dnsaddrport(const char *str, size_t len,
struct ares_addr *host, unsigned short *port)
static ares_status_t parse_dnsaddrport(const char *str, size_t len,
struct ares_addr *host,
unsigned short *port)
{
char ipaddr[INET6_ADDRSTRLEN] = "";
char ipport[6] = "";
@ -1996,8 +1999,8 @@ static int parse_dnsaddrport(const char *str, size_t len,
*
* Returns an error code on failure, else ARES_SUCCESS.
*/
static int config_nameserver(struct server_state **servers, int *nservers,
const char *str)
static ares_status_t config_nameserver(struct server_state **servers,
int *nservers, const char *str)
{
struct ares_addr host;
struct server_state *newserv;
@ -2056,7 +2059,7 @@ static int config_nameserver(struct server_state **servers, int *nservers,
}
#endif /* !WATT32 */
static int config_sortlist(struct apattern **sortlist, int *nsort,
static ares_status_t config_sortlist(struct apattern **sortlist, int *nsort,
const char *str)
{
struct apattern pat;
@ -2150,7 +2153,7 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
return ARES_SUCCESS;
}
static int set_search(ares_channel channel, const char *str)
static ares_status_t set_search(ares_channel channel, const char *str)
{
size_t cnt;
@ -2172,7 +2175,7 @@ static int set_search(ares_channel channel, const char *str)
return ARES_SUCCESS;
}
static int set_options(ares_channel channel, const char *str)
static ares_status_t set_options(ares_channel channel, const char *str)
{
const char *p, *q, *val;
@ -2378,7 +2381,7 @@ int ares_set_sortlist(ares_channel channel, const char *sortstr)
{
int nsort = 0;
struct apattern *sortlist = NULL;
int status;
ares_status_t status;
if (!channel)
return ARES_ENODATA;
@ -2393,7 +2396,7 @@ int ares_set_sortlist(ares_channel channel, const char *sortstr)
return status;
}
int ares__init_servers_state(ares_channel channel)
ares_status_t ares__init_servers_state(ares_channel channel)
{
struct server_state *server;
int i;

@ -43,7 +43,7 @@ int ares_get_servers(ares_channel channel,
struct ares_addr_node *srvr_head = NULL;
struct ares_addr_node *srvr_last = NULL;
struct ares_addr_node *srvr_curr;
int status = ARES_SUCCESS;
ares_status_t status = ARES_SUCCESS;
int i;
if (!channel)
@ -98,7 +98,7 @@ int ares_get_servers_ports(ares_channel channel,
struct ares_addr_port_node *srvr_head = NULL;
struct ares_addr_port_node *srvr_last = NULL;
struct ares_addr_port_node *srvr_curr;
int status = ARES_SUCCESS;
ares_status_t status = ARES_SUCCESS;
int i;
if (!channel)
@ -257,15 +257,15 @@ int ares_set_servers_ports(ares_channel channel,
/* Incomming string format: host[:port][,host[:port]]... */
/* IPv6 addresses with ports require square brackets [fe80::1%lo0]:53 */
static int set_servers_csv(ares_channel channel,
const char* _csv, int use_port)
static ares_status_t set_servers_csv(ares_channel channel,
const char* _csv, int use_port)
{
size_t i;
char* csv = NULL;
char* ptr;
char* start_host;
int cc = 0;
int rv = ARES_SUCCESS;
ares_status_t rv = ARES_SUCCESS;
struct ares_addr_port_node *servers = NULL;
struct ares_addr_port_node *last = NULL;

@ -57,7 +57,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
{
struct ares_addrinfo ai;
char *question_hostname = NULL;
int status;
ares_status_t status;
int req_naddrttls = 0;
if (naddrttls)

@ -59,7 +59,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
{
struct ares_addrinfo ai;
char *question_hostname = NULL;
int status;
ares_status_t status;
int req_naddrttls = 0;
if (naddrttls)

@ -78,7 +78,8 @@ ares_parse_caa_reply (const unsigned char *abuf, int alen,
unsigned int qdcount, ancount, i;
const unsigned char *aptr;
const unsigned char *strptr;
int status, rr_type, rr_class, rr_len;
ares_status_t status;
int rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
struct ares_caa_reply *caa_head = NULL;

@ -50,7 +50,8 @@ ares_parse_mx_reply (const unsigned char *abuf, int alen,
{
unsigned int qdcount, ancount, i;
const unsigned char *aptr, *vptr;
int status, rr_type, rr_class, rr_len;
ares_status_t status;
int rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
struct ares_mx_reply *mx_head = NULL;

@ -49,7 +49,8 @@ ares_parse_naptr_reply (const unsigned char *abuf, int alen,
{
unsigned int qdcount, ancount, i;
const unsigned char *aptr, *vptr;
int status, rr_type, rr_class, rr_len;
ares_status_t status;
int rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
struct ares_naptr_reply *naptr_head = NULL;

@ -52,7 +52,8 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
struct hostent** host )
{
unsigned int qdcount, ancount;
int status, i, rr_type, rr_class, rr_len;
ares_status_t status;
int i, rr_type, rr_class, rr_len;
int nameservers_num;
long len;
const unsigned char *aptr;

@ -49,7 +49,8 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
int addrlen, int family, struct hostent **host)
{
unsigned int qdcount, ancount;
int status, i, rr_type, rr_class, rr_len;
ares_status_t status;
int i, rr_type, rr_class, rr_len;
long len;
const unsigned char *aptr;
char *ptrname, *hostname, *rr_name, *rr_data;

@ -53,7 +53,8 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
char *qname = NULL, *rr_name = NULL;
struct ares_soa_reply *soa = NULL;
int qdcount, ancount, qclass;
int status, i, rr_type, rr_class, rr_len;
ares_status_t status;
int i, rr_type, rr_class, rr_len;
if (alen < HFIXEDSZ)
return ARES_EBADRESP;

@ -50,7 +50,8 @@ ares_parse_srv_reply (const unsigned char *abuf, int alen,
{
unsigned int qdcount, ancount, i;
const unsigned char *aptr, *vptr;
int status, rr_type, rr_class, rr_len;
ares_status_t status;
int rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
struct ares_srv_reply *srv_head = NULL;

@ -56,7 +56,8 @@ ares__parse_txt_reply (const unsigned char *abuf, int alen,
unsigned int qdcount, ancount, i;
const unsigned char *aptr;
const unsigned char *strptr;
int status, rr_type, rr_class, rr_len;
ares_status_t status;
int rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
struct ares_txt_ext *txt_head = NULL;

@ -55,7 +55,8 @@ ares_parse_uri_reply (const unsigned char *abuf, int alen,
{
unsigned int qdcount, ancount, i;
const unsigned char *aptr, *vptr;
int status, rr_type, rr_class, rr_len, rr_ttl;
ares_status_t status;
int rr_type, rr_class, rr_len, rr_ttl;
long len;
char *uri_str = NULL, *rr_name = NULL;
struct ares_uri_reply *uri_head = NULL;

@ -227,7 +227,7 @@ struct query {
int server; /* Server this query has last been sent to. */
struct query_server_info *server_info; /* per-server state */
int using_tcp;
int error_status;
ares_status_t error_status;
int timeouts; /* number of timeouts we saw for this request */
int no_retries; /* do not perform any additional retries, this is set when
* a query is to be canceled */
@ -348,24 +348,24 @@ int ares__timedout(struct timeval *now,
struct timeval *check);
/* Returns one of the normal ares status codes like ARES_SUCCESS */
int ares__send_query(ares_channel channel, struct query *query,
struct timeval *now);
ares_status_t ares__send_query(ares_channel channel, struct query *query,
struct timeval *now);
/* Identical to ares_query, but returns a normal ares return code like
* ARES_SUCCESS, and can be passed the qid by reference which will be
* filled in on ARES_SUCCESS */
int ares_query_qid(ares_channel channel, const char *name,
int dnsclass, int type, ares_callback callback,
void *arg, unsigned short *qid);
ares_status_t ares_query_qid(ares_channel channel, const char *name,
int dnsclass, int type, ares_callback callback,
void *arg, unsigned short *qid);
/* Identical to ares_send() except returns normal ares return codes like
* ARES_SUCCESS */
int ares_send_ex(ares_channel channel, const unsigned char *qbuf, int qlen,
ares_callback callback, void *arg);
ares_status_t ares_send_ex(ares_channel channel, const unsigned char *qbuf,
int qlen, ares_callback callback, void *arg);
void ares__close_connection(struct server_connection *conn);
void ares__close_sockets(struct server_state *server);
void ares__check_cleanup_conn(ares_channel channel, ares_socket_t fd);
int ares__get_hostent(FILE *fp, int family, struct hostent **host);
int ares__read_line(FILE *fp, char **buf, size_t *bufsize);
ares_status_t ares__get_hostent(FILE *fp, int family, struct hostent **host);
ares_status_t ares__read_line(FILE *fp, char **buf, size_t *bufsize);
void ares__free_query(struct query *query);
ares_rand_state *ares__init_rand_state(void);
@ -374,22 +374,25 @@ void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t len);
unsigned short ares__generate_new_id(ares_rand_state *state);
struct timeval ares__tvnow(void);
int ares__expand_name_validated(const unsigned char *encoded,
const unsigned char *abuf,
int alen, char **s, long *enclen,
int is_hostname);
int ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf, int alen,
char **s, long *enclen, int is_hostname);
int ares__init_servers_state(ares_channel channel);
ares_status_t ares__expand_name_validated(const unsigned char *encoded,
const unsigned char *abuf,
int alen, char **s, long *enclen,
int is_hostname);
ares_status_t ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf,
int alen, char **s, long *enclen,
int is_hostname);
ares_status_t ares__init_servers_state(ares_channel channel);
void ares__destroy_servers_state(ares_channel channel);
int ares__parse_qtype_reply(const unsigned char* abuf, int alen, int* qtype);
int ares__single_domain(ares_channel channel, const char *name, char **s);
int ares__cat_domain(const char *name, const char *domain, char **s);
int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *ai_node);
int ares__readaddrinfo(FILE *fp, const char *name, unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai);
ares_status_t ares__single_domain(ares_channel channel, const char *name,
char **s);
ares_status_t ares__cat_domain(const char *name, const char *domain, char **s);
ares_status_t ares__sortaddrinfo(ares_channel channel,
struct ares_addrinfo_node *ai_node);
ares_status_t ares__readaddrinfo(FILE *fp, const char *name,
unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai);
void ares__freeaddrinfo_nodes(struct ares_addrinfo_node *ai_node);
@ -401,26 +404,28 @@ void ares__freeaddrinfo_cnames(struct ares_addrinfo_cname *ai_cname);
struct ares_addrinfo_cname *ares__append_addrinfo_cname(struct ares_addrinfo_cname **ai_cname);
int ares_append_ai_node(int aftype, unsigned short port, int ttl,
const void *adata,
struct ares_addrinfo_node **nodes);
ares_status_t ares_append_ai_node(int aftype, unsigned short port, int ttl,
const void *adata,
struct ares_addrinfo_node **nodes);
void ares__addrinfo_cat_cnames(struct ares_addrinfo_cname **head,
struct ares_addrinfo_cname *tail);
int ares__parse_into_addrinfo(const unsigned char *abuf,
int alen, int cname_only_is_enodata,
unsigned short port,
struct ares_addrinfo *ai);
int ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
struct hostent **host);
int ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
int req_naddrttls, struct ares_addrttl *addrttls,
struct ares_addr6ttl *addr6ttls, int *naddrttls);
int ares__addrinfo_localhost(const char *name, unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai);
ares_status_t ares__parse_into_addrinfo(const unsigned char *abuf,
int alen, int cname_only_is_enodata,
unsigned short port,
struct ares_addrinfo *ai);
ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
struct hostent **host);
ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
int req_naddrttls,
struct ares_addrttl *addrttls,
struct ares_addr6ttl *addr6ttls,
int *naddrttls);
ares_status_t ares__addrinfo_localhost(const char *name, unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai);
#if 0 /* Not used */
long ares__tvdiff(struct timeval t1, struct timeval t2);

@ -77,10 +77,10 @@ static void process_answer(ares_channel channel, const unsigned char *abuf,
static void handle_error(struct server_connection *conn, struct timeval *now);
static void skip_server(ares_channel channel, struct query *query,
struct server_state *server);
static int next_server(ares_channel channel, struct query *query,
struct timeval *now);
static int open_socket(ares_channel channel, struct server_state *server,
int is_tcp);
static ares_status_t next_server(ares_channel channel, struct query *query,
struct timeval *now);
static ares_status_t open_socket(ares_channel channel,
struct server_state *server, int is_tcp);
static int same_questions(const unsigned char *qbuf, int qlen,
const unsigned char *abuf, int alen);
static int same_address(struct sockaddr *sa, struct ares_addr *aa);
@ -725,10 +725,10 @@ static void skip_server(ares_channel channel, struct query *query,
}
}
static int next_server(ares_channel channel, struct query *query,
struct timeval *now)
static ares_status_t next_server(ares_channel channel, struct query *query,
struct timeval *now)
{
int status;
ares_status_t status;
/* We need to try each server channel->tries times. We have channel->nservers
* servers to try. In total, we need to do channel->nservers * channel->tries
* attempts. Use query->try to remember how many times we already attempted
@ -768,13 +768,13 @@ static int next_server(ares_channel channel, struct query *query,
return status;
}
int ares__send_query(ares_channel channel, struct query *query,
struct timeval *now)
ares_status_t ares__send_query(ares_channel channel, struct query *query,
struct timeval *now)
{
struct server_state *server;
struct server_connection *conn;
int timeplus;
int status;
ares_status_t status;
server = &channel->servers[query->server];
if (query->using_tcp) {
@ -783,8 +783,8 @@ int ares__send_query(ares_channel channel, struct query *query,
* a send request.
*/
if (server->tcp_conn == NULL) {
int err = open_socket(channel, server, 1);
switch (err) {
status = open_socket(channel, server, 1);
switch (status) {
/* Good result, continue on */
case ARES_SUCCESS:
break;
@ -798,8 +798,8 @@ int ares__send_query(ares_channel channel, struct query *query,
/* Anything else is not retryable, likely ENOMEM */
default:
end_query(channel, query, err, NULL, 0);
return err;
end_query(channel, query, status, NULL, 0);
return status;
}
}
@ -836,8 +836,8 @@ int ares__send_query(ares_channel channel, struct query *query,
}
if (node == NULL) {
int err = open_socket(channel, server, 0);
switch (err) {
status = open_socket(channel, server, 0);
switch (status) {
/* Good result, continue on */
case ARES_SUCCESS:
break;
@ -851,8 +851,8 @@ int ares__send_query(ares_channel channel, struct query *query,
/* Anything else is not retryable, likely ENOMEM */
default:
end_query(channel, query, err, NULL, 0);
return err;
end_query(channel, query, status, NULL, 0);
return status;
}
node = ares__llist_node_first(server->connections);
}
@ -1051,8 +1051,8 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
return 0;
}
static int open_socket(ares_channel channel, struct server_state *server,
int is_tcp)
static ares_status_t open_socket(ares_channel channel,
struct server_state *server, int is_tcp)
{
ares_socket_t s;
int opt;

@ -61,13 +61,14 @@ static unsigned short generate_unique_id(ares_channel channel)
return (unsigned short)id;
}
int ares_query_qid(ares_channel channel, const char *name,
int dnsclass, int type, ares_callback callback,
void *arg, unsigned short *qid)
ares_status_t ares_query_qid(ares_channel channel, const char *name,
int dnsclass, int type, ares_callback callback,
void *arg, unsigned short *qid)
{
struct qquery *qquery;
unsigned char *qbuf;
int qlen, rd, status;
int qlen, rd;
ares_status_t status;
unsigned short id = generate_unique_id(channel);
/* Compose the query. */

@ -61,7 +61,8 @@ void ares_search(ares_channel channel, const char *name, int dnsclass,
struct search_query *squery;
char *s;
const char *p;
int status, ndots;
ares_status_t status;
int ndots;
/* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
if (ares__is_onion_domain(name))
@ -222,7 +223,7 @@ static void end_squery(struct search_query *squery, int status,
}
/* Concatenate two domains. */
int ares__cat_domain(const char *name, const char *domain, char **s)
ares_status_t ares__cat_domain(const char *name, const char *domain, char **s)
{
size_t nlen = strlen(name);
size_t dlen = strlen(domain);
@ -246,13 +247,14 @@ int ares__cat_domain(const char *name, const char *domain, char **s)
* the string we should query, in an allocated buffer. If not, set *s
* to NULL.
*/
int ares__single_domain(ares_channel channel, const char *name, char **s)
ares_status_t ares__single_domain(ares_channel channel, const char *name,
char **s)
{
size_t len = strlen(name);
const char *hostaliases;
FILE *fp;
char *line = NULL;
int status;
ares_status_t status;
size_t linesize;
const char *p, *q;
int error;

@ -37,8 +37,8 @@
#include "ares_dns.h"
#include "ares_private.h"
int ares_send_ex(ares_channel channel, const unsigned char *qbuf, int qlen,
ares_callback callback, void *arg)
ares_status_t ares_send_ex(ares_channel channel, const unsigned char *qbuf,
int qlen, ares_callback callback, void *arg)
{
struct query *query;
int i, packetsz;

@ -31,37 +31,61 @@
const char *ares_strerror(int code)
{
/* Return a string literal from a table. */
const char *errtext[] = {
"Successful completion",
"DNS server returned answer with no data",
"DNS server claims query was misformatted",
"DNS server returned general failure",
"Domain name not found",
"DNS server does not implement requested operation",
"DNS server refused query",
"Misformatted DNS query",
"Misformatted domain name",
"Unsupported address family",
"Misformatted DNS reply",
"Could not contact DNS servers",
"Timeout while contacting DNS servers",
"End of file",
"Error reading file",
"Out of memory",
"Channel is being destroyed",
"Misformatted string",
"Illegal flags specified",
"Given hostname is not numeric",
"Illegal hints flags specified",
"c-ares library initialization not yet performed",
"Error loading iphlpapi.dll",
"Could not find GetNetworkParams function",
"DNS query cancelled"
};
ares_status_t status = code;
switch (status) {
case ARES_SUCCESS:
return "Successful completion";
case ARES_ENODATA:
return "DNS server returned answer with no data";
case ARES_EFORMERR:
return "DNS server claims query was misformatted";
case ARES_ESERVFAIL:
return "DNS server returned general failure";
case ARES_ENOTFOUND:
return "Domain name not found";
case ARES_ENOTIMP:
return "DNS server does not implement requested operation";
case ARES_EREFUSED:
return "DNS server refused query";
case ARES_EBADQUERY:
return "Misformatted DNS query";
case ARES_EBADNAME:
return "Misformatted domain name";
case ARES_EBADFAMILY:
return "Unsupported address family";
case ARES_EBADRESP:
return "Misformatted DNS reply";
case ARES_ECONNREFUSED:
return "Could not contact DNS servers";
case ARES_ETIMEOUT:
return "Timeout while contacting DNS servers";
case ARES_EOF:
return "End of file";
case ARES_EFILE:
return "Error reading file";
case ARES_ENOMEM:
return "Out of memory";
case ARES_EDESTRUCTION:
return "Channel is being destroyed";
case ARES_EBADSTR:
return "Misformatted string";
case ARES_EBADFLAGS:
return "Illegal flags specified";
case ARES_ENONAME:
return "Given hostname is not numeric";
case ARES_EBADHINTS:
return "Illegal hints flags specified";
case ARES_ENOTINITIALIZED:
return "c-ares library initialization not yet performed";
case ARES_ELOADIPHLPAPI:
return "Error loading iphlpapi.dll";
case ARES_EADDRGETNETWORKPARAMS:
return "Could not find GetNetworkParams function";
case ARES_ECANCELLED:
return "DNS query cancelled";
case ARES_ESERVICE:
return "Invalid service name or number";
}
if(code >= 0 && code < (int)(sizeof(errtext) / sizeof(*errtext)))
return errtext[code];
else
return "unknown";
return "unknown";
}

@ -558,7 +558,7 @@ TEST_F(LibraryTest, Striendstr) {
const char *str = "plugh";
EXPECT_NE(nullptr, ares_striendstr(str, str));
}
extern "C" int ares__single_domain(ares_channel, const char*, char**);
extern "C" ares_status_t ares__single_domain(ares_channel, const char*, char**);
TEST_F(DefaultChannelTest, SingleDomain) {
TempFile aliases("www www.google.com\n");
EnvValue with_env("HOSTALIASES", aliases.filename());

Loading…
Cancel
Save