*
* Copyright (c) 2023 Brad House
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* SPDX-License-Identifier: MIT
*/
#ifndef __ARES_DNS_RECORD_H
#define __ARES_DNS_RECORD_H
#ifdef __cplusplus
extern "C" {
#endif
*
* This is a set of functions to create and manipulate DNS records.
*
* @{
*/
* on requests (e.g. ARES_REC_TYPE_ANY), and some may only be valid on
* responses */
typedef enum {
ARES_REC_TYPE_A = 1,
ARES_REC_TYPE_NS = 2,
ARES_REC_TYPE_CNAME = 5,
ARES_REC_TYPE_SOA = 6,
ARES_REC_TYPE_PTR = 12,
ARES_REC_TYPE_HINFO = 13,
ARES_REC_TYPE_MX = 15,
ARES_REC_TYPE_TXT = 16,
ARES_REC_TYPE_SIG = 24,
ARES_REC_TYPE_AAAA = 28,
ARES_REC_TYPE_SRV = 33,
ARES_REC_TYPE_NAPTR = 35,
ARES_REC_TYPE_OPT = 41,
ARES_REC_TYPE_TLSA = 52,
* Entities (DANE) Transport Layer Security
* (TLS) Protocol: TLSA */
ARES_REC_TYPE_SVCB = 64,
ARES_REC_TYPE_HTTPS = 65,
* HTTPS */
ARES_REC_TYPE_ANY = 255,
ARES_REC_TYPE_URI = 256,
ARES_REC_TYPE_CAA = 257,
* Authorization. */
ARES_REC_TYPE_RAW_RR = 65536
* is not parsed, but provided in wire
* format */
} ares_dns_rec_type_t;
typedef enum {
ARES_CLASS_IN = 1,
ARES_CLASS_CHAOS = 3,
ARES_CLASS_HESOID = 4,
ARES_CLASS_NONE = 254,
ARES_CLASS_ANY = 255
} ares_dns_class_t;
typedef enum {
ARES_SECTION_ANSWER = 1,
ARES_SECTION_AUTHORITY = 2,
ARES_SECTION_ADDITIONAL = 3
} ares_dns_section_t;
typedef enum {
ARES_OPCODE_QUERY = 0,
ARES_OPCODE_IQUERY = 1,
ARES_OPCODE_STATUS = 2,
ARES_OPCODE_NOTIFY = 4,
ARES_OPCODE_UPDATE = 5
} ares_dns_opcode_t;
typedef enum {
ARES_FLAG_QR = 1 << 0,
ARES_FLAG_AA = 1 << 1,
ARES_FLAG_TC = 1 << 2,
ARES_FLAG_RD = 1 << 3,
ARES_FLAG_RA = 1 << 4,
* recursion */
ARES_FLAG_AD = 1 << 5,
* response that the data included has been verified by
* the server providing it */
ARES_FLAG_CD = 1 << 6
* query that non-verified data is acceptable to the
* resolver sending the query. */
} ares_dns_flags_t;
typedef enum {
ARES_RCODE_NOERROR = 0,
ARES_RCODE_FORMERR = 1,
* to interpret the query. */
ARES_RCODE_SERVFAIL = 2,
* unable to process this query due to a
* problem with the nameserver */
ARES_RCODE_NXDOMAIN = 3,
* responses from an authoritative name
* server, this code signifies that the
* domain name referenced in the query does
* not exist. */
ARES_RCODE_NOTIMP = 4,
* not support the requested kind of
* query */
ARES_RCODE_REFUSED = 5,
* perform the specified operation for
* policy reasons. */
ARES_RCODE_YXDOMAIN = 6,
* exist, does exist. */
ARES_RCODE_YXRRSET = 7,
* exist, does exist. */
ARES_RCODE_NXRRSET = 8,
* does not exist. */
ARES_RCODE_NOTAUTH = 9,
* for the zone named in the Zone section.
*/
ARES_RCODE_NOTZONE = 10,
* or Update Section is not within the zone
* denoted by the Zone Section. */
ARES_RCODE_DSOTYPEI = 11,
ARES_RCODE_BADSIG = 16,
ARES_RCODE_BADKEY = 17,
ARES_RCODE_BADTIME = 18,
ARES_RCODE_BADMODE = 19,
ARES_RCODE_BADNAME = 20,
ARES_RCODE_BADALG = 21,
ARES_RCODE_BADTRUNC = 22,
ARES_RCODE_BADCOOKIE = 23
} ares_dns_rcode_t;
typedef enum {
ARES_DATATYPE_INADDR = 1,
ARES_DATATYPE_INADDR6 = 2,
ARES_DATATYPE_U8 = 3,
ARES_DATATYPE_U16 = 4,
ARES_DATATYPE_U32 = 5,
ARES_DATATYPE_NAME = 6,
ARES_DATATYPE_STR = 7,
ARES_DATATYPE_BIN = 8,
ARES_DATATYPE_BINP = 9,
* printable. Guaranteed to have a NULL
* terminator for convenience (not included in
* length) */
ARES_DATATYPE_OPT = 10,
* data. */
ARES_DATATYPE_ABINP = 11
* Guaranteed to have a NULL terminator for
* convenience (not included in length) */
} ares_dns_datatype_t;
* to ensure we have a proper offset between keys so we can keep these sorted
*/
typedef enum {
ARES_RR_A_ADDR = (ARES_REC_TYPE_A * 100) + 1,
ARES_RR_NS_NSDNAME = (ARES_REC_TYPE_NS * 100) + 1,
ARES_RR_CNAME_CNAME = (ARES_REC_TYPE_CNAME * 100) + 1,
ARES_RR_SOA_MNAME = (ARES_REC_TYPE_SOA * 100) + 1,
ARES_RR_SOA_RNAME = (ARES_REC_TYPE_SOA * 100) + 2,
ARES_RR_SOA_SERIAL = (ARES_REC_TYPE_SOA * 100) + 3,
ARES_RR_SOA_REFRESH = (ARES_REC_TYPE_SOA * 100) + 4,
ARES_RR_SOA_RETRY = (ARES_REC_TYPE_SOA * 100) + 5,
ARES_RR_SOA_EXPIRE = (ARES_REC_TYPE_SOA * 100) + 6,
ARES_RR_SOA_MINIMUM = (ARES_REC_TYPE_SOA * 100) + 7,
ARES_RR_PTR_DNAME = (ARES_REC_TYPE_PTR * 100) + 1,
ARES_RR_HINFO_CPU = (ARES_REC_TYPE_HINFO * 100) + 1,
ARES_RR_HINFO_OS = (ARES_REC_TYPE_HINFO * 100) + 2,
ARES_RR_MX_PREFERENCE = (ARES_REC_TYPE_MX * 100) + 1,
ARES_RR_MX_EXCHANGE = (ARES_REC_TYPE_MX * 100) + 2,
ARES_RR_TXT_DATA = (ARES_REC_TYPE_TXT * 100) + 1,
ARES_RR_SIG_TYPE_COVERED = (ARES_REC_TYPE_SIG * 100) + 1,
ARES_RR_SIG_ALGORITHM = (ARES_REC_TYPE_SIG * 100) + 2,
ARES_RR_SIG_LABELS = (ARES_REC_TYPE_SIG * 100) + 3,
ARES_RR_SIG_ORIGINAL_TTL = (ARES_REC_TYPE_SIG * 100) + 4,
ARES_RR_SIG_EXPIRATION = (ARES_REC_TYPE_SIG * 100) + 5,
ARES_RR_SIG_INCEPTION = (ARES_REC_TYPE_SIG * 100) + 6,
ARES_RR_SIG_KEY_TAG = (ARES_REC_TYPE_SIG * 100) + 7,
ARES_RR_SIG_SIGNERS_NAME = (ARES_REC_TYPE_SIG * 100) + 8,
ARES_RR_SIG_SIGNATURE = (ARES_REC_TYPE_SIG * 100) + 9,
ARES_RR_AAAA_ADDR = (ARES_REC_TYPE_AAAA * 100) + 1,
ARES_RR_SRV_PRIORITY = (ARES_REC_TYPE_SRV * 100) + 2,
ARES_RR_SRV_WEIGHT = (ARES_REC_TYPE_SRV * 100) + 3,
ARES_RR_SRV_PORT = (ARES_REC_TYPE_SRV * 100) + 4,
ARES_RR_SRV_TARGET = (ARES_REC_TYPE_SRV * 100) + 5,
ARES_RR_NAPTR_ORDER = (ARES_REC_TYPE_NAPTR * 100) + 1,
ARES_RR_NAPTR_PREFERENCE = (ARES_REC_TYPE_NAPTR * 100) + 2,
ARES_RR_NAPTR_FLAGS = (ARES_REC_TYPE_NAPTR * 100) + 3,
ARES_RR_NAPTR_SERVICES = (ARES_REC_TYPE_NAPTR * 100) + 4,
ARES_RR_NAPTR_REGEXP = (ARES_REC_TYPE_NAPTR * 100) + 5,
ARES_RR_NAPTR_REPLACEMENT = (ARES_REC_TYPE_NAPTR * 100) + 6,
ARES_RR_OPT_UDP_SIZE = (ARES_REC_TYPE_OPT * 100) + 1,
ARES_RR_OPT_VERSION = (ARES_REC_TYPE_OPT * 100) + 3,
ARES_RR_OPT_FLAGS = (ARES_REC_TYPE_OPT * 100) + 4,
ARES_RR_OPT_OPTIONS = (ARES_REC_TYPE_OPT * 100) + 5,
ARES_RR_TLSA_CERT_USAGE = (ARES_REC_TYPE_TLSA * 100) + 1,
ARES_RR_TLSA_SELECTOR = (ARES_REC_TYPE_TLSA * 100) + 2,
ARES_RR_TLSA_MATCH = (ARES_REC_TYPE_TLSA * 100) + 3,
ARES_RR_TLSA_DATA = (ARES_REC_TYPE_TLSA * 100) + 4,
ARES_RR_SVCB_PRIORITY = (ARES_REC_TYPE_SVCB * 100) + 1,
ARES_RR_SVCB_TARGET = (ARES_REC_TYPE_SVCB * 100) + 2,
ARES_RR_SVCB_PARAMS = (ARES_REC_TYPE_SVCB * 100) + 3,
ARES_RR_HTTPS_PRIORITY = (ARES_REC_TYPE_HTTPS * 100) + 1,
ARES_RR_HTTPS_TARGET = (ARES_REC_TYPE_HTTPS * 100) + 2,
ARES_RR_HTTPS_PARAMS = (ARES_REC_TYPE_HTTPS * 100) + 3,
ARES_RR_URI_PRIORITY = (ARES_REC_TYPE_URI * 100) + 1,
ARES_RR_URI_WEIGHT = (ARES_REC_TYPE_URI * 100) + 2,
ARES_RR_URI_TARGET = (ARES_REC_TYPE_URI * 100) + 3,
ARES_RR_CAA_CRITICAL = (ARES_REC_TYPE_CAA * 100) + 1,
ARES_RR_CAA_TAG = (ARES_REC_TYPE_CAA * 100) + 2,
ARES_RR_CAA_VALUE = (ARES_REC_TYPE_CAA * 100) + 3,
ARES_RR_RAW_RR_TYPE = (ARES_REC_TYPE_RAW_RR * 100) + 1,
ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2
} ares_dns_rr_key_t;
typedef enum {
ARES_TLSA_USAGE_CA = 0,
ARES_TLSA_USAGE_SERVICE = 1,
ARES_TLSA_USAGE_TRUSTANCHOR = 2,
ARES_TLSA_USAGE_DOMAIN = 3
} ares_tlsa_usage_t;
typedef enum {
ARES_TLSA_SELECTOR_FULL = 0,
ARES_TLSA_SELECTOR_SUBJPUBKEYINFO = 1
} ares_tlsa_selector_t;
typedef enum {
ARES_TLSA_MATCH_EXACT = 0,
ARES_TLSA_MATCH_SHA256 = 1,
ARES_TLSA_MATCH_SHA512 = 2
} ares_tlsa_match_t;
typedef enum {
ARES_SVCB_PARAM_MANDATORY = 0,
ARES_SVCB_PARAM_ALPN = 1,
ARES_SVCB_PARAM_NO_DEFAULT_ALPN = 2,
ARES_SVCB_PARAM_PORT = 3,
ARES_SVCB_PARAM_IPV4HINT = 4,
ARES_SVCB_PARAM_ECH = 5,
ARES_SVCB_PARAM_IPV6HINT = 6
} ares_svcb_param_t;
typedef enum {
ARES_OPT_PARAM_LLQ = 1,
ARES_OPT_PARAM_UL = 2,
ARES_OPT_PARAM_NSID = 3,
ARES_OPT_PARAM_DAU = 5,
ARES_OPT_PARAM_DHU = 6,
ARES_OPT_PARAM_N3U = 7,
ARES_OPT_PARAM_EDNS_CLIENT_SUBNET = 8,
ARES_OPT_PARAM_EDNS_EXPIRE = 9,
ARES_OPT_PARAM_COOKIE = 10,
ARES_OPT_PARAM_EDNS_TCP_KEEPALIVE = 11,
ARES_OPT_PARAM_PADDING = 12,
ARES_OPT_PARAM_CHAIN = 13,
ARES_OPT_PARAM_EDNS_KEY_TAG = 14,
ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15
} ares_opt_param_t;
* ARES_RR_HTTPS_PARAMS returned by ares_dns_opt_get_datatype() */
typedef enum {
ARES_OPT_DATATYPE_NONE = 1,
*/
ARES_OPT_DATATYPE_STR_LIST = 2,
ARES_OPT_DATATYPE_U8_LIST = 3,
ARES_OPT_DATATYPE_U16 = 4,
ARES_OPT_DATATYPE_U16_LIST = 5,
ARES_OPT_DATATYPE_U32 = 6,
ARES_OPT_DATATYPE_U32_LIST = 7,
ARES_OPT_DATATYPE_INADDR4_LIST = 8,
ARES_OPT_DATATYPE_INADDR6_LIST = 9,
ARES_OPT_DATATYPE_BIN = 10,
ARES_OPT_DATATYPE_NAME = 11
} ares_dns_opt_datatype_t;
typedef enum {
ARES_DNS_PARSE_AN_BASE_RAW = 1 << 0,
ARES_DNS_PARSE_NS_BASE_RAW = 1 << 1,
ARES_DNS_PARSE_AR_BASE_RAW = 1 << 2,
ARES_DNS_PARSE_AN_EXT_RAW = 1 << 3,
ARES_DNS_PARSE_NS_EXT_RAW = 1 << 4,
ARES_DNS_PARSE_AR_EXT_RAW = 1 << 5
} ares_dns_parse_flags_t;
*
* \param[in] type DNS Record Type
* \return string
*/
CARES_EXTERN const char *ares_dns_rec_type_tostr(ares_dns_rec_type_t type);
*
* \param[in] qclass DNS Class
* \return string
*/
CARES_EXTERN const char *ares_dns_class_tostr(ares_dns_class_t qclass);
*
* \param[in] opcode DNS OpCode
* \return string
*/
CARES_EXTERN const char *ares_dns_opcode_tostr(ares_dns_opcode_t opcode);
*
* \param[in] key DNS Resource Record parameter
* \return string
*/
CARES_EXTERN const char *ares_dns_rr_key_tostr(ares_dns_rr_key_t key);
*
* \param[in] section Section
* \return string
*/
CARES_EXTERN const char *ares_dns_section_tostr(ares_dns_section_t section);
*
* \param[out] qclass Pointer passed by reference to write class
* \param[in] str String to convert
* \return ARES_TRUE on success
*/
CARES_EXTERN ares_bool_t ares_dns_class_fromstr(ares_dns_class_t *qclass,
const char *str);
*
* \param[out] qtype Pointer passed by reference to write record type
* \param[in] str String to convert
* \return ARES_TRUE on success
*/
CARES_EXTERN ares_bool_t ares_dns_rec_type_fromstr(ares_dns_rec_type_t *qtype,
const char *str);
*
* \param[in] rcode Response code to convert
* \return ARES_TRUE on success
*/
CARES_EXTERN const char *ares_dns_rcode_tostr(ares_dns_rcode_t rcode);
* return the starting pointer of the network byte order address and the
* length of the address (4 or 16).
*
* \param[in] ipaddr ASCII string form of the ip address
* \param[in,out] addr Must set "family" member to one of AF_UNSPEC,
* AF_INET, AF_INET6 on input.
* \param[out] out_len Length of binary form address
* \return Pointer to start of binary address or NULL on error.
*/
CARES_EXTERN const void *ares_dns_pton(const char *ipaddr,
struct ares_addr *addr, size_t *out_len);
*
* \param[in] addr properly filled address structure
* \return String representing PTR, use ares_free_string() to free
*/
CARES_EXTERN char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
* is a helper to return the best match for a datatype for interpreting the
* option record.
*
* \param[in] key Key associated with options/parameters
* \param[in] opt Option Key/Parameter
* \return Datatype
*/
CARES_EXTERN ares_dns_opt_datatype_t
ares_dns_opt_get_datatype(ares_dns_rr_key_t key, unsigned short opt);
* is a helper to return the name if the option is known.
*
* \param[in] key Key associated with options/parameters
* \param[in] opt Option Key/Parameter
* \return name, or NULL if not known.
*/
CARES_EXTERN const char *ares_dns_opt_get_name(ares_dns_rr_key_t key,
unsigned short opt);
* the Resource record type.
*
* \param[in] type Record Type
* \param[out] cnt Number of keys returned
* \return array of keys associated with Resource Record
*/
CARES_EXTERN const ares_dns_rr_key_t *
ares_dns_rr_get_keys(ares_dns_rec_type_t type, size_t *cnt);
*
* \param[in] key Resource Record Key
* \return datatype
*/
CARES_EXTERN ares_dns_datatype_t
ares_dns_rr_key_datatype(ares_dns_rr_key_t key);
*
* \param[in] key Resource Record Key
* \return DNS Resource Record Type
*/
CARES_EXTERN ares_dns_rec_type_t
ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key);
struct ares_dns_rr;
typedef struct ares_dns_rr ares_dns_rr_t;
struct ares_dns_qd;
typedef struct ares_dns_qd ares_dns_qd_t;
struct ares_dns_record;
typedef struct ares_dns_record ares_dns_record_t;
*
* \param[out] dnsrec Pointer passed by reference for a newly allocated
* record object. Must be ares_dns_record_destroy()'d by
* caller.
* \param[in] id DNS Query ID. If structuring a new query to be sent
* with ares_send(), this value should be zero.
* \param[in] flags DNS Flags from \ares_dns_flags_t
* \param[in] opcode DNS OpCode (typically ARES_OPCODE_QUERY)
* \param[in] rcode DNS RCode
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_record_create(ares_dns_record_t **dnsrec,
unsigned short id,
unsigned short flags,
ares_dns_opcode_t opcode,
ares_dns_rcode_t rcode);
*
* \param[in] dnsrec Initialized record object
*/
CARES_EXTERN void ares_dns_record_destroy(ares_dns_record_t *dnsrec);
*
* \param[in] dnsrec Initialized record object
* \return DNS query id
*/
CARES_EXTERN unsigned short
ares_dns_record_get_id(const ares_dns_record_t *dnsrec);
*
* \param[in] dnsrec Initialized record object
* \param[in] id DNS query id
* \return ARES_TRUE on success, ARES_FALSE on usage error
*/
CARES_EXTERN ares_bool_t ares_dns_record_set_id(ares_dns_record_t *dnsrec,
unsigned short id);
*
* \param[in] dnsrec Initialized record object
* \return One or more \ares_dns_flags_t
*/
CARES_EXTERN unsigned short
ares_dns_record_get_flags(const ares_dns_record_t *dnsrec);
*
* \param[in] dnsrec Initialized record object
* \return opcode
*/
CARES_EXTERN ares_dns_opcode_t
ares_dns_record_get_opcode(const ares_dns_record_t *dnsrec);
*
* \param[in] dnsrec Initialized record object
* \return rcode
*/
CARES_EXTERN ares_dns_rcode_t
ares_dns_record_get_rcode(const ares_dns_record_t *dnsrec);
* query. Most DNS servers will reject queries with more than 1 question.
*
* \param[in] dnsrec Initialized record object
* \param[in] name Name/Hostname of request
* \param[in] qtype Type of query
* \param[in] qclass Class of query (typically ARES_CLASS_IN)
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_record_query_add(ares_dns_record_t *dnsrec,
const char *name,
ares_dns_rec_type_t qtype,
ares_dns_class_t qclass);
* a search with aliases.
*
* Note that this will invalidate the name pointer returned from
* ares_dns_record_query_get().
*
* \param[in] dnsrec Initialized record object
* \param[in] idx Index of question (typically 0)
* \param[in] name Name to use as replacement.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_record_query_set_name(
ares_dns_record_t *dnsrec, size_t idx, const char *name);
* needing to query more than one address class (e.g. A and AAAA)
*
* \param[in] dnsrec Initialized record object
* \param[in] idx Index of question (typically 0)
* \param[in] qtype Record Type to use as replacement.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_record_query_set_type(
ares_dns_record_t *dnsrec, size_t idx, ares_dns_rec_type_t qtype);
*
* \param[in] dnsrec Initialized record object
* \return count of queries
*/
CARES_EXTERN size_t ares_dns_record_query_cnt(const ares_dns_record_t *dnsrec);
*
* \param[in] dnsrec Initialized record object
* \param[in] idx Index of query
* \param[out] name Optional. Returns name, may pass NULL if not desired.
* This pointer will be invalided by any call to
* ares_dns_record_query_set_name().
* \param[out] qtype Optional. Returns record type, may pass NULL.
* \param[out] qclass Optional. Returns class, may pass NULL.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_record_query_get(
const ares_dns_record_t *dnsrec, size_t idx, const char **name,
ares_dns_rec_type_t *qtype, ares_dns_class_t *qclass);
*
* \param[in] dnsrec Initialized record object
* \param[in] sect Section. ARES_SECTION_ANSWER is most used.
* \return count of resource records.
*/
CARES_EXTERN size_t ares_dns_record_rr_cnt(const ares_dns_record_t *dnsrec,
ares_dns_section_t sect);
*
* \param[out] rr_out Pointer to created resource record. This pointer
* is owned by the DNS record itself, this is just made
* available to facilitate adding RR-specific fields.
* \param[in] dnsrec Initialized record object
* \param[in] sect Section to add resource record to
* \param[in] name Resource Record name/hostname
* \param[in] type Record Type
* \param[in] rclass Class
* \param[in] ttl TTL
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_record_rr_add(
ares_dns_rr_t **rr_out, ares_dns_record_t *dnsrec, ares_dns_section_t sect,
const char *name, ares_dns_rec_type_t type, ares_dns_class_t rclass,
unsigned int ttl);
*
* \param[in] dnsrec Initialized record object
* \param[in] sect Section for resource record
* \param[in] idx Index of resource record in section
* \return NULL on misuse, otherwise a writable pointer to the resource record
*/
CARES_EXTERN ares_dns_rr_t *ares_dns_record_rr_get(ares_dns_record_t *dnsrec,
ares_dns_section_t sect,
size_t idx);
*
* \param[in] dnsrec Initialized record object
* \param[in] sect Section for resource record
* \param[in] idx Index of resource record in section
* \return NULL on misuse, otherwise a const pointer to the resource record
*/
CARES_EXTERN const ares_dns_rr_t *
ares_dns_record_rr_get_const(const ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t idx);
*
* \param[in] dnsrec Initialized record object
* \param[in] sect Section for resource record
* \param[in] idx Index of resource record in section
* \return ARES_SUCCESS on success, otherwise an error code.
*/
CARES_EXTERN ares_status_t ares_dns_record_rr_del(ares_dns_record_t *dnsrec,
ares_dns_section_t sect,
size_t idx);
*
* \param[in] rr Pointer to resource record
* \return Name
*/
CARES_EXTERN const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr);
*
* \param[in] rr Pointer to resource record
* \return type
*/
CARES_EXTERN ares_dns_rec_type_t ares_dns_rr_get_type(const ares_dns_rr_t *rr);
*
* \param[in] rr Pointer to resource record
* \return class
*/
CARES_EXTERN ares_dns_class_t ares_dns_rr_get_class(const ares_dns_rr_t *rr);
*
* \param[in] rr Pointer to resource record
* \return TTL
*/
CARES_EXTERN unsigned int ares_dns_rr_get_ttl(const ares_dns_rr_t *rr);
* only be used on keys with datatype ARES_DATATYPE_INADDR
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] addr Pointer to ipv4 address to use.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_addr(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
const struct in_addr *addr);
* only be used on keys with datatype ARES_DATATYPE_INADDR6
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] addr Pointer to ipv6 address to use.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t
ares_dns_rr_set_addr6(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
const struct ares_in6_addr *addr);
* only be used on keys with datatype ARES_DATATYPE_STR or ARES_DATATYPE_NAME.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] val Pointer to string to set.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_str(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
const char *val);
* only be used on keys with datatype ARES_DATATYPE_U8
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] val 8bit unsigned integer
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_u8(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned char val);
* only be used on keys with datatype ARES_DATATYPE_U16
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] val 16bit unsigned integer
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_u16(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short val);
* only be used on keys with datatype ARES_DATATYPE_U32
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] val 32bit unsigned integer
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_u32(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned int val);
* only be used on keys with datatype ARES_DATATYPE_BIN or ARES_DATATYPE_BINP.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] val Pointer to binary data.
* \param[in] len Length of binary data
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
const unsigned char *val,
size_t len);
* Can only be used on keys with datatype ARES_DATATYPE_ABINP. The value will
* Be added as the last element in the array.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] val Pointer to binary data.
* \param[in] len Length of binary data
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
const unsigned char *val,
size_t len);
* key by specified index. Can only be used on keys with datatype
* ARES_DATATYPE_ABINP. The value at the index will be deleted.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] idx Index to delete
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
size_t idx);
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] opt Option record key id.
* \param[out] val Optional. Value to associate with option.
* \param[out] val_len Length of value passed.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_rr_set_opt(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
const unsigned char *val,
size_t val_len);
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] opt Option record key id.
* \return ARES_SUCCESS if removed, ARES_ENOTFOUND if not found
*/
CARES_EXTERN ares_status_t ares_dns_rr_del_opt_byid(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt);
* datatype ARES_DATATYPE_INADDR.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return pointer to ipv4 address or NULL on error
*/
CARES_EXTERN const struct in_addr *
ares_dns_rr_get_addr(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
* datatype ARES_DATATYPE_INADDR6.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return pointer to ipv6 address or NULL on error
*/
CARES_EXTERN const struct ares_in6_addr *
ares_dns_rr_get_addr6(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
* datatype ARES_DATATYPE_STR and ARES_DATATYPE_NAME.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return pointer string or NULL on error
*/
CARES_EXTERN const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
* datatype ARES_DATATYPE_U8.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return 8bit unsigned integer
*/
CARES_EXTERN unsigned char ares_dns_rr_get_u8(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
* datatype ARES_DATATYPE_U16.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return 16bit unsigned integer
*/
CARES_EXTERN unsigned short ares_dns_rr_get_u16(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
* datatype ARES_DATATYPE_U32.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return 32bit unsigned integer
*/
CARES_EXTERN unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
* datatype ARES_DATATYPE_BIN, ARES_DATATYPE_BINP, or ARES_DATATYPE_ABINP.
* If BINP or ABINP, the data is guaranteed to have a NULL terminator which
* is NOT included in the length.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[out] len Length of binary data returned
* \return pointer binary data or NULL on error
*/
CARES_EXTERN const unsigned char *
ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
size_t *len);
* keys with datatype ARES_DATATYPE_ABINP.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return count of values
*/
CARES_EXTERN size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
* only be used on keys with datatype ARES_DATATYPE_ABINP. If ABINP, the data
* is guaranteed to have a NULL terminator which is NOT included in the length.
* If want all array membersconcatenated, may use ares_dns_rr_get_bin()
* instead.
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] idx Index of value to retrieve
* \param[out] len Length of binary data returned
* \return pointer binary data or NULL on error
*/
CARES_EXTERN const unsigned char *
ares_dns_rr_get_abin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
size_t idx, size_t *len);
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \return count, or 0 if none.
*/
CARES_EXTERN size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] idx Index of option record
* \param[out] val Optional. Pointer passed by reference to hold value.
* Options may not have values. Value if returned is
* guaranteed to be NULL terminated, however in most
* cases it is not printable.
* \param[out] val_len Optional. Pointer passed by reference to hold value
* length.
* \return option key/id on success, 65535 on misuse.
*/
CARES_EXTERN unsigned short
ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
size_t idx, const unsigned char **val, size_t *val_len);
*
* \param[in] dns_rr Pointer to resource record
* \param[in] key DNS Resource Record Key
* \param[in] opt Option record key id (this is not the index).
* \param[out] val Optional. Pointer passed by reference to hold value.
* Options may not have values. Value if returned is
* guaranteed to be NULL terminated, however in most cases
* it is not printable.
* \param[out] val_len Optional. Pointer passed by reference to hold value
* length.
* \return ARES_TRUE on success, ARES_FALSE on misuse.
*/
CARES_EXTERN ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
const unsigned char **val,
size_t *val_len);
*
* \param[in] buf pointer to bytes to be parsed
* \param[in] buf_len Length of buf provided
* \param[in] flags Flags dictating how the message should be parsed.
* \param[out] dnsrec Pointer passed by reference for a new DNS record object
* that must be ares_dns_record_destroy()'d by caller.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_parse(const unsigned char *buf,
size_t buf_len, unsigned int flags,
ares_dns_record_t **dnsrec);
*
* \param[in] dnsrec Pointer to initialized and filled DNS record object.
* \param[out] buf Pointer passed by reference to be filled in with with
* DNS message. Must be ares_free()'d by caller.
* \param[out] buf_len Length of returned buffer containing DNS message.
* \return ARES_SUCCESS on success
*/
CARES_EXTERN ares_status_t ares_dns_write(const ares_dns_record_t *dnsrec,
unsigned char **buf, size_t *buf_len);
* (such as the ttl decrement capability).
*
* \param[in] dnsrec Pointer to initialized and filled DNS record object.
* \return duplicted DNS record object, or NULL on out of memory.
*/
CARES_EXTERN ares_dns_record_t *
ares_dns_record_duplicate(const ares_dns_record_t *dnsrec);
#ifdef __cplusplus
}
#endif
#endif