sonarcloud: fix more codesmells (#583)

pull/584/head
Brad House 1 year ago committed by GitHub
parent ceb85775e1
commit a26dfd0123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 94
      src/lib/ares__buf.c
  2. 6
      src/lib/ares__buf.h
  3. 10
      src/lib/ares__htable.c
  4. 2
      src/lib/ares__htable.h
  5. 2
      src/lib/ares__htable_asvp.c
  6. 2
      src/lib/ares__htable_asvp.h
  7. 2
      src/lib/ares__htable_stvp.c
  8. 2
      src/lib/ares__htable_stvp.h
  9. 2
      src/lib/ares__llist.c
  10. 2
      src/lib/ares__llist.h
  11. 4
      src/lib/ares__readaddrinfo.c
  12. 15
      src/lib/ares__slist.c
  13. 13
      src/lib/ares__slist.h
  14. 2
      src/lib/ares_dns_mapping.c
  15. 2
      src/lib/ares_dns_parse.c
  16. 88
      src/lib/ares_dns_record.c
  17. 81
      src/lib/ares_dns_record.h
  18. 4
      src/lib/ares_math.c
  19. 15
      src/lib/ares_parse_ptr_reply.c
  20. 20
      src/lib/inet_net_pton.c
  21. 20
      src/tools/adig.c
  22. 4
      src/tools/ares_getopt.c

@ -251,11 +251,11 @@ unsigned char *ares__buf_finish_bin(ares__buf_t *buf, size_t *len)
}
ares__buf_reclaim(buf);
if (buf->alloc_buf == NULL) {
/* We don't want to return NULL except on failure, may be zero-length */
if (ares__buf_ensure_space(buf, 1) != ARES_SUCCESS) {
return NULL;
}
/* We don't want to return NULL except on failure, may be zero-length */
if (buf->alloc_buf == NULL &&
ares__buf_ensure_space(buf, 1) != ARES_SUCCESS) {
return NULL;
}
ptr = buf->alloc_buf;
*len = buf->data_len;
@ -376,9 +376,8 @@ ares_status_t ares__buf_fetch_be32(ares__buf_t *buf, unsigned int *u32)
return ARES_EBADRESP;
}
*u32 =
(unsigned int)((unsigned int)(ptr[0]) << 24 | (unsigned int)(ptr[1]) << 16 |
(unsigned int)(ptr[2]) << 8 | (unsigned int)(ptr[3]));
*u32 = ((unsigned int)(ptr[0]) << 24 | (unsigned int)(ptr[1]) << 16 |
(unsigned int)(ptr[2]) << 8 | (unsigned int)(ptr[3]));
return ares__buf_consume(buf, sizeof(*u32));
}
@ -541,38 +540,40 @@ static ares_status_t ares__buf_fetch_dnsname_into_buf(ares__buf_t *buf,
}
/* NOTE: dest may be NULL if the user is trying to skip the name. validation
* still occurs */
if (dest) {
/* Non-printable characters need to be output as \DDD */
if (!ares__isprint(c)) {
unsigned char escape[4];
escape[0] = '\\';
escape[1] = '0' + (c / 100);
escape[2] = '0' + ((c % 100) / 10);
escape[3] = '0' + (c % 10);
status = ares__buf_append(dest, escape, sizeof(escape));
if (status != ARES_SUCCESS) {
goto fail;
}
* still occurs above. */
if (dest == NULL) {
continue;
}
continue;
}
/* Non-printable characters need to be output as \DDD */
if (!ares__isprint(c)) {
unsigned char escape[4];
/* Reserved characters need to be escaped, otherwise normal */
if (is_reservedch(c)) {
status = ares__buf_append_byte(dest, '\\');
if (status != ARES_SUCCESS) {
goto fail;
}
escape[0] = '\\';
escape[1] = '0' + (c / 100);
escape[2] = '0' + ((c % 100) / 10);
escape[3] = '0' + (c % 10);
status = ares__buf_append(dest, escape, sizeof(escape));
if (status != ARES_SUCCESS) {
goto fail;
}
status = ares__buf_append_byte(dest, c);
continue;
}
/* Reserved characters need to be escaped, otherwise normal */
if (is_reservedch(c)) {
status = ares__buf_append_byte(dest, '\\');
if (status != ARES_SUCCESS) {
return status;
goto fail;
}
}
status = ares__buf_append_byte(dest, c);
if (status != ARES_SUCCESS) {
return status;
}
}
return ares__buf_consume(buf, len);
@ -658,26 +659,23 @@ size_t ares__buf_consume_line(ares__buf_t *buf, int include_linefeed)
}
for (i = 0; i < remaining_len; i++) {
switch (ptr[i]) {
case '\n':
if (include_linefeed) {
i++;
}
goto done;
default:
break;
if (ptr[i] == '\n') {
goto done;
}
}
done:
if (include_linefeed && i > 0 && i < remaining_len && ptr[i] == '\n') {
i++;
}
if (i > 0) {
ares__buf_consume(buf, i);
}
return i;
}
ares_status_t ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
size_t data_len)
ares_status_t ares__buf_begins_with(const 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);
@ -847,12 +845,10 @@ ares_status_t ares__buf_parse_dns_name(ares__buf_t *buf, char **name,
/* New label */
/* Labels are separated by periods */
if (ares__buf_len(namebuf) != 0) {
if (name != NULL) {
status = ares__buf_append_byte(namebuf, '.');
if (status != ARES_SUCCESS) {
goto fail;
}
if (ares__buf_len(namebuf) != 0 && name != NULL) {
status = ares__buf_append_byte(namebuf, '.');
if (status != ARES_SUCCESS) {
goto fail;
}
}

@ -281,8 +281,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
*/
ares_status_t ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
size_t data_len);
ares_status_t ares__buf_begins_with(const ares__buf_t *buf,
const unsigned char *data, size_t data_len);
/*! Size of unprocessed remaining data length
@ -290,7 +290,7 @@ ares_status_t ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
* \param[in] buf Initialized buffer object
* \return length remaining
*/
size_t ares__buf_len(const ares__buf_t *buf);
size_t ares__buf_len(const ares__buf_t *buf);
/*! Retrieve a pointer to the currently unprocessed data. Generally this isn't
* recommended to be used in practice. The returned pointer may be invalidated

@ -140,7 +140,7 @@ fail:
* efficient */
#define HASH_IDX(h, key) h->hash(key, h->seed) & (h->size - 1)
static ares__llist_node_t *ares__htable_find(ares__htable_t *htable,
static ares__llist_node_t *ares__htable_find(const ares__htable_t *htable,
unsigned int idx, const void *key)
{
ares__llist_node_t *node = NULL;
@ -186,9 +186,9 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable)
if (buckets[idx] == NULL) {
buckets[idx] = ares__llist_create(htable->bucket_free);
if (buckets[idx] == NULL) {
goto fail;
}
}
if (buckets[idx] == NULL) {
goto fail;
}
if (ares__llist_insert_first(buckets[idx], val) == NULL) {
@ -292,7 +292,7 @@ ares_bool_t ares__htable_remove(ares__htable_t *htable, const void *key)
return ARES_TRUE;
}
size_t ares__htable_num_keys(ares__htable_t *htable)
size_t ares__htable_num_keys(const ares__htable_t *htable)
{
if (htable == NULL) {
return 0;

@ -108,7 +108,7 @@ ares__htable_t *ares__htable_create(ares__htable_hashfunc_t hash_func,
* \param[in] htable Initialized hashtable.
* \return count of keys
*/
size_t ares__htable_num_keys(ares__htable_t *htable);
size_t ares__htable_num_keys(const ares__htable_t *htable);
/*! Insert bucket into hashtable
*

@ -185,7 +185,7 @@ ares_bool_t ares__htable_asvp_remove(ares__htable_asvp_t *htable,
return ares__htable_remove(htable->hash, &key);
}
size_t ares__htable_asvp_num_keys(ares__htable_asvp_t *htable)
size_t ares__htable_asvp_num_keys(const ares__htable_asvp_t *htable)
{
if (htable == NULL) {
return 0;

@ -113,7 +113,7 @@ ares_bool_t ares__htable_asvp_remove(ares__htable_asvp_t *htable,
* \param[in] htable Initialized hash table
* \return count
*/
size_t ares__htable_asvp_num_keys(ares__htable_asvp_t *htable);
size_t ares__htable_asvp_num_keys(const ares__htable_asvp_t *htable);
/*! @} */

@ -183,7 +183,7 @@ ares_bool_t ares__htable_stvp_remove(ares__htable_stvp_t *htable, size_t key)
return ares__htable_remove(htable->hash, &key);
}
size_t ares__htable_stvp_num_keys(ares__htable_stvp_t *htable)
size_t ares__htable_stvp_num_keys(const ares__htable_stvp_t *htable)
{
if (htable == NULL) {
return 0;

@ -109,7 +109,7 @@ ares_bool_t ares__htable_stvp_remove(ares__htable_stvp_t *htable, size_t key);
* \param[in] htable Initialized hash table
* \return count
*/
size_t ares__htable_stvp_num_keys(ares__htable_stvp_t *htable);
size_t ares__htable_stvp_num_keys(const ares__htable_stvp_t *htable);
/*! @} */

@ -207,7 +207,7 @@ void *ares__llist_node_val(ares__llist_node_t *node)
return node->data;
}
size_t ares__llist_len(ares__llist_t *list)
size_t ares__llist_len(const ares__llist_t *list)
{
if (list == NULL) {
return 0;

@ -148,7 +148,7 @@ void *ares__llist_node_val(ares__llist_node_t *node);
* \param[in] list Initialized list object
* \return count
*/
size_t ares__llist_len(ares__llist_t *list);
size_t ares__llist_len(const ares__llist_t *list);
/*! Obtain list object from referenced node
*

@ -58,9 +58,9 @@ ares_status_t ares__readaddrinfo(FILE *fp, const char *name,
size_t alias_count;
ares_status_t status = ARES_SUCCESS;
size_t linesize;
struct ares_addrinfo_cname *cname = NULL;
struct ares_addrinfo_cname *cname = NULL;
struct ares_addrinfo_cname *cnames = NULL;
struct ares_addrinfo_node *nodes = NULL;
struct ares_addrinfo_node *nodes = NULL;
ares_bool_t match_with_alias;
ares_bool_t match_with_canonical;
ares_bool_t want_cname =

@ -115,7 +115,7 @@ void ares__slist_replace_destructor(ares__slist_t *list,
list->destruct = destruct;
}
static size_t ares__slist_max_level(ares__slist_t *list)
static size_t ares__slist_max_level(const ares__slist_t *list)
{
size_t max_level = 0;
@ -250,7 +250,8 @@ fail:
return NULL;
}
ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val)
ares__slist_node_t *ares__slist_node_find(const ares__slist_t *list,
const void *val)
{
size_t i;
ares__slist_node_t *node = NULL;
@ -309,7 +310,7 @@ ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val)
return node;
}
ares__slist_node_t *ares__slist_node_first(ares__slist_t *list)
ares__slist_node_t *ares__slist_node_first(const ares__slist_t *list)
{
if (list == NULL) {
return NULL;
@ -318,7 +319,7 @@ ares__slist_node_t *ares__slist_node_first(ares__slist_t *list)
return list->head[0];
}
ares__slist_node_t *ares__slist_node_last(ares__slist_t *list)
ares__slist_node_t *ares__slist_node_last(const ares__slist_t *list)
{
if (list == NULL) {
return NULL;
@ -326,7 +327,7 @@ ares__slist_node_t *ares__slist_node_last(ares__slist_t *list)
return list->tail;
}
ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node)
ares__slist_node_t *ares__slist_node_next(const ares__slist_node_t *node)
{
if (node == NULL) {
return NULL;
@ -334,7 +335,7 @@ ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node)
return node->next[0];
}
ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node)
ares__slist_node_t *ares__slist_node_prev(const ares__slist_node_t *node)
{
if (node == NULL) {
return NULL;
@ -351,7 +352,7 @@ void *ares__slist_node_val(ares__slist_node_t *node)
return node->data;
}
size_t ares__slist_len(ares__slist_t *list)
size_t ares__slist_len(const ares__slist_t *list)
{
if (list == NULL) {
return 0;

@ -106,28 +106,28 @@ ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val);
* \param[in] list Initialized SkipList Object
* \return SkipList Node Object or NULL if none
*/
ares__slist_node_t *ares__slist_node_first(ares__slist_t *list);
ares__slist_node_t *ares__slist_node_first(const ares__slist_t *list);
/*! Fetch last node in SkipList
*
* \param[in] list Initialized SkipList Object
* \return SkipList Node Object or NULL if none
*/
ares__slist_node_t *ares__slist_node_last(ares__slist_t *list);
ares__slist_node_t *ares__slist_node_last(const ares__slist_t *list);
/*! Fetch next node in SkipList
*
* \param[in] node SkipList Node Object
* \return SkipList Node Object or NULL if none
*/
ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node);
ares__slist_node_t *ares__slist_node_next(const ares__slist_node_t *node);
/*! Fetch previous node in SkipList
*
* \param[in] node SkipList Node Object
* \return SkipList Node Object or NULL if none
*/
ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node);
ares__slist_node_t *ares__slist_node_prev(const ares__slist_node_t *node);
/*! Fetch SkipList Node Object by Value
*
@ -135,7 +135,8 @@ ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node);
* \param[in] val Object to use for comparison
* \return SkipList Node Object or NULL if not found
*/
ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val);
ares__slist_node_t *ares__slist_node_find(const ares__slist_t *list,
const void *val);
/*! Fetch Node Value
@ -150,7 +151,7 @@ void *ares__slist_node_val(ares__slist_node_t *node);
* \param[in] list Initialized SkipList Object
* \return number of entries
*/
size_t ares__slist_len(ares__slist_t *list);
size_t ares__slist_len(const ares__slist_t *list);
/*! Fetch SkipList Object from SkipList Node
*

@ -66,7 +66,7 @@ ares_bool_t ares_dns_flags_arevalid(unsigned short flags)
ARES_FLAG_RD | ARES_FLAG_RA | ARES_FLAG_AD |
ARES_FLAG_CD;
if (flags & ~(allflags)) {
if (flags & ~allflags) {
return ARES_FALSE;
}

@ -32,7 +32,7 @@
# include <stdint.h>
#endif
static size_t ares_dns_rr_remaining_len(ares__buf_t *buf, size_t orig_len,
static size_t ares_dns_rr_remaining_len(const ares__buf_t *buf, size_t orig_len,
size_t rdlength)
{
size_t used_len = orig_len - ares__buf_len(buf);

@ -61,7 +61,7 @@ ares_status_t ares_dns_record_create(ares_dns_record_t **dnsrec,
return ARES_SUCCESS;
}
unsigned short ares_dns_record_get_id(ares_dns_record_t *dnsrec)
unsigned short ares_dns_record_get_id(const ares_dns_record_t *dnsrec)
{
if (dnsrec == NULL) {
return 0;
@ -69,7 +69,7 @@ unsigned short ares_dns_record_get_id(ares_dns_record_t *dnsrec)
return dnsrec->id;
}
unsigned short ares_dns_record_get_flags(ares_dns_record_t *dnsrec)
unsigned short ares_dns_record_get_flags(const ares_dns_record_t *dnsrec)
{
if (dnsrec == NULL) {
return 0;
@ -77,7 +77,7 @@ unsigned short ares_dns_record_get_flags(ares_dns_record_t *dnsrec)
return dnsrec->flags;
}
ares_dns_opcode_t ares_dns_record_get_opcode(ares_dns_record_t *dnsrec)
ares_dns_opcode_t ares_dns_record_get_opcode(const ares_dns_record_t *dnsrec)
{
if (dnsrec == NULL) {
return 0;
@ -85,7 +85,7 @@ ares_dns_opcode_t ares_dns_record_get_opcode(ares_dns_record_t *dnsrec)
return dnsrec->opcode;
}
ares_dns_rcode_t ares_dns_record_get_rcode(ares_dns_record_t *dnsrec)
ares_dns_rcode_t ares_dns_record_get_rcode(const ares_dns_record_t *dnsrec)
{
if (dnsrec == NULL) {
return 0;
@ -217,7 +217,7 @@ void ares_dns_record_destroy(ares_dns_record_t *dnsrec)
ares_free(dnsrec);
}
size_t ares_dns_record_query_cnt(ares_dns_record_t *dnsrec)
size_t ares_dns_record_query_cnt(const ares_dns_record_t *dnsrec)
{
if (dnsrec == NULL) {
return 0;
@ -242,7 +242,7 @@ ares_status_t ares_dns_record_query_add(ares_dns_record_t *dnsrec, char *name,
size_t alloc_cnt = ares__round_up_pow2(dnsrec->qdcount + 1);
temp = ares_realloc_zero(dnsrec->qd, sizeof(*temp) * (dnsrec->qdalloc),
sizeof(*temp) * (alloc_cnt));
sizeof(*temp) * alloc_cnt);
if (temp == NULL) {
return ARES_ENOMEM;
}
@ -289,8 +289,8 @@ ares_status_t ares_dns_record_query_get(ares_dns_record_t *dnsrec, size_t idx,
return ARES_SUCCESS;
}
size_t ares_dns_record_rr_cnt(ares_dns_record_t *dnsrec,
ares_dns_section_t sect)
size_t ares_dns_record_rr_cnt(const ares_dns_record_t *dnsrec,
ares_dns_section_t sect)
{
if (dnsrec == NULL || !ares_dns_section_isvalid(sect)) {
return 0;
@ -342,9 +342,8 @@ ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
return ARES_SUCCESS;
}
temp = ares_realloc_zero(*rr_ptr, sizeof(*temp) * (*rr_alloc),
sizeof(*temp) * (cnt));
sizeof(*temp) * cnt);
if (temp == NULL) {
return ARES_ENOMEM;
}
@ -446,7 +445,7 @@ ares_dns_rr_t *ares_dns_record_rr_get(ares_dns_record_t *dnsrec,
return &rr_ptr[idx];
}
const char *ares_dns_rr_get_name(ares_dns_rr_t *rr)
const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr)
{
if (rr == NULL) {
return NULL;
@ -454,7 +453,7 @@ const char *ares_dns_rr_get_name(ares_dns_rr_t *rr)
return rr->name;
}
ares_dns_rec_type_t ares_dns_rr_get_type(ares_dns_rr_t *rr)
ares_dns_rec_type_t ares_dns_rr_get_type(const ares_dns_rr_t *rr)
{
if (rr == NULL) {
return 0;
@ -462,7 +461,7 @@ ares_dns_rec_type_t ares_dns_rr_get_type(ares_dns_rr_t *rr)
return rr->type;
}
ares_dns_class_t ares_dns_rr_get_class(ares_dns_rr_t *rr)
ares_dns_class_t ares_dns_rr_get_class(const ares_dns_rr_t *rr)
{
if (rr == NULL) {
return 0;
@ -470,7 +469,7 @@ ares_dns_class_t ares_dns_rr_get_class(ares_dns_rr_t *rr)
return rr->rclass;
}
unsigned int ares_dns_rr_get_ttl(ares_dns_rr_t *rr)
unsigned int ares_dns_rr_get_ttl(const ares_dns_rr_t *rr)
{
if (rr == NULL) {
return 0;
@ -619,16 +618,25 @@ static void *ares_dns_rr_data_ptr(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
return NULL;
}
const struct in_addr *ares_dns_rr_get_addr(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
static const void *ares_dns_rr_data_ptr_const(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
const size_t **lenptr)
{
/* We're going to cast off the const */
return ares_dns_rr_data_ptr((void *)((size_t)dns_rr), key,
(void *)((size_t)lenptr));
}
const struct in_addr *ares_dns_rr_get_addr(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
{
struct in_addr *addr;
const struct in_addr *addr;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_INADDR) {
return NULL;
}
addr = ares_dns_rr_data_ptr(dns_rr, key, NULL);
addr = ares_dns_rr_data_ptr_const(dns_rr, key, NULL);
if (addr == NULL) {
return NULL;
}
@ -636,16 +644,16 @@ const struct in_addr *ares_dns_rr_get_addr(ares_dns_rr_t *dns_rr,
return addr;
}
const struct ares_in6_addr *ares_dns_rr_get_addr6(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
const struct ares_in6_addr *ares_dns_rr_get_addr6(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
{
struct ares_in6_addr *addr;
const struct ares_in6_addr *addr;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_INADDR6) {
return NULL;
}
addr = ares_dns_rr_data_ptr(dns_rr, key, NULL);
addr = ares_dns_rr_data_ptr_const(dns_rr, key, NULL);
if (addr == NULL) {
return NULL;
}
@ -653,15 +661,16 @@ const struct ares_in6_addr *ares_dns_rr_get_addr6(ares_dns_rr_t *dns_rr,
return addr;
}
unsigned char ares_dns_rr_get_u8(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
unsigned char ares_dns_rr_get_u8(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
{
unsigned char *u8;
const unsigned char *u8;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_U8) {
return 0;
}
u8 = ares_dns_rr_data_ptr(dns_rr, key, NULL);
u8 = ares_dns_rr_data_ptr_const(dns_rr, key, NULL);
if (u8 == NULL) {
return 0;
}
@ -669,15 +678,16 @@ unsigned char ares_dns_rr_get_u8(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
return *u8;
}
unsigned short ares_dns_rr_get_u16(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
unsigned short ares_dns_rr_get_u16(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
{
unsigned short *u16;
const unsigned short *u16;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_U16) {
return 0;
}
u16 = ares_dns_rr_data_ptr(dns_rr, key, NULL);
u16 = ares_dns_rr_data_ptr_const(dns_rr, key, NULL);
if (u16 == NULL) {
return 0;
}
@ -685,15 +695,16 @@ unsigned short ares_dns_rr_get_u16(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
return *u16;
}
unsigned int ares_dns_rr_get_u32(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
{
unsigned int *u32;
const unsigned int *u32;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_U32) {
return 0;
}
u32 = ares_dns_rr_data_ptr(dns_rr, key, NULL);
u32 = ares_dns_rr_data_ptr_const(dns_rr, key, NULL);
if (u32 == NULL) {
return 0;
}
@ -701,17 +712,17 @@ unsigned int ares_dns_rr_get_u32(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
return *u32;
}
const unsigned char *ares_dns_rr_get_bin(ares_dns_rr_t *dns_rr,
const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, size_t *len)
{
unsigned char **bin = NULL;
size_t *bin_len = NULL;
unsigned char * const *bin = NULL;
size_t const *bin_len = NULL;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BIN || len == NULL) {
return NULL;
}
bin = ares_dns_rr_data_ptr(dns_rr, key, &bin_len);
bin = ares_dns_rr_data_ptr_const(dns_rr, key, &bin_len);
if (bin == NULL) {
return 0;
}
@ -726,15 +737,16 @@ const unsigned char *ares_dns_rr_get_bin(ares_dns_rr_t *dns_rr,
return *bin;
}
const char *ares_dns_rr_get_str(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key)
const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
{
char **str;
char * const *str;
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_STR) {
return NULL;
}
str = ares_dns_rr_data_ptr(dns_rr, key, NULL);
str = ares_dns_rr_data_ptr_const(dns_rr, key, NULL);
if (str == NULL) {
return NULL;
}

@ -272,28 +272,28 @@ void ares_dns_record_destroy(ares_dns_record_t *dnsrec);
* \param[in] dnsrec Initialized record object
* \return DNS query id
*/
unsigned short ares_dns_record_get_id(ares_dns_record_t *dnsrec);
unsigned short ares_dns_record_get_id(const ares_dns_record_t *dnsrec);
/*! Get the DNS Record Flags
*
* \param[in] dnsrec Initialized record object
* \return One or more \ares_dns_flags_t
*/
unsigned short ares_dns_record_get_flags(ares_dns_record_t *dnsrec);
unsigned short ares_dns_record_get_flags(const ares_dns_record_t *dnsrec);
/*! Get the DNS Record OpCode
*
* \param[in] dnsrec Initialized record object
* \return opcode
*/
ares_dns_opcode_t ares_dns_record_get_opcode(ares_dns_record_t *dnsrec);
ares_dns_opcode_t ares_dns_record_get_opcode(const ares_dns_record_t *dnsrec);
/*! Get the DNS Record RCode
*
* \param[in] dnsrec Initialized record object
* \return rcode
*/
ares_dns_rcode_t ares_dns_record_get_rcode(ares_dns_record_t *dnsrec);
ares_dns_rcode_t ares_dns_record_get_rcode(const ares_dns_record_t *dnsrec);
/*! Add a query to the DNS Record. Typically a record will have only 1
* query. Most DNS servers will reject queries with more than 1 question.
@ -313,7 +313,7 @@ ares_status_t ares_dns_record_query_add(ares_dns_record_t *dnsrec, char *name,
* \param[in] dnsrec Initialized record object
* \return count of queries
*/
size_t ares_dns_record_query_cnt(ares_dns_record_t *dnsrec);
size_t ares_dns_record_query_cnt(const ares_dns_record_t *dnsrec);
/*! Get the data about the query at the provided index.
*
@ -335,8 +335,8 @@ ares_status_t ares_dns_record_query_get(ares_dns_record_t *dnsrec, size_t idx,
* \param[in] sect Section. ARES_SECTION_ANSWER is most used.
* \return count of resource records.
*/
size_t ares_dns_record_rr_cnt(ares_dns_record_t *dnsrec,
ares_dns_section_t sect);
size_t ares_dns_record_rr_cnt(const ares_dns_record_t *dnsrec,
ares_dns_section_t sect);
/*! Add a Resource Record to the DNS Record.
@ -398,28 +398,28 @@ ares_dns_rec_type_t ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key);
* \param[in] rr Pointer to resource record
* \return Name
*/
const char *ares_dns_rr_get_name(ares_dns_rr_t *rr);
const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr);
/*! Retrieve the resource record type
*
* \param[in] rr Pointer to resource record
* \return type
*/
ares_dns_rec_type_t ares_dns_rr_get_type(ares_dns_rr_t *rr);
ares_dns_rec_type_t ares_dns_rr_get_type(const ares_dns_rr_t *rr);
/*! Retrieve the resource record class
*
* \param[in] rr Pointer to resource record
* \return class
*/
ares_dns_class_t ares_dns_rr_get_class(ares_dns_rr_t *rr);
ares_dns_class_t ares_dns_rr_get_class(const ares_dns_rr_t *rr);
/*! Retrieve the resource record TTL
*
* \param[in] rr Pointer to resource record
* \return TTL
*/
unsigned int ares_dns_rr_get_ttl(ares_dns_rr_t *rr);
unsigned int ares_dns_rr_get_ttl(const ares_dns_rr_t *rr);
/*! Set ipv4 address data type for specified resource record and key. Can
* only be used on keys with datatype ARES_DATATYPE_INADDR
@ -508,8 +508,8 @@ ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
* \param[in] key DNS Resource Record Key
* \return pointer to ipv4 address or NULL on error
*/
const struct in_addr *ares_dns_rr_get_addr(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
const struct in_addr *ares_dns_rr_get_addr(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve a pointer to the ipv6 address. Can only be used on keys with
* datatype ARES_DATATYPE_INADDR6.
@ -518,8 +518,8 @@ const struct in_addr *ares_dns_rr_get_addr(ares_dns_rr_t *dns_rr,
* \param[in] key DNS Resource Record Key
* \return pointer to ipv6 address or NULL on error
*/
const struct ares_in6_addr *ares_dns_rr_get_addr6(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
const struct ares_in6_addr *ares_dns_rr_get_addr6(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve a pointer to the string. Can only be used on keys with
* datatype ARES_DATATYPE_STR.
@ -528,7 +528,8 @@ const struct ares_in6_addr *ares_dns_rr_get_addr6(ares_dns_rr_t *dns_rr,
* \param[in] key DNS Resource Record Key
* \return pointer string or NULL on error
*/
const char *ares_dns_rr_get_str(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve an 8bit unsigned integer. Can only be used on keys with
* datatype ARES_DATATYPE_U8.
@ -537,7 +538,8 @@ const char *ares_dns_rr_get_str(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
* \param[in] key DNS Resource Record Key
* \return 8bit unsigned integer
*/
unsigned char ares_dns_rr_get_u8(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
unsigned char ares_dns_rr_get_u8(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve an 16bit unsigned integer. Can only be used on keys with
* datatype ARES_DATATYPE_U16.
@ -546,8 +548,8 @@ unsigned char ares_dns_rr_get_u8(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
* \param[in] key DNS Resource Record Key
* \return 16bit unsigned integer
*/
unsigned short ares_dns_rr_get_u16(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
unsigned short ares_dns_rr_get_u16(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve an 32bit unsigned integer. Can only be used on keys with
* datatype ARES_DATATYPE_U32.
@ -556,7 +558,8 @@ unsigned short ares_dns_rr_get_u16(ares_dns_rr_t *dns_rr,
* \param[in] key DNS Resource Record Key
* \return 32bit unsigned integer
*/
unsigned int ares_dns_rr_get_u32(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve a pointer to the binary data. Can only be used on keys with
* datatype ARES_DATATYPE_BIN.
@ -566,8 +569,8 @@ unsigned int ares_dns_rr_get_u32(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
* \param[out] len Length of binary data returned
* \return pointer binary data or NULL on error
*/
const unsigned char *ares_dns_rr_get_bin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, size_t *len);
const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, size_t *len);
/*! Parse a complete DNS message.
@ -579,28 +582,28 @@ const unsigned char *ares_dns_rr_get_bin(ares_dns_rr_t *dns_rr,
* that must be ares_dns_record_destroy()'d by caller.
* \return ARES_SUCCESS on success
*/
ares_status_t ares_dns_parse(const unsigned char *buf, size_t buf_len,
unsigned int flags, ares_dns_record_t **dnsrec);
ares_status_t ares_dns_parse(const unsigned char *buf, size_t buf_len,
unsigned int flags, ares_dns_record_t **dnsrec);
/*! @} */
/* ---- PRIVATE BELOW ----- */
ares_bool_t ares_dns_opcode_isvalid(ares_dns_opcode_t opcode);
ares_bool_t ares_dns_rcode_isvalid(ares_dns_rcode_t rcode);
ares_bool_t ares_dns_flags_arevalid(unsigned short flags);
ares_bool_t ares_dns_rec_type_isvalid(ares_dns_rec_type_t type,
ares_bool_t is_query);
ares_bool_t ares_dns_class_isvalid(ares_dns_class_t qclass,
ares_bool_t is_query);
ares_bool_t ares_dns_section_isvalid(ares_dns_section_t sect);
ares_status_t ares_dns_rr_set_str_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, char *val);
ares_status_t ares_dns_rr_set_bin_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, unsigned char *val,
size_t len);
ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t cnt);
ares_bool_t ares_dns_opcode_isvalid(ares_dns_opcode_t opcode);
ares_bool_t ares_dns_rcode_isvalid(ares_dns_rcode_t rcode);
ares_bool_t ares_dns_flags_arevalid(unsigned short flags);
ares_bool_t ares_dns_rec_type_isvalid(ares_dns_rec_type_t type,
ares_bool_t is_query);
ares_bool_t ares_dns_class_isvalid(ares_dns_class_t qclass,
ares_bool_t is_query);
ares_bool_t ares_dns_section_isvalid(ares_dns_section_t sect);
ares_status_t ares_dns_rr_set_str_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, char *val);
ares_status_t ares_dns_rr_set_bin_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, unsigned char *val,
size_t len);
ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t cnt);
struct ares_dns_qd {
char *name;

@ -60,8 +60,8 @@ size_t ares__log2(size_t n)
};
if (sizeof(size_t) == 4) {
return tab32[(size_t)(n * 0x077CB531) >> 27];
return tab32[(n * 0x077CB531) >> 27];
}
return tab64[((size_t)(n * 0x07EDD5E59A4E28C2)) >> 58];
return tab64[(n * 0x07EDD5E59A4E28C2) >> 58];
}

@ -170,10 +170,18 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen_int,
if (ptrcount == 0) {
status = ARES_ENODATA;
goto done;
} else {
status = ARES_SUCCESS;
}
/* Fill in hostname */
hostent->h_name = ares_strdup(hostname);
if (hostent->h_name == NULL) {
status = ARES_ENOMEM;
goto done;
}
done:
if (status != ARES_SUCCESS) {
ares_free_hostent(hostent);
@ -182,13 +190,6 @@ done:
status = ARES_EBADRESP;
}
} else {
/* Fill in hostname */
hostent->h_name = ares_strdup(hostname);
if (hostent->h_name == NULL) {
status = ARES_ENOMEM;
goto done;
}
*host = hostent;
}
ares_dns_record_destroy(dnsrec);

@ -242,16 +242,16 @@ static int ares_inet_pton6(const char *src, unsigned char *dst)
{
static const char xdigits_l[] = "0123456789abcdef";
static const char xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[NS_IN6ADDRSZ];
unsigned char *tp;
unsigned char *endp;
unsigned char *colonp;
const char *xdigits;
const char *curtok;
int ch;
int saw_xdigit;
int count_xdigit;
unsigned int val;
unsigned char tmp[NS_IN6ADDRSZ];
unsigned char *tp;
unsigned char *endp;
unsigned char *colonp;
const char *xdigits;
const char *curtok;
int ch;
int saw_xdigit;
int count_xdigit;
unsigned int val;
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
endp = tp + NS_IN6ADDRSZ;

@ -190,16 +190,16 @@ static size_t ares_strcpy(char *dest, const char *src, size_t dest_size)
int main(int argc, char **argv)
{
ares_channel channel;
int c;
int i;
int optmask = ARES_OPT_FLAGS;
int dnsclass = C_IN;
int type = T_A;
int status;
int nfds;
int count;
int use_ptr_helper = 0;
ares_channel channel;
int c;
int i;
int optmask = ARES_OPT_FLAGS;
int dnsclass = C_IN;
int type = T_A;
int status;
int nfds;
int count;
int use_ptr_helper = 0;
struct ares_options options;
struct hostent *hostent;
fd_set read_fds;

@ -50,8 +50,8 @@
#include <string.h>
#include "ares_getopt.h"
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = 0; /* character checked for validity */
static int optreset; /* reset getopt */
char *optarg; /* argument associated with option */

Loading…
Cancel
Save