ARES_DNS_RECORD(3)
π¦ ARES_DNS_RECORD(3) β from the Library Functions Manual π¦
okay so bestie, this is the ares_dns_record(3) page and it is literally the whole DNS-record squad: parsing, writing, creating, destroying, and all the enum lore that comes with it. Weβre doing this in two parts, and this part is the NAME β¨ SYNOPSIS β¨ ENUMERATIONS serve. Buckle up. π
πΈ NAME πΈ
The whole iconic crew on this page is: ares_dns_class_t, ares_dns_flags_t, ares_dns_opcode_t, ares_dns_parse, ares_dns_rcode_t, ares_dns_record_create, ares_dns_record_destroy, ares_dns_record_get_flags, ares_dns_record_get_id, ares_dns_record_get_opcode, ares_dns_record_get_rcode, ares_dns_record_query_add, ares_dns_record_query_cnt, ares_dns_record_query_get, ares_dns_rec_type_t, and ares_dns_write.
And what do they all do? Theyβre the DNS Record parsing, writing, creating and destroying functions. periodt. π«Ά
β¨ SYNOPSIS β¨
First things first, you gotta bring in the header:
#include <ares.h>
Then here are the signatures, verbatim, no cap. Donβt let the group-chat energy tempt you to βfixβ them β copy these exactly:
void ares_dns_record_destroy(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);
ares_status_t ares_dns_write(const ares_dns_record_t *dnsrec,
unsigned char **buf, size_t *buf_len);
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);
ares_dns_record_t *ares_dns_record_duplicate(const ares_dns_record_t *dnsrec);
unsigned short ares_dns_record_get_id(const ares_dns_record_t *dnsrec);
ares_bool_t ares_dns_record_set_id(ares_dns_record_t *dnsrec,
unsigned short id);
unsigned short ares_dns_record_get_flags(const ares_dns_record_t *dnsrec);
ares_dns_opcode_t ares_dns_record_get_opcode(const ares_dns_record_t *dnsrec);
ares_dns_rcode_t ares_dns_record_get_rcode(const ares_dns_record_t *dnsrec);
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);
ares_status_t ares_dns_record_query_set_name(ares_dns_record_t *dnsrec,
size_t idx,
const char *name);
ares_status_t ares_dns_record_query_set_type(ares_dns_record_t *dnsrec,
size_t idx,
ares_dns_rec_type_t qtype);
size_t ares_dns_record_query_cnt(const ares_dns_record_t *dnsrec);
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);
π ENUMERATIONS π
These are the enum families, and yes, there are a lot of them. Also important: some record types may only be valid on requests, and some may only be valid on responses β so donβt just yeet them anywhere. π
π ares_dns_rec_type_t β DNS record types handled by c-ares π
Some record types may only be valid on requests, and some may only be valid on responses:
ARES_REC_TYPE_Aβ Host addressARES_REC_TYPE_NSβ Authoritative serverARES_REC_TYPE_CNAMEβ Canonical nameARES_REC_TYPE_SOAβ Start of authority zoneARES_REC_TYPE_PTRβ Domain name pointerARES_REC_TYPE_HINFOβ Host informationARES_REC_TYPE_MXβ Mail routing informationARES_REC_TYPE_TXTβ Text stringsARES_REC_TYPE_SIGβ RFC 2535. RFC 2931. SIG RecordARES_REC_TYPE_AAAAβ RFC 3596. Ip6 AddressARES_REC_TYPE_SRVβ RFC 2782. Server SelectionARES_REC_TYPE_NAPTRβ RFC 3403. Naming Authority PointerARES_REC_TYPE_OPTβ RFC 6891. EDNS0 option (meta-RR). Pseudo Record.ARES_REC_TYPE_TLSAβ RFC 6698. DNS-Based Authentication of Named Entities (DANE) Transport Layer Security (TLS) Protocol: TLSAARES_REC_TYPE_SVCBβ RFC 9460. General Purpose Service BindingARES_REC_TYPE_HTTPSβ RFC 9460. Service Binding type for use with HTTPSARES_REC_TYPE_ANYβ Wildcard match. Not response RRARES_REC_TYPE_URIβ RFC 7553. Uniform Resource IdentifierARES_REC_TYPE_CAAβ RFC 6844. Certification Authority AuthorizationARES_REC_TYPE_RAW_RRβ Used as an indicator that the RR record is not parsed, but provided in wire format
π¦ ares_dns_class_t β DNS classes for requests and responses π¦
ARES_CLASS_INβ InternetARES_CLASS_CHAOSβ CHAOSARES_CLASS_HESIODβ Hesoid [Dyer 87]ARES_CLASS_NONEβ RFC 2136ARES_CLASS_ANYβ Any class (requests only)
π ares_dns_opcode_t β DNS header opcodes π
ARES_OPCODE_QUERYβ Standard queryARES_OPCODE_IQUERYβ Inverse query. ObsoleteARES_OPCODE_STATUSβ Name server status queryARES_OPCODE_NOTIFYβ Zone change notification (RFC 1996)ARES_OPCODE_UPDATEβ Zone update message (RFC 2136)
β ares_dns_flags_t β DNS header flags β
ARES_FLAG_QRβ QR. If set, is a responseARES_FLAG_AAβ Authoritative Answer. If set, is authoritativeARES_FLAG_TCβ Truncation. If set, is truncated responseARES_FLAG_RDβ Recursion Desired. If set, recursion is desiredARES_FLAG_RAβ Recursion Available. If set, server supports recursionARES_FLAG_ADβ RFC 2065. Authentic Data bit indicates in a response that the data included has been verified by the server providing itARES_FLAG_CDβ RFC 2065. Checking Disabled bit indicates in a query that non-verified data is acceptable to the resolver sending the query
π ares_dns_rcode_t β DNS response codes from server π
ARES_RCODE_NOERRORβ SuccessARES_RCODE_FORMERRβ Format error. The name server was unable to interpret the queryARES_RCODE_SERVFAILβ Server Failure. The name server was unable to process this query due to a problem with the nameserverARES_RCODE_NXDOMAINβ Name Error. Meaningful only for responses from an authoritative name server, this code signifies that the domain name referenced in the query does not exist.ARES_RCODE_NOTIMPβ Not implemented. The name server does not support the requested kind of queryARES_RCODE_REFUSEDβ Refused. The name server refuses to perform the specified operation for policy reasons.ARES_RCODE_YXDOMAINβ RFC 2136. Some name that ought not to exist, does existARES_RCODE_YXRRSETβ RFC 2136. Some RRset that ought to not exist, does existARES_RCODE_NXRRSETβ RFC 2136. Some RRset that ought to exist, does not existARES_RCODE_NOTAUTHβ RFC 2136. The server is not authoritative for the zone named in the Zone section.ARES_RCODE_NOTZONEβ RFC 2136. A name used in the Prerequisite or Update Section is not within the zone denoted by the Zone Section.ARES_RCODE_DSOTYPEIβ RFC 8409. DSO-TYPE Not implementedARES_RCODE_BADSIGβ RFC 8945. TSIG Signature FailureARES_RCODE_BADKEYβ RFC 8945. Key not recognizedARES_RCODE_BADTIMEβ RFC 8945. Signature out of time windowARES_RCODE_BADMODEβ RFC 2930. Bad TKEY ModeARES_RCODE_BADNAMEβ RFC 2930. Duplicate Key NameARES_RCODE_BADALGβ RFC 2930. Algorithm not supportedARES_RCODE_BADTRUNCβ RFC 8945. Bad TruncationARES_RCODE_BADCOOKIEβ RFC 7973. Bad/missing Server Cookie
π§ ares_dns_parse_flags_t β flags for altering ares_dns_parse(3) behaviour π§
ARES_DNS_PARSE_AN_BASE_RAWβ Parse Answer Section from RFC 1035 that allow name compression as RAW RR typeARES_DNS_PARSE_NS_BASE_RAWβ Parse Authority Section from RFC 1035 that allow name compression as RAW RR typeARES_DNS_PARSE_AR_BASE_RAWβ Parse Additional Section from RFC 1035 that allow name compression as RAW RR typeARES_DNS_PARSE_AN_EXT_RAWβ Parse Answer Section from later RFCs (no name compression) as RAW RR typeARES_DNS_PARSE_NS_EXT_RAWβ Parse Authority Section from later RFCs (no name compression) as RAW RR typeARES_DNS_PARSE_AR_EXT_RAWβ Parse Additional Section from later RFCs (no name compression) as RAW RR type
π DESCRIPTION π
okay so bestie, this is the part where we meet the whole DNS record squad β every function that touches ares_dns_record stuff. buckle up, it's giving very much "group project but everyone actually pulls their weight" β¨
ares_dns_record_destroy(3)β destroys the memory associated with the DNS record passed in viadnsrec, but only if that record was created by eitherares_dns_record_create(3)orares_dns_parse(3). clean up after yourself, bestie π§Ήares_dns_parse(3)β parses the buffer inbufwith lengthbuf_lenπ¦ theflagsparameter can be one or moreares_dns_parse_flags_t, or zero if you don't need any flags. the resulting DNS record data structure lands in the variable pointed to bydnsrec, and you must destroy it usingares_dns_record_destroy(3). no leaving it lying around πares_dns_write(3)β takes a populated DNS record structure indnsrecand writes a wire-format DNS message into the variable pointed to bybuf, then writes the length of that buffer into the variable pointed to bybuf_lenπ₯ the buffer must be destroyed usingares_free_string(3). yes, that's a whole cleanup step, don't skip it πares_dns_record_create(3)β creates an empty DNS record structure in the variable pointed to bydnsrecπ- the
idparameter is the DNS message id β but if you're passing this toares_send(3), that identifier gets overwritten, so it should typically be0. - the
flagsparameter is one or moreares_dns_flags_t. - the opcode goes in the
opcodeparameter and should typically beARES_OPCODE_QUERY. - the response code is meant mostly for responses, goes in the
rcodeparameter, and is typicallyARES_RCODE_NOERROR.
- the
ares_dns_record_duplicate(3)β duplicates an existing DNS record structure π«Ά lowkey useful if you need to save a result you got fromares_send_dnsrec(3)orares_search_dnsrec(3). the structure to duplicate goes indnsrec, and you get the duplicated copy back β orNULLon error, like out of memory. rude, but okay πares_dns_record_get_id(3)β retrieves the DNS message id from the DNS record indnsrec. simple. iconic. no notes πares_dns_record_set_id(3)β sets the DNS message id in theidparameter on the DNS record indnsrec. heads up: this id will be overwritten when you pass the record to c-ares, so it mostly exists for external purposes π¦ares_dns_record_get_flags(3)β retrieves the DNS message flags from the DNS record indnsrecβ¨ares_dns_record_get_opcode(3)β retrieves the DNS message flags from the DNS record indnsrec. yes bestie, flags β that's what the page says, and we don't rewrite the lore πares_dns_record_get_rcode(3)β retrieves the DNS message response code from the DNS record indnsrecπΈares_dns_record_query_add(3)β adds a question to the DNS record indnsrecπ the domain name for the question goes inname, the question type goes inqtype, and the question class goes inqclass(typicallyARES_CLASS_IN). very demure, very mindful.ares_dns_record_query_set_name(3)β modifies the question name in the DNS record indnsrecπ the index of the query goes inidx, and it must be less thanares_dns_record_query_cnt(3). the new domain name goes inname. π¨ care should be taken: this will cause invalidation of any name pointer retrieved fromares_dns_Record_query_get(3). this function is useful if you're sending multiple similar queries without re-creating the entire DNS query. efficiency queen πares_dns_record_query_set_type(3)β modifies the question type in the DNS record indnsrecπ¦ the index of the query goes inidx, and it must be less thanares_dns_record_query_cnt(3). the new query type goes inqtype.ares_dns_record_query_cnt(3)β retrieves the number of DNS questions in the DNS record indnsrecπ’ares_dns_record_query_get(3)β retrieves the details of a single DNS question indnsrecπ- the index in
idxmust be less than the value returned fromares_dns_record_query_cnt(3). - the DNS question name is returned in the variable pointed to by
nameβ you can passNULLif you don't need the name. this pointer will be invalided by any call toares_dns_record_query_set_name(3). - the DNS question type is returned in the variable pointed to by
qtypeβ you can passNULLif you don't need the type. - the DNS question class is returned in the variable pointed to by
qclassβ you can passNULLif you don't need the class.
- the index in
β¨ RETURN VALUES β¨
so here's the vibe check on what these functions hand back, bestie π
ares_dns_parse(3), ares_dns_write(3), ares_dns_record_create(3), ares_dns_record_query_add(3), and ares_dns_record_query_get(3) all return an ares_status_t error code π«Ά
ARES_SUCCESSβ returned on success, slay βARES_ENOMEMβ returned on out of memory πARES_EFORMERRβ returned on misuse π
and ares_dns_write(3) also returns ARES_EBADQUERY if the message is too large to encode. too much message, not enough buffer π
ares_dns_record_get_id(3), ares_dns_record_set_id(3), ares_dns_record_get_flags(3), ares_dns_record_get_opcode(3), ares_dns_record_get_rcode(3), and ares_dns_record_query_cnt(3) all return their prescribed datatype values, and in general can't fail except for misuse cases β in which a 0 may be returned. however, 0 can also be a valid return value for most of these functions, so don't assume 0 automatically means "problem" π
π¦ AVAILABILITY π¦
these functions were first introduced in c-ares version 1.22.0 β periodt.
πΈ SEE ALSO πΈ
xoxo, your Unix bestie π this page is from ARES_DNS_RECORD(3), dated 12 November 2023 β catch you in the next man page, and don't forget to destroy your DNS records πβ¨
π¦ where this page comes from
- alpine 3.22: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.23: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.24: c-ares-doc 1.34.9-r0 Β· MIT
- arch rolling: c-ares 1.34.9-1 Β· MIT
- centos-stream 10: c-ares-devel 1.34.9-1.el10 Β· MIT
- nixos 26.05: c-ares 1.34.9
- π the page's license: MIT
- Copyright (C) 2023 The c-ares project and its contributors
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms