clang-format

pull/595/head
Brad House 1 year ago
parent 699f469f18
commit 2cc2779fc9
  1. 21
      src/lib/ares__buf.c
  2. 6
      src/lib/ares__close_sockets.c
  3. 151
      src/lib/ares__hosts_file.c
  4. 3
      src/lib/ares__htable_strvp.c
  5. 5
      src/lib/ares__slist.c
  6. 1
      src/lib/ares__socket.c
  7. 3
      src/lib/ares__sortaddrinfo.c
  8. 5
      src/lib/ares_destroy.c
  9. 17
      src/lib/ares_getaddrinfo.c
  10. 9
      src/lib/ares_gethostbyaddr.c
  11. 6
      src/lib/ares_gethostbyname.c
  12. 28
      src/lib/ares_init.c
  13. 22
      src/lib/ares_options.c
  14. 17
      src/lib/ares_private.h
  15. 37
      src/lib/ares_process.c
  16. 61
      src/lib/ares_sysconfig.c
  17. 52
      src/lib/ares_sysconfig_files.c
  18. 121
      src/lib/ares_update_servers.c

@ -45,7 +45,6 @@ struct ares__buf {
* SIZE_MAX if not set. */
};
/* Reserved characters for names that need to be escaped */
static ares_bool_t is_reservedch(int ch)
{
@ -107,7 +106,6 @@ ares_bool_t ares__is_hostnamech(int ch)
return ARES_FALSE;
}
ares__buf_t *ares__buf_create(void)
{
ares__buf_t *buf = ares_malloc_zero(sizeof(*buf));
@ -389,8 +387,9 @@ const unsigned char *ares__buf_tag_fetch(const ares__buf_t *buf, size_t *len)
size_t ares__buf_tag_length(const ares__buf_t *buf)
{
if (buf == NULL || buf->tag_offset == SIZE_MAX)
if (buf == NULL || buf->tag_offset == SIZE_MAX) {
return 0;
}
return buf->offset - buf->tag_offset;
}
@ -400,11 +399,13 @@ ares_status_t ares__buf_tag_fetch_bytes(const ares__buf_t *buf,
size_t ptr_len = 0;
const unsigned char *ptr = ares__buf_tag_fetch(buf, &ptr_len);
if (ptr == NULL || bytes == NULL || len == NULL)
if (ptr == NULL || bytes == NULL || len == NULL) {
return ARES_EFORMERR;
}
if (*len < ptr_len)
if (*len < ptr_len) {
return ARES_EFORMERR;
}
*len = ptr_len;
@ -421,24 +422,27 @@ ares_status_t ares__buf_tag_fetch_string(const ares__buf_t *buf, char *str,
ares_status_t status;
size_t i;
if (str == NULL || len == 0)
if (str == NULL || len == 0) {
return ARES_EFORMERR;
}
/* Space for NULL terminator */
out_len = len - 1;
status = ares__buf_tag_fetch_bytes(buf, (unsigned char *)str, &out_len);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
/* NULL terminate */
str[out_len] = 0;
/* Validate string is printable */
for (i = 0; i < out_len; i++) {
if (!ares__isprint(str[i]))
if (!ares__isprint(str[i])) {
return ARES_EBADSTR;
}
}
return ARES_SUCCESS;
}
@ -573,7 +577,6 @@ ares_status_t ares__buf_fetch_bytes_into_buf(ares__buf_t *buf,
return ares__buf_consume(buf, len);
}
static ares_status_t ares__buf_fetch_dnsname_into_buf(ares__buf_t *buf,
ares__buf_t *dest,
size_t len,

@ -84,8 +84,9 @@ void ares__check_cleanup_conn(ares_channel channel,
{
ares_bool_t do_cleanup = ARES_FALSE;
if (channel == NULL || conn == NULL)
if (channel == NULL || conn == NULL) {
return;
}
if (ares__llist_len(conn->queries_to_conn)) {
return;
@ -102,8 +103,9 @@ void ares__check_cleanup_conn(ares_channel channel,
do_cleanup = ARES_TRUE;
}
if (!do_cleanup)
if (!do_cleanup) {
return;
}
ares__close_connection(conn);
}

@ -44,7 +44,6 @@
#include <time.h>
#include "ares_platform.h"
/* HOSTS FILE PROCESSING OVERVIEW
* ==============================
* The hosts file on the system contains static entries to be processed locally
@ -99,8 +98,8 @@ struct ares_hosts_entry {
ares__llist_t *hosts;
};
static ares_status_t ares__read_file_into_buf(const char *filename, ares__buf_t *buf)
static ares_status_t ares__read_file_into_buf(const char *filename,
ares__buf_t *buf)
{
FILE *fp = NULL;
unsigned char *ptr = NULL;
@ -108,8 +107,9 @@ static ares_status_t ares__read_file_into_buf(const char *filename, ares__buf_t
size_t ptr_len = 0;
ares_status_t status;
if (filename == NULL || buf == NULL)
if (filename == NULL || buf == NULL) {
return ARES_EFORMERR;
}
fp = fopen(filename, "rb");
if (fp == NULL) {
@ -162,8 +162,9 @@ static ares_status_t ares__read_file_into_buf(const char *filename, ares__buf_t
status = ARES_SUCCESS;
done:
if (fp != NULL)
if (fp != NULL) {
fclose(fp);
}
return status;
}
@ -171,22 +172,22 @@ static ares_bool_t ares__is_hostname(const char *str)
{
size_t i;
for (i = 0; str[i] != 0; i++) {
if (!ares__is_hostnamech(str[i]))
if (!ares__is_hostnamech(str[i])) {
return ARES_FALSE;
}
}
return ARES_TRUE;
}
static const void *ares__parse_ipaddr(const char *ipaddr,
struct ares_addr *addr,
size_t *out_len)
struct ares_addr *addr, size_t *out_len)
{
const void *ptr = NULL;
size_t ptr_len = 0;
if (ipaddr == NULL || addr == NULL || out_len == NULL)
if (ipaddr == NULL || addr == NULL || out_len == NULL) {
return NULL;
}
*out_len = 0;
@ -225,8 +226,9 @@ static ares_bool_t ares__normalize_ipaddr(const char *ipaddr, char *out,
data.family = AF_UNSPEC;
addr = ares__parse_ipaddr(ipaddr, &data, &addr_len);
if (addr == NULL)
if (addr == NULL) {
return ARES_FALSE;
}
if (!ares_inet_ntop(data.family, addr, out, (ares_socklen_t)out_len)) {
return ARES_FALSE;
@ -237,15 +239,18 @@ static ares_bool_t ares__normalize_ipaddr(const char *ipaddr, char *out,
static void ares__hosts_entry_destroy(ares_hosts_entry_t *entry)
{
if (entry == NULL)
if (entry == NULL) {
return;
}
/* Honor reference counting */
if (entry->refcnt != 0)
if (entry->refcnt != 0) {
entry->refcnt--;
}
if (entry->refcnt > 0)
if (entry->refcnt > 0) {
return;
}
ares__llist_destroy(entry->hosts);
ares__llist_destroy(entry->ips);
@ -259,8 +264,9 @@ static void ares__hosts_entry_destroy_cb(void *entry)
void ares__hosts_file_destroy(ares_hosts_file_t *hf)
{
if (hf == NULL)
if (hf == NULL) {
return;
}
ares_free(hf->filename);
ares__htable_strvp_destroy(hf->hosthash);
@ -299,38 +305,40 @@ fail:
return NULL;
}
static ares_bool_t ares__hosts_entry_ipaddr_exists(
ares_hosts_entry_t *entry, const char *ipaddr)
static ares_bool_t ares__hosts_entry_ipaddr_exists(ares_hosts_entry_t *entry,
const char *ipaddr)
{
ares__llist_node_t *node;
for (node = ares__llist_node_first(entry->ips); node != NULL;
node = ares__llist_node_next(node)) {
const char *myaddr = ares__llist_node_val(node);
if (strcmp(myaddr, ipaddr) == 0)
if (strcmp(myaddr, ipaddr) == 0) {
return ARES_TRUE;
}
}
return ARES_FALSE;
}
static ares_bool_t ares__hosts_entry_host_exists(
ares_hosts_entry_t *entry, const char *host)
static ares_bool_t ares__hosts_entry_host_exists(ares_hosts_entry_t *entry,
const char *host)
{
ares__llist_node_t *node;
for (node = ares__llist_node_first(entry->ips); node != NULL;
node = ares__llist_node_next(node)) {
const char *myhost = ares__llist_node_val(node);
if (strcasecmp(myhost, host) == 0)
if (strcasecmp(myhost, host) == 0) {
return ARES_TRUE;
}
}
return ARES_FALSE;
}
static ares_status_t ares__hosts_file_merge_entry(
ares_hosts_entry_t *existing, ares_hosts_entry_t *entry)
static ares_status_t ares__hosts_file_merge_entry(ares_hosts_entry_t *existing,
ares_hosts_entry_t *entry)
{
ares__llist_node_t *node;
@ -373,8 +381,8 @@ typedef enum {
ARES_MATCH_HOST = 2
} ares_hosts_file_match_t;
static ares_hosts_file_match_t ares__hosts_file_match(
const ares_hosts_file_t *hf, ares_hosts_entry_t *entry,
static ares_hosts_file_match_t
ares__hosts_file_match(const ares_hosts_file_t *hf, ares_hosts_entry_t *entry,
ares_hosts_entry_t **match)
{
ares__llist_node_t *node;
@ -384,17 +392,19 @@ static ares_hosts_file_match_t ares__hosts_file_match(
node = ares__llist_node_next(node)) {
const char *ipaddr = ares__llist_node_val(node);
*match = ares__htable_strvp_get_direct(hf->iphash, ipaddr);
if (*match != NULL)
if (*match != NULL) {
return ARES_MATCH_IPADDR;
}
}
for (node = ares__llist_node_first(entry->hosts); node != NULL;
node = ares__llist_node_next(node)) {
const char *host = ares__llist_node_val(node);
*match = ares__htable_strvp_get_direct(hf->hosthash, host);
if (*match != NULL)
if (*match != NULL) {
return ARES_MATCH_HOST;
}
}
return ARES_MATCH_NONE;
}
@ -438,8 +448,9 @@ static ares_status_t ares__hosts_file_add(ares_hosts_file_t *hosts,
/* first hostname match wins. If we detect a duplicate hostname for another
* ip it will automatically be added to the same entry */
if (ares__htable_strvp_get(hosts->hosthash, val, NULL))
if (ares__htable_strvp_get(hosts->hosthash, val, NULL)) {
continue;
}
if (!ares__htable_strvp_insert(hosts->hosthash, val, entry)) {
return ARES_ENOMEM;
@ -453,8 +464,9 @@ static ares_status_t ares__parse_hosts_hostnames(ares__buf_t *buf,
ares_hosts_entry_t *entry)
{
entry->hosts = ares__llist_create(ares_free);
if (entry->hosts == NULL)
if (entry->hosts == NULL) {
return ARES_ENOMEM;
}
/* Parse hostnames and aliases */
while (ares__buf_len(buf)) {
@ -465,8 +477,9 @@ static ares_status_t ares__parse_hosts_hostnames(ares__buf_t *buf,
ares__buf_consume_whitespace(buf, ARES_FALSE);
if (ares__buf_len(buf) == 0)
if (ares__buf_len(buf) == 0) {
break;
}
/* See if it is a comment, if so stop processing */
if (ares__buf_begins_with(buf, &comment, 1)) {
@ -476,31 +489,36 @@ static ares_status_t ares__parse_hosts_hostnames(ares__buf_t *buf,
ares__buf_tag(buf);
/* Must be at end of line */
if (ares__buf_consume_nonwhitespace(buf) == 0)
if (ares__buf_consume_nonwhitespace(buf) == 0) {
break;
}
status = ares__buf_tag_fetch_string(buf, hostname, sizeof(hostname));
if (status != ARES_SUCCESS) {
/* Bad entry, just ignore as long as its not the first. If its the first,
* it must be valid */
if (ares__llist_len(entry->hosts) == 0)
if (ares__llist_len(entry->hosts) == 0) {
return ARES_EBADSTR;
}
continue;
}
/* Validate it is a valid hostname characterset */
if (!ares__is_hostname(hostname))
if (!ares__is_hostname(hostname)) {
continue;
}
/* Don't add a duplicate to the same entry */
if (ares__hosts_entry_host_exists(entry, hostname))
if (ares__hosts_entry_host_exists(entry, hostname)) {
continue;
}
/* Add to list */
temp = ares_strdup(hostname);
if (temp == NULL)
if (temp == NULL) {
return ARES_ENOMEM;
}
if (ares__llist_insert_last(entry->hosts, temp) == NULL) {
ares_free(temp);
@ -509,13 +527,13 @@ static ares_status_t ares__parse_hosts_hostnames(ares__buf_t *buf,
}
/* Must have at least 1 entry */
if (ares__llist_len(entry->hosts) == 0)
if (ares__llist_len(entry->hosts) == 0) {
return ARES_EBADSTR;
}
return ARES_SUCCESS;
}
static ares_status_t ares__parse_hosts_ipaddr(ares__buf_t *buf,
ares_hosts_entry_t **entry_out)
{
@ -566,7 +584,6 @@ static ares_status_t ares__parse_hosts_ipaddr(ares__buf_t *buf,
return ARES_SUCCESS;
}
static ares_status_t ares__parse_hosts(const char *filename,
ares_hosts_file_t **out)
{
@ -584,8 +601,9 @@ static ares_status_t ares__parse_hosts(const char *filename,
}
status = ares__read_file_into_buf(filename, buf);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto done;
}
hf = ares__hosts_file_create(filename);
if (hf == NULL) {
@ -613,8 +631,9 @@ static ares_status_t ares__parse_hosts(const char *filename,
/* Pull off ip address */
status = ares__parse_hosts_ipaddr(buf, &entry);
if (status == ARES_ENOMEM)
if (status == ARES_ENOMEM) {
goto done;
}
if (status != ARES_SUCCESS) {
/* Bad line, consume and go onto next */
ares__buf_consume_line(buf, ARES_TRUE);
@ -657,7 +676,6 @@ done:
return status;
}
static ares_bool_t ares__hosts_expired(const char *filename,
const ares_hosts_file_t *hf)
{
@ -677,8 +695,9 @@ static ares_bool_t ares__hosts_expired(const char *filename,
(void)filename;
#endif
if (hf == NULL)
if (hf == NULL) {
return ARES_TRUE;
}
/* Expire every 60s if we can't get a time */
if (mod_ts == 0) {
@ -686,16 +705,17 @@ static ares_bool_t ares__hosts_expired(const char *filename,
}
/* If filenames are different, its expired */
if (strcasecmp(hf->filename, filename) != 0)
if (strcasecmp(hf->filename, filename) != 0) {
return ARES_TRUE;
}
if (hf->ts <= mod_ts)
if (hf->ts <= mod_ts) {
return ARES_TRUE;
}
return ARES_FALSE;
}
static ares_status_t ares__hosts_path(ares_channel channel, ares_bool_t use_env,
char **path)
{
@ -766,7 +786,6 @@ static ares_status_t ares__hosts_path(ares_channel channel, ares_bool_t use_env,
return ARES_SUCCESS;
}
static ares_status_t ares__hosts_update(ares_channel channel,
ares_bool_t use_env)
{
@ -774,8 +793,9 @@ static ares_status_t ares__hosts_update(ares_channel channel,
char *filename = NULL;
status = ares__hosts_path(channel, use_env, &filename);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
if (!ares__hosts_expired(filename, channel->hf)) {
ares_free(filename);
@ -800,25 +820,28 @@ ares_status_t ares__hosts_search_ipaddr(ares_channel channel,
*entry = NULL;
status = ares__hosts_update(channel, use_env);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
if (channel->hf == NULL)
if (channel->hf == NULL) {
return ARES_ENOTFOUND;
}
if (!ares__normalize_ipaddr(ipaddr, addr, sizeof(addr))) {
return ARES_EBADNAME;
}
*entry = ares__htable_strvp_get_direct(channel->hf->iphash, addr);
if (*entry == NULL)
if (*entry == NULL) {
return ARES_ENOTFOUND;
}
return ARES_SUCCESS;
}
ares_status_t ares__hosts_search_host(ares_channel channel,
ares_bool_t use_env, const char *host,
ares_status_t ares__hosts_search_host(ares_channel channel, ares_bool_t use_env,
const char *host,
const ares_hosts_entry_t **entry)
{
ares_status_t status;
@ -826,11 +849,13 @@ ares_status_t ares__hosts_search_host(ares_channel channel,
*entry = NULL;
status = ares__hosts_update(channel, use_env);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
if (channel->hf == NULL)
if (channel->hf == NULL) {
return ARES_ENOTFOUND;
}
*entry = ares__htable_strvp_get_direct(channel->hf->hosthash, host);
if (*entry == NULL) {
@ -841,8 +866,7 @@ ares_status_t ares__hosts_search_host(ares_channel channel,
}
ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
int family,
struct hostent **hostent)
int family, struct hostent **hostent)
{
ares_status_t status;
size_t naliases;
@ -871,8 +895,9 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
addr.family = family;
ptr = ares__parse_ipaddr(ipaddr, &addr, &ptr_len);
if (ptr == NULL)
if (ptr == NULL) {
continue;
}
/* If family == AF_UNSPEC, then we want to inherit this for future
* conversions as we can only support a single address class */
@ -917,8 +942,8 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
/* Copy aliases */
naliases = ares__llist_len(entry->hosts) - 1;
(*hostent)->h_aliases = ares_malloc_zero((naliases + 1) *
sizeof((*hostent)->h_aliases));
(*hostent)->h_aliases =
ares_malloc_zero((naliases + 1) * sizeof((*hostent)->h_aliases));
if ((*hostent)->h_aliases == NULL) {
status = ARES_ENOMEM;
goto fail;
@ -946,8 +971,9 @@ fail:
return status;
}
static ares_status_t ares__hosts_ai_append_cnames(
const ares_hosts_entry_t *entry, struct ares_addrinfo_cname **cnames_out)
static ares_status_t
ares__hosts_ai_append_cnames(const ares_hosts_entry_t *entry,
struct ares_addrinfo_cname **cnames_out)
{
struct ares_addrinfo_cname *cname = NULL;
struct ares_addrinfo_cname *cnames = NULL;
@ -1011,8 +1037,7 @@ done:
}
ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
const char *name,
int family,
const char *name, int family,
unsigned short port,
ares_bool_t want_cnames,
struct ares_addrinfo *ai)

@ -113,8 +113,7 @@ fail:
}
ares_bool_t ares__htable_strvp_insert(ares__htable_strvp_t *htable,
const char *key,
void *val)
const char *key, void *val)
{
ares__htable_strvp_bucket_t *bucket = NULL;

@ -304,13 +304,13 @@ void *ares__slist_node_claim(ares__slist_node_t *node)
return val;
}
void ares__slist_node_reinsert(ares__slist_node_t *node)
{
ares__slist_t *list;
if (node == NULL)
if (node == NULL) {
return;
}
list = node->parent;
@ -318,7 +318,6 @@ void ares__slist_node_reinsert(ares__slist_node_t *node)
ares__slist_node_push(list, node);
}
ares__slist_node_t *ares__slist_node_find(const ares__slist_t *list,
const void *val)
{

@ -450,4 +450,3 @@ void ares_set_socket_functions(ares_channel channel,
channel->sock_funcs = funcs;
channel->sock_func_cb_data = data;
}

@ -70,7 +70,8 @@ struct addrinfo_sort_elem {
#define ARES_IPV6_ADDR_SCOPE_ORGLOCAL 0x08
#define ARES_IPV6_ADDR_SCOPE_GLOBAL 0x0e
#define ARES_IN_LOOPBACK(a) ((((long unsigned int)(a)) & 0xff000000) == 0x7f000000)
#define ARES_IN_LOOPBACK(a) \
((((long unsigned int)(a)) & 0xff000000) == 0x7f000000)
/* RFC 4193. */
#define ARES_IN6_IS_ADDR_ULA(a) (((a)->s6_addr[0] & 0xfe) == 0xfc)

@ -32,7 +32,6 @@
#include "ares.h"
#include "ares_private.h"
void ares_destroy(ares_channel channel)
{
size_t i;
@ -93,11 +92,11 @@ void ares_destroy(ares_channel channel)
ares_free(channel);
}
void ares__destroy_server(struct server_state *server)
{
if (server == NULL)
if (server == NULL) {
return;
}
ares__close_sockets(server);
ares__llist_destroy(server->connections);

@ -108,8 +108,9 @@ struct ares_addrinfo_cname *
struct ares_addrinfo_cname *tail = ares_malloc_zero(sizeof(*tail));
struct ares_addrinfo_cname *last = *head;
if (tail == NULL)
if (tail == NULL) {
return NULL;
}
if (!last) {
*head = tail;
@ -147,8 +148,9 @@ struct ares_addrinfo_node *
struct ares_addrinfo_node *tail = ares_malloc_zero(sizeof(*tail));
struct ares_addrinfo_node *last = *head;
if (tail == NULL)
if (tail == NULL) {
return NULL;
}
if (!last) {
*head = tail;
@ -385,7 +387,8 @@ static ares_status_t file_lookup(struct host_query *hquery)
return ARES_ENOTFOUND;
}
status = ares__hosts_search_host(hquery->channel,
status = ares__hosts_search_host(
hquery->channel,
(hquery->hints.ai_flags & ARES_AI_ENVHOSTS) ? ARES_TRUE : ARES_FALSE,
hquery->name, &entry);
@ -393,9 +396,8 @@ static ares_status_t file_lookup(struct host_query *hquery)
goto done;
}
status = ares__hosts_entry_to_addrinfo(entry, hquery->name,
hquery->hints.ai_family,
hquery->port,
status = ares__hosts_entry_to_addrinfo(
entry, hquery->name, hquery->hints.ai_family, hquery->port,
(hquery->hints.ai_flags & ARES_AI_CANONNAME) ? ARES_TRUE : ARES_FALSE,
hquery->ai);
@ -451,7 +453,8 @@ static void next_lookup(struct host_query *hquery, ares_status_t status)
}
}
static void terminate_retries(const struct host_query *hquery, unsigned short qid)
static void terminate_retries(const struct host_query *hquery,
unsigned short qid)
{
unsigned short term_qid =
(qid == hquery->qid_a) ? hquery->qid_aaaa : hquery->qid_a;

@ -189,20 +189,23 @@ static ares_status_t file_lookup(ares_channel channel,
ptr = &addr->addr.addr6;
}
if (ptr == NULL)
if (ptr == NULL) {
return ARES_ENOTFOUND;
}
if (!ares_inet_ntop(addr->family, ptr, ipaddr, sizeof(ipaddr))) {
return ARES_ENOTFOUND;
}
status = ares__hosts_search_ipaddr(channel, ARES_FALSE, ipaddr, &entry);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
status = ares__hosts_entry_to_hostent(entry, addr->family, host);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
return ARES_SUCCESS;
}

@ -230,7 +230,6 @@ static size_t get6_address_index(const struct ares_in6_addr *addr,
return i;
}
static ares_status_t ares__hostent_localhost(const char *name, int family,
struct hostent **host_out)
{
@ -267,7 +266,6 @@ done:
int ares_gethostbyname_file(ares_channel channel, const char *name, int family,
struct hostent **host)
{
const ares_hosts_entry_t *entry;
ares_status_t status;
@ -275,8 +273,9 @@ int ares_gethostbyname_file(ares_channel channel, const char *name, int family,
if (channel == NULL || name == NULL || host == NULL) {
/* Anything will do, really. This seems fine, and is consistent with
other error cases. */
if (host != NULL)
if (host != NULL) {
*host = NULL;
}
return ARES_ENOTFOUND;
}
@ -308,4 +307,3 @@ done:
return (int)status;
}

@ -103,21 +103,26 @@ static int server_sort_cb(const void *data1, const void *data2)
const struct server_state *s1 = data1;
const struct server_state *s2 = data2;
if (s1->consec_failures < s2->consec_failures)
if (s1->consec_failures < s2->consec_failures) {
return -1;
if (s1->consec_failures > s2->consec_failures)
}
if (s1->consec_failures > s2->consec_failures) {
return 1;
if (s1->idx < s2->idx)
}
if (s1->idx < s2->idx) {
return -1;
if (s1->idx > s2->idx)
}
if (s1->idx > s2->idx) {
return 1;
}
return 0;
}
static void server_destroy_cb(void *data)
{
if (data == NULL)
if (data == NULL) {
return;
}
ares__destroy_server(data);
}
@ -153,15 +158,17 @@ static ares_status_t init_by_defaults(ares_channel channel)
addr.addr.addr4.s_addr = htonl(INADDR_LOOPBACK);
rc = ares__sconfig_append(&sconfig, &addr, 0, 0);
if (rc != ARES_SUCCESS)
if (rc != ARES_SUCCESS) {
return rc;
}
rc = ares__servers_update(channel, sconfig, ARES_FALSE);
ares__llist_destroy(sconfig);
if (rc != ARES_SUCCESS)
if (rc != ARES_SUCCESS) {
return rc;
}
}
#if defined(USE_WINSOCK)
# define toolong(x) (x == -1) && (SOCKERRNO == WSAEFAULT)
@ -303,8 +310,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
}
/* Initialize Server List */
channel->servers = ares__slist_create(channel->rand_state, server_sort_cb,
server_destroy_cb);
channel->servers =
ares__slist_create(channel->rand_state, server_sort_cb, server_destroy_cb);
if (channel->servers == NULL) {
status = ARES_ENOMEM;
goto done;
@ -449,7 +456,6 @@ int ares_dup(ares_channel *dest, ares_channel src)
return ARES_SUCCESS; /* everything went fine */
}
void ares_set_local_ip4(ares_channel channel, unsigned int local_ip)
{
channel->local_ip4 = local_ip;
@ -469,7 +475,6 @@ void ares_set_local_dev(ares_channel channel, const char *local_dev_name)
channel->local_dev_name[sizeof(channel->local_dev_name) - 1] = 0;
}
int ares_set_sortlist(ares_channel channel, const char *sortstr)
{
size_t nsort = 0;
@ -493,4 +498,3 @@ int ares_set_sortlist(ares_channel channel, const char *sortstr)
}
return (int)status;
}

@ -57,21 +57,22 @@ static struct in_addr *ares_save_opt_servers(ares_channel channel,
int *nservers)
{
ares__slist_node_t *snode;
struct in_addr *out = ares_malloc_zero(ares__slist_len(channel->servers) *
sizeof(*out));
struct in_addr *out =
ares_malloc_zero(ares__slist_len(channel->servers) * sizeof(*out));
*nservers = 0;
if (out == NULL)
if (out == NULL) {
return NULL;
}
for (snode = ares__slist_node_first(channel->servers); snode != NULL;
snode = ares__slist_node_next(snode)) {
const struct server_state *server = ares__slist_node_val(snode);
if (server->addr.family != AF_INET)
if (server->addr.family != AF_INET) {
continue;
}
memcpy(&out[*nservers], &server->addr.addr.addr4, sizeof(*out));
(*nservers)++;
@ -80,7 +81,6 @@ static struct in_addr *ares_save_opt_servers(ares_channel channel,
return out;
}
/* Save options from initialized channel */
int ares_save_options(ares_channel channel, struct ares_options *options,
int *optmask)
@ -222,7 +222,6 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
return ARES_SUCCESS;
}
static ares_status_t ares__init_options_servers(ares_channel channel,
const struct in_addr *servers,
size_t nservers)
@ -231,8 +230,9 @@ static ares_status_t ares__init_options_servers(ares_channel channel,
ares_status_t status;
slist = ares_in_addr_to_server_config_llist(servers, nservers);
if (slist == NULL)
if (slist == NULL) {
return ARES_ENOMEM;
}
status = ares__servers_update(channel, slist, ARES_TRUE);
@ -247,8 +247,9 @@ ares_status_t ares__init_by_options(ares_channel channel,
{
size_t i;
if (channel == NULL)
if (channel == NULL) {
return ARES_ENODATA;
}
if (options == NULL) {
if (optmask != 0) {
@ -377,9 +378,10 @@ ares_status_t ares__init_by_options(ares_channel channel,
ares_status_t status;
status = ares__init_options_servers(channel, options->servers,
(size_t)options->nservers);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
}
channel->optmask = (unsigned int)optmask;

@ -388,7 +388,6 @@ ares_status_t ares__init_by_options(ares_channel channel,
int optmask);
ares_status_t ares__init_by_sysconfig(ares_channel channel);
typedef struct {
ares__llist_t *sconfig;
struct apattern *sortlist;
@ -401,6 +400,7 @@ typedef struct {
ares_bool_t rotate;
size_t timeout_ms;
} ares_sysconfig_t;
ares_status_t ares__init_by_environment(ares_sysconfig_t *sysconfig);
ares_status_t ares__init_sysconfig_files(ares_channel channel,
@ -465,8 +465,7 @@ ares_ssize_t ares__socket_recv(ares_channel channel, ares_socket_t s,
void *data, size_t data_len);
void ares__close_socket(ares_channel, ares_socket_t);
int ares__connect_socket(ares_channel channel, ares_socket_t sockfd,
const struct sockaddr *addr,
ares_socklen_t addrlen);
const struct sockaddr *addr, ares_socklen_t addrlen);
ares_bool_t ares__is_hostnamech(int ch);
void ares__destroy_server(struct server_state *server);
@ -479,8 +478,9 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig,
unsigned short tcp_port);
ares_status_t ares__sconfig_append_fromstr(ares__llist_t **sconfig,
const char *str);
ares__llist_t *ares_in_addr_to_server_config_llist(
const struct in_addr *servers, size_t nservers);
ares__llist_t *
ares_in_addr_to_server_config_llist(const struct in_addr *servers,
size_t nservers);
struct ares_hosts_entry;
typedef struct ares_hosts_entry ares_hosts_entry_t;
@ -489,15 +489,14 @@ void ares__hosts_file_destroy(ares_hosts_file_t *hf);
ares_status_t ares__hosts_search_ipaddr(ares_channel channel,
ares_bool_t use_env, const char *ipaddr,
const ares_hosts_entry_t **entry);
ares_status_t ares__hosts_search_host(ares_channel channel,
ares_bool_t use_env, const char *host,
ares_status_t ares__hosts_search_host(ares_channel channel, ares_bool_t use_env,
const char *host,
const ares_hosts_entry_t **entry);
ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
int family,
struct hostent **hostent);
ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
const char *name,
int family,
const char *name, int family,
unsigned short port,
ares_bool_t want_cnames,
struct ares_addrinfo *ai);

@ -54,8 +54,7 @@ static void read_packets(ares_channel channel, fd_set *read_fds,
ares_socket_t read_fd, struct timeval *now);
static void process_timeouts(ares_channel channel, struct timeval *now);
static ares_status_t process_answer(ares_channel channel,
const unsigned char *abuf,
size_t alen,
const unsigned char *abuf, size_t alen,
struct server_connection *conn,
ares_bool_t tcp, struct timeval *now);
static void handle_conn_error(struct server_connection *conn,
@ -70,7 +69,6 @@ static void end_query(ares_channel channel, struct query *query,
ares_status_t status, const unsigned char *abuf,
size_t alen);
static void server_increment_failures(struct server_state *server)
{
ares__slist_node_t *node;
@ -84,14 +82,14 @@ static void server_increment_failures(struct server_state *server)
ares__slist_node_reinsert(node);
}
static void server_set_good(struct server_state *server)
{
ares__slist_node_t *node;
ares_channel channel = server->channel;
if (!server->consec_failures)
if (!server->consec_failures) {
return;
}
node = ares__slist_node_find(channel->servers, server);
if (node == NULL) {
@ -103,7 +101,8 @@ static void server_set_good(struct server_state *server)
}
/* return true if now is exactly check time or later */
ares_bool_t ares__timedout(const struct timeval *now, const struct timeval *check)
ares_bool_t ares__timedout(const struct timeval *now,
const struct timeval *check)
{
time_t secs = (now->tv_sec - check->tv_sec);
@ -178,13 +177,15 @@ static ares_bool_t try_again(int errnum)
#endif
#ifdef EWOULDBLOCK
if (errnum == EWOULDBLOCK)
if (errnum == EWOULDBLOCK) {
return ARES_TRUE;
}
#endif
#if defined EAGAIN && EAGAIN != EWOULDBLOCK
if (errnum == EAGAIN)
if (errnum == EAGAIN) {
return ARES_TRUE;
}
#endif
return ARES_FALSE;
@ -254,7 +255,6 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds,
}
}
/* If any TCP socket selects true for reading, read some data,
* allocate a buffer if we finish reading the length word, and process
* a packet if we finish reading one.
@ -373,8 +373,8 @@ static ares_socket_t *channel_socket_list(ares_channel channel, size_t *num)
struct server_state *server = ares__slist_node_val(snode);
ares__llist_node_t *node;
for (node = ares__llist_node_first(server->connections);
node != NULL; node = ares__llist_node_next(node)) {
for (node = ares__llist_node_first(server->connections); node != NULL;
node = ares__llist_node_next(node)) {
const struct server_connection *conn = ares__llist_node_val(node);
if (conn->fd == ARES_SOCKET_BAD) {
@ -559,8 +559,7 @@ static void process_timeouts(ares_channel channel, struct timeval *now)
* server connection! Return something other than ARES_SUCCESS to cause
* the connection to be terminated after this call. */
static ares_status_t process_answer(ares_channel channel,
const unsigned char *abuf,
size_t alen,
const unsigned char *abuf, size_t alen,
struct server_connection *conn,
ares_bool_t tcp, struct timeval *now)
{
@ -699,8 +698,7 @@ static void handle_conn_error(struct server_connection *conn,
ares_status_t ares__requeue_query(struct query *query, struct timeval *now)
{
ares_channel channel = query->channel;
size_t max_tries = ares__slist_len(channel->servers) *
channel->tries;
size_t max_tries = ares__slist_len(channel->servers) * channel->tries;
query->try_count++;
@ -709,14 +707,14 @@ ares_status_t ares__requeue_query(struct query *query, struct timeval *now)
}
/* If we are here, all attempts to perform query failed. */
if (query->error_status == ARES_SUCCESS)
if (query->error_status == ARES_SUCCESS) {
query->error_status = ARES_ETIMEOUT;
}
end_query(channel, query, query->error_status, NULL, 0);
return ARES_ETIMEOUT;
}
/* Pick a random server from the list, we first get a random number in the
* range of the number of servers, then scan until we find that server in
* the list */
@ -735,7 +733,6 @@ static struct server_state *ares__random_server(ares_channel channel)
cnt = 0;
for (node = ares__slist_node_first(channel->servers); node != NULL;
node = ares__slist_node_next(node)) {
if (cnt == idx) {
return ares__slist_node_val(node);
}
@ -932,8 +929,6 @@ ares_status_t ares__send_query(struct query *query, struct timeval *now)
return ARES_SUCCESS;
}
static ares_bool_t same_questions(const unsigned char *qbuf, size_t qlen,
const ares_dns_record_t *arec)
{
@ -1061,5 +1056,3 @@ void ares__free_query(struct query *query)
ares_free(query);
}

@ -586,7 +586,6 @@ static ares_bool_t get_SuffixList_Windows(char **outptr)
return *outptr != NULL ? ARES_TRUE : ARES_FALSE;
}
static ares_status_t ares__init_sysconfig_windows(ares_sysconfig_t *sysconfig)
{
char *line = NULL;
@ -595,18 +594,20 @@ static ares_status_t ares__init_sysconfig_windows(ares_sysconfig_t *sysconfig)
if (get_DNS_Windows(&line)) {
status = ares__sconfig_append_fromstr(&sysconfig->sconfig, line);
ares_free(line);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto done;
}
}
if (get_SuffixList_Windows(&line)) {
sysconfig->domains = ares__strsplit(line, ", ", &sysconfig->ndomains);
if (sysconfig->domains == NULL) {
status = ARES_EFILE;
}
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto done;
}
}
done:
return status;
@ -653,13 +654,14 @@ static ares_status_t ares__init_sysconfig_mvs(ares_sysconfig_t *sysconfig)
addr.addr.addr4.s_addr = addr_in->sin_addr.s_addr;
addr.family = AF_INET;
status = ares__sconfig_append(&sysconfig->sconfig, &addr,
htons(addr_in->sin_port),
status =
ares__sconfig_append(&sysconfig->sconfig, &addr, htons(addr_in->sin_port),
htons(addr_in->sin_port));
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
}
for (i = 0; i < count6; i++) {
struct sockaddr_in6 *addr_in = &(v6->__stat_nsaddr_list[i]);
@ -669,13 +671,14 @@ static ares_status_t ares__init_sysconfig_mvs(ares_sysconfig_t *sysconfig)
memcpy(&(addr.addr.addr6), &(addr_in->sin6_addr),
sizeof(addr_in->sin6_addr));
status = ares__sconfig_append(&sysconfig->sconfig, &addr,
htons(addr_in->sin_port),
status =
ares__sconfig_append(&sysconfig->sconfig, &addr, htons(addr_in->sin_port),
htons(addr_in->sin_port));
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
}
return ARES_SUCCESS;
}
@ -735,17 +738,18 @@ static ares_status_t ares__init_sysconfig_watt32(ares_sysconfig_t *sysconfig)
status = ares__sconfig_append(&sysconfig->sconfig, &addr, 0, 0);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
}
return ARES_SUCCESS;
}
#endif
#if defined(ANDROID) || defined(__ANDROID__)
static ares_status_t ares__init_sysconfig_android(ares_sysconfig_t *sysconfig)
size_t i;
static ares_status_t
ares__init_sysconfig_android(ares_sysconfig_t *sysconfig) size_t i;
char **dns_servers;
char *domains;
size_t num_servers;
@ -831,8 +835,7 @@ static ares_status_t ares__init_sysconfig_libresolv(ares_sysconfig_t *sysconfig)
ares_inet_ntop(family, &addr[i].sin.sin_addr, ipaddr, sizeof(ipaddr));
port = ntohs(addr[i].sin.sin_port);
} else if (family == AF_INET6) {
ares_inet_ntop(family, &addr[i].sin6.sin6_addr, ipaddr,
sizeof(ipaddr));
ares_inet_ntop(family, &addr[i].sin6.sin6_addr, ipaddr, sizeof(ipaddr));
port = ntohs(addr[i].sin6.sin6_port);
} else {
continue;
@ -887,7 +890,8 @@ static ares_status_t ares__init_sysconfig_libresolv(ares_sysconfig_t *sysconfig)
}
# ifdef __APPLE__
if (res.retry >= 0) {
sysconfig->timeout_ms /= ((unsigned int)res.retry + 1) *
sysconfig->timeout_ms /=
((unsigned int)res.retry + 1) *
(unsigned int)(res.nscount > 0 ? res.nscount : 1);
}
# endif
@ -915,26 +919,29 @@ static ares_status_t ares_sysconfig_apply(ares_channel channel,
if (sysconfig->sconfig && !(channel->optmask & ARES_OPT_SERVERS)) {
status = ares__servers_update(channel, sysconfig->sconfig, ARES_FALSE);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
return status;
}
}
if (sysconfig->domains && !(channel->optmask & ARES_OPT_DOMAINS)) {
size_t i;
ares__strsplit_free(channel->domains, channel->ndomains);
channel->domains = ares_malloc_zero(sizeof(*channel->domains) *
sysconfig->ndomains);
if (channel->domains == NULL)
channel->domains =
ares_malloc_zero(sizeof(*channel->domains) * sysconfig->ndomains);
if (channel->domains == NULL) {
return ARES_ENOMEM;
}
channel->ndomains = sysconfig->ndomains;
for (i = 0; i < channel->ndomains; i++) {
channel->domains[i] = ares_strdup(sysconfig->domains[i]);
if (channel->domains[i] == NULL)
if (channel->domains[i] == NULL) {
return ARES_ENOMEM;
}
}
}
if (sysconfig->lookups && !(channel->optmask & ARES_OPT_LOOKUPS)) {
ares_free(channel->lookups);
@ -946,13 +953,13 @@ static ares_status_t ares_sysconfig_apply(ares_channel channel,
if (sysconfig->sortlist && !(channel->optmask & ARES_OPT_SORTLIST)) {
ares_free(channel->sortlist);
channel->sortlist = ares_malloc(sizeof(*channel->sortlist) *
sysconfig->nsortlist);
channel->sortlist =
ares_malloc(sizeof(*channel->sortlist) * sysconfig->nsortlist);
if (channel->sortlist == NULL) {
return ARES_ENOMEM;
}
memcpy(channel->sortlist, sysconfig->sortlist, sizeof(*channel->sortlist) *
sysconfig->nsortlist);
memcpy(channel->sortlist, sysconfig->sortlist,
sizeof(*channel->sortlist) * sysconfig->nsortlist);
channel->nsort = sysconfig->nsortlist;
}
@ -983,8 +990,9 @@ ares_status_t ares__init_by_sysconfig(ares_channel channel)
memset(&sysconfig, 0, sizeof(sysconfig));
status = ares__init_by_environment(&sysconfig);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto done;
}
#ifdef _WIN32
status = ares__init_sysconfig_windows(&sysconfig);
@ -1007,8 +1015,9 @@ ares_status_t ares__init_by_sysconfig(ares_channel channel)
}
status = ares_sysconfig_apply(channel, &sysconfig);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto done;
}
done:
ares_sysconfig_free(&sysconfig);

@ -66,7 +66,6 @@
#include "ares_platform.h"
#include "ares_private.h"
static int ip_addr(const char *ipbuf, ares_ssize_t len, struct in_addr *addr)
{
/* Four octets and three periods yields at most 15 characters. */
@ -171,7 +170,8 @@ ares_status_t ares__parse_sortlist(struct apattern **sortlist, size_t *nsort,
/* Lets see if it is CIDR */
/* First we'll try IPv6 */
if ((bits = ares_inet_net_pton(AF_INET6, ipbufpfx[0] ? ipbufpfx : ipbuf,
&pat.addr.addr6, sizeof(pat.addr.addr6))) > 0) {
&pat.addr.addr6, sizeof(pat.addr.addr6))) >
0) {
pat.type = PATTERN_CIDR;
pat.mask.bits = (unsigned short)bits;
pat.family = AF_INET6;
@ -231,7 +231,6 @@ ares_status_t ares__parse_sortlist(struct apattern **sortlist, size_t *nsort,
return ARES_SUCCESS;
}
static ares_status_t config_search(ares_sysconfig_t *sysconfig, const char *str)
{
if (sysconfig->domains && sysconfig->ndomains > 0) {
@ -242,8 +241,9 @@ static ares_status_t config_search(ares_sysconfig_t *sysconfig, const char *str)
}
sysconfig->domains = ares__strsplit(str, ", ", &sysconfig->ndomains);
if (sysconfig->domains == NULL)
if (sysconfig->domains == NULL) {
return ARES_ENOMEM;
}
return ARES_SUCCESS;
}
@ -262,7 +262,6 @@ static ares_status_t config_domain(ares_sysconfig_t *sysconfig, char *str)
return config_search(sysconfig, str);
}
static ares_status_t config_lookup(ares_sysconfig_t *sysconfig, const char *str,
const char *bindch, const char *altbindch,
const char *filech)
@ -325,8 +324,9 @@ static ares_status_t set_options(ares_sysconfig_t *sysconfig, const char *str)
const char *q;
const char *val;
if (str == NULL)
if (str == NULL) {
return ARES_SUCCESS;
}
p = str;
while (*p) {
@ -446,7 +446,6 @@ static char *try_config(char *s, const char *opt, char scc)
return p;
}
ares_status_t ares__init_by_environment(ares_sysconfig_t *sysconfig)
{
const char *localdomain;
@ -456,8 +455,9 @@ ares_status_t ares__init_by_environment(ares_sysconfig_t *sysconfig)
localdomain = getenv("LOCALDOMAIN");
if (localdomain) {
char *temp = ares_strdup(localdomain);
if (temp == NULL)
if (temp == NULL) {
return ARES_ENOMEM;
}
status = config_domain(sysconfig, temp);
ares_free(temp);
if (status != ARES_SUCCESS) {
@ -476,7 +476,6 @@ ares_status_t ares__init_by_environment(ares_sysconfig_t *sysconfig)
return ARES_SUCCESS;
}
ares_status_t ares__init_sysconfig_files(ares_channel channel,
ares_sysconfig_t *sysconfig)
{
@ -507,7 +506,8 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
} else if ((p = try_config(line, "nameserver", ';'))) {
status = ares__sconfig_append_fromstr(&sysconfig->sconfig, p);
} else if ((p = try_config(line, "sortlist", ';'))) {
status = ares__parse_sortlist(&sysconfig->sortlist, &sysconfig->nsortlist, p);
status =
ares__parse_sortlist(&sysconfig->sortlist, &sysconfig->nsortlist, p);
} else if ((p = try_config(line, "options", ';'))) {
status = set_options(sysconfig, p);
} else {
@ -520,8 +520,9 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
}
fclose(fp);
if (status != ARES_EOF)
if (status != ARES_EOF) {
goto done;
}
} else {
error = ERRNO;
switch (error) {
@ -541,15 +542,15 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
/* Many systems (Solaris, Linux, BSD's) use nsswitch.conf */
fp = fopen("/etc/nsswitch.conf", "r");
if (fp) {
while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS) {
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) {
if ((p = try_config(line, "hosts:", '\0'))) {
(void)config_lookup(sysconfig, p, "dns", "resolve", "files");
}
}
fclose(fp);
if (status != ARES_EOF)
if (status != ARES_EOF) {
goto done;
}
} else {
error = ERRNO;
switch (error) {
@ -559,28 +560,27 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", error,
strerror(error)));
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
"/etc/nsswitch.conf"));
DEBUGF(
fprintf(stderr, "Error opening file: %s\n", "/etc/nsswitch.conf"));
break;
}
/* ignore error, maybe we will get luck in next if clause */
}
/* Linux / GNU libc 2.x and possibly others have host.conf */
fp = fopen("/etc/host.conf", "r");
if (fp) {
while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS) {
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) {
if ((p = try_config(line, "order", '\0'))) {
/* ignore errors */
(void)config_lookup(sysconfig, p, "bind", NULL, "hosts");
}
}
fclose(fp);
if (status != ARES_EOF)
if (status != ARES_EOF) {
goto done;
}
} else {
error = ERRNO;
switch (error) {
@ -590,8 +590,7 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", error,
strerror(error)));
DEBUGF(
fprintf(stderr, "Error opening file: %s\n", "/etc/host.conf"));
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/host.conf"));
break;
}
@ -602,16 +601,16 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
/* Tru64 uses /etc/svc.conf */
fp = fopen("/etc/svc.conf", "r");
if (fp) {
while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS) {
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) {
if ((p = try_config(line, "hosts=", '\0'))) {
/* ignore errors */
(void)config_lookup(sysconfig, p, "bind", NULL, "local");
}
}
fclose(fp);
if (status != ARES_EOF)
if (status != ARES_EOF) {
goto done;
}
} else {
error = ERRNO;
switch (error) {
@ -621,8 +620,7 @@ ares_status_t ares__init_sysconfig_files(ares_channel channel,
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", error,
strerror(error)));
DEBUGF(
fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf"));
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf"));
break;
}
/* ignore error */

@ -45,32 +45,32 @@ typedef struct {
static ares_bool_t ares__addr_match(const struct ares_addr *addr1,
const struct ares_addr *addr2)
{
if (addr1 == NULL && addr2 == NULL)
if (addr1 == NULL && addr2 == NULL) {
return ARES_TRUE;
}
if (addr1 == NULL || addr2 == NULL)
if (addr1 == NULL || addr2 == NULL) {
return ARES_FALSE;
}
if (addr1->family != addr2->family)
if (addr1->family != addr2->family) {
return ARES_FALSE;
}
if (addr1->family == AF_INET &&
memcmp(&addr1->addr.addr4, &addr2->addr.addr4, sizeof(addr1->addr.addr4))
== 0) {
if (addr1->family == AF_INET && memcmp(&addr1->addr.addr4, &addr2->addr.addr4,
sizeof(addr1->addr.addr4)) == 0) {
return ARES_TRUE;
}
if (addr1->family == AF_INET6 &&
memcmp(&addr1->addr.addr6._S6_un._S6_u8, &addr2->addr.addr6._S6_un._S6_u8,
sizeof(addr1->addr.addr6._S6_un._S6_u8))
== 0) {
sizeof(addr1->addr.addr6._S6_un._S6_u8)) == 0) {
return ARES_TRUE;
}
return ARES_FALSE;
}
/* Validate that the ip address matches the subnet (network base and network
* mask) specified. Addresses are specified in standard Network Byte Order as
* 16 bytes, and the netmask is 0 to 128 (bits).
@ -122,12 +122,14 @@ static ares_bool_t ares_server_blacklisted(const struct ares_addr *addr)
size_t i;
if (addr->family != AF_INET6)
if (addr->family != AF_INET6) {
return ARES_FALSE;
}
/* See if ipaddr matches any of the entries in the blacklist. */
for (i = 0; i < sizeof(blacklist_v6) / sizeof(*blacklist_v6); i++) {
if (ares_ipv6_subnet_matches(blacklist_v6[i].netbase, blacklist_v6[i].netmask,
if (ares_ipv6_subnet_matches(blacklist_v6[i].netbase,
blacklist_v6[i].netmask,
(const unsigned char *)&addr->addr.addr6)) {
return ARES_TRUE;
}
@ -229,7 +231,6 @@ static ares_status_t parse_dnsaddrport(const char *str, size_t len,
return ARES_SUCCESS;
}
ares_status_t ares__sconfig_append(ares__llist_t **sconfig,
const struct ares_addr *addr,
unsigned short udp_port,
@ -238,12 +239,14 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig,
ares_sconfig_t *s;
ares_status_t status;
if (sconfig == NULL || addr == NULL)
if (sconfig == NULL || addr == NULL) {
return ARES_EFORMERR;
}
/* Silently skip blacklisted IPv6 servers. */
if (ares_server_blacklisted(addr))
if (ares_server_blacklisted(addr)) {
return ARES_SUCCESS;
}
s = ares_malloc_zero(sizeof(*s));
if (s == NULL) {
@ -275,7 +278,6 @@ fail:
return status;
}
/* Add the IPv4 or IPv6 nameservers in str (separated by commas or spaces) to
* the servers list, updating servers and nservers as required.
*
@ -337,9 +339,6 @@ ares_status_t ares__sconfig_append_fromstr(ares__llist_t **sconfig,
return ARES_SUCCESS;
}
static unsigned short ares__sconfig_get_port(ares_channel channel,
const ares_sconfig_t *s,
ares_bool_t is_tcp)
@ -366,14 +365,17 @@ static ares__slist_node_t *ares__server_find(ares_channel channel,
node = ares__slist_node_next(node)) {
const struct server_state *server = ares__slist_node_val(node);
if (!ares__addr_match(&server->addr, &s->addr))
if (!ares__addr_match(&server->addr, &s->addr)) {
continue;
}
if (server->tcp_port != ares__sconfig_get_port(channel, s, ARES_TRUE))
if (server->tcp_port != ares__sconfig_get_port(channel, s, ARES_TRUE)) {
continue;
}
if (server->udp_port != ares__sconfig_get_port(channel, s, ARES_FALSE))
if (server->udp_port != ares__sconfig_get_port(channel, s, ARES_FALSE)) {
continue;
}
return node;
}
@ -389,19 +391,21 @@ static ares_bool_t ares__server_isdup(ares_channel channel,
for (prev = ares__llist_node_prev(s); prev != NULL;
prev = ares__llist_node_prev(prev)) {
const ares_sconfig_t *p = ares__llist_node_val(prev);
if (!ares__addr_match(&server->addr, &p->addr))
if (!ares__addr_match(&server->addr, &p->addr)) {
continue;
}
if (ares__sconfig_get_port(channel, server, ARES_TRUE) !=
ares__sconfig_get_port(channel, p, ARES_TRUE))
ares__sconfig_get_port(channel, p, ARES_TRUE)) {
continue;
}
if (ares__sconfig_get_port(channel, server, ARES_FALSE) !=
ares__sconfig_get_port(channel, p, ARES_FALSE))
ares__sconfig_get_port(channel, p, ARES_FALSE)) {
continue;
}
return ARES_TRUE;
}
@ -416,8 +420,9 @@ static ares_status_t ares__server_create(ares_channel channel,
ares_status_t status;
struct server_state *server = ares_malloc_zero(sizeof(*server));
if (server == NULL)
if (server == NULL) {
return ARES_ENOMEM;
}
server->idx = idx;
server->channel = channel;
@ -474,17 +479,19 @@ static ares_bool_t ares__server_in_newconfig(struct server_state *server,
for (node = ares__llist_node_first(srvlist); node != NULL;
node = ares__llist_node_next(node)) {
const ares_sconfig_t *s = ares__llist_node_val(node);
if (!ares__addr_match(&server->addr, &s->addr))
if (!ares__addr_match(&server->addr, &s->addr)) {
continue;
}
if (server->tcp_port != ares__sconfig_get_port(channel, s, ARES_TRUE))
if (server->tcp_port != ares__sconfig_get_port(channel, s, ARES_TRUE)) {
continue;
}
if (server->udp_port != ares__sconfig_get_port(channel, s, ARES_FALSE))
if (server->udp_port != ares__sconfig_get_port(channel, s, ARES_FALSE)) {
continue;
}
return ARES_TRUE;
}
@ -509,7 +516,6 @@ static void ares__servers_remove_stale(ares_channel channel,
}
}
static void ares__servers_trim_single(ares_channel channel)
{
while (ares__slist_len(channel->servers) > 1) {
@ -517,7 +523,6 @@ static void ares__servers_trim_single(ares_channel channel)
}
}
ares_status_t ares__servers_update(ares_channel channel,
ares__llist_t *server_list,
ares_bool_t user_specified)
@ -534,7 +539,6 @@ ares_status_t ares__servers_update(ares_channel channel,
/* Add new entries */
for (node = ares__llist_node_first(server_list); node != NULL;
node = ares__llist_node_next(node)) {
const ares_sconfig_t *sconfig = ares__llist_node_val(node);
ares__slist_node_t *snode;
@ -555,9 +559,10 @@ ares_status_t ares__servers_update(ares_channel channel,
}
} else {
status = ares__server_create(channel, sconfig, idx);
if (status != ARES_SUCCESS)
if (status != ARES_SUCCESS) {
goto done;
}
}
idx++;
}
@ -580,30 +585,33 @@ done:
return status;
}
static ares__llist_t *ares_addr_node_to_server_config_llist(
const struct ares_addr_node *servers)
static ares__llist_t *
ares_addr_node_to_server_config_llist(const struct ares_addr_node *servers)
{
const struct ares_addr_node *node;
ares__llist_t *s;
if (servers == NULL)
if (servers == NULL) {
return NULL;
}
s = ares__llist_create(ares_free);
if (s == NULL)
if (s == NULL) {
return NULL;
}
for (node = servers; node != NULL; node = node->next) {
ares_sconfig_t *sconfig;
/* Invalid entry */
if (node->family != AF_INET && node->family != AF_INET6)
if (node->family != AF_INET && node->family != AF_INET6) {
continue;
}
sconfig = ares_malloc_zero(sizeof(*sconfig));
if (sconfig == NULL)
if (sconfig == NULL) {
goto fail;
}
sconfig->addr.family = node->family;
if (node->family == AF_INET) {
@ -618,7 +626,6 @@ static ares__llist_t *ares_addr_node_to_server_config_llist(
ares_free(sconfig);
goto fail;
}
}
return s;
@ -634,23 +641,27 @@ static ares__llist_t *ares_addr_port_node_to_server_config_llist(
const struct ares_addr_port_node *node;
ares__llist_t *s;
if (servers == NULL)
if (servers == NULL) {
return NULL;
}
s = ares__llist_create(ares_free);
if (s == NULL)
if (s == NULL) {
return NULL;
}
for (node = servers; node != NULL; node = node->next) {
ares_sconfig_t *sconfig;
/* Invalid entry */
if (node->family != AF_INET && node->family != AF_INET6)
if (node->family != AF_INET && node->family != AF_INET6) {
continue;
}
sconfig = ares_malloc_zero(sizeof(*sconfig));
if (sconfig == NULL)
if (sconfig == NULL) {
goto fail;
}
sconfig->addr.family = node->family;
if (node->family == AF_INET) {
@ -677,26 +688,29 @@ fail:
return NULL;
}
ares__llist_t *ares_in_addr_to_server_config_llist(
const struct in_addr *servers, size_t nservers)
ares__llist_t *
ares_in_addr_to_server_config_llist(const struct in_addr *servers,
size_t nservers)
{
size_t i;
ares__llist_t *s;
if (servers == NULL || nservers == 0)
if (servers == NULL || nservers == 0) {
return NULL;
}
s = ares__llist_create(ares_free);
if (s == NULL)
if (s == NULL) {
return NULL;
}
for (i = 0; i < nservers; i++) {
ares_sconfig_t *sconfig;
sconfig = ares_malloc_zero(sizeof(*sconfig));
if (sconfig == NULL)
if (sconfig == NULL) {
goto fail;
}
sconfig->addr.family = AF_INET;
memcpy(&sconfig->addr.addr.addr4, &servers[i],
@ -818,7 +832,6 @@ int ares_get_servers_ports(ares_channel channel,
return (int)status;
}
int ares_set_servers(ares_channel channel, struct ares_addr_node *servers)
{
ares__llist_t *slist;
@ -840,7 +853,6 @@ int ares_set_servers(ares_channel channel, struct ares_addr_node *servers)
return (int)status;
}
int ares_set_servers_ports(ares_channel channel,
struct ares_addr_port_node *servers)
{
@ -863,7 +875,6 @@ int ares_set_servers_ports(ares_channel channel,
return (int)status;
}
/* Incomming string format: host[:port][,host[:port]]... */
/* IPv6 addresses with ports require square brackets [fe80::1]:53 */
static ares_status_t set_servers_csv(ares_channel channel, const char *_csv,

Loading…
Cancel
Save