ares_dns_record.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /* MIT License
  2. *
  3. * Copyright (c) 2023 Brad House
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * SPDX-License-Identifier: MIT
  25. */
  26. #ifndef __ARES_DNS_RECORD_H
  27. #define __ARES_DNS_RECORD_H
  28. /* Include ares.h, not this file directly */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /*! \addtogroup ares_dns_record DNS Record Handling
  33. *
  34. * This is a set of functions to create and manipulate DNS records.
  35. *
  36. * @{
  37. */
  38. /*! DNS Record types handled by c-ares. Some record types may only be valid
  39. * on requests (e.g. ARES_REC_TYPE_ANY), and some may only be valid on
  40. * responses */
  41. typedef enum {
  42. ARES_REC_TYPE_A = 1, /*!< Host address. */
  43. ARES_REC_TYPE_NS = 2, /*!< Authoritative server. */
  44. ARES_REC_TYPE_CNAME = 5, /*!< Canonical name. */
  45. ARES_REC_TYPE_SOA = 6, /*!< Start of authority zone. */
  46. ARES_REC_TYPE_PTR = 12, /*!< Domain name pointer. */
  47. ARES_REC_TYPE_HINFO = 13, /*!< Host information. */
  48. ARES_REC_TYPE_MX = 15, /*!< Mail routing information. */
  49. ARES_REC_TYPE_TXT = 16, /*!< Text strings. */
  50. ARES_REC_TYPE_SIG = 24, /*!< RFC 2535 / RFC 2931. SIG Record */
  51. ARES_REC_TYPE_AAAA = 28, /*!< RFC 3596. Ip6 Address. */
  52. ARES_REC_TYPE_SRV = 33, /*!< RFC 2782. Server Selection. */
  53. ARES_REC_TYPE_NAPTR = 35, /*!< RFC 3403. Naming Authority Pointer */
  54. ARES_REC_TYPE_OPT = 41, /*!< RFC 6891. EDNS0 option (meta-RR) */
  55. ARES_REC_TYPE_TLSA = 52, /*!< RFC 6698. DNS-Based Authentication of Named
  56. * Entities (DANE) Transport Layer Security
  57. * (TLS) Protocol: TLSA */
  58. ARES_REC_TYPE_SVCB = 64, /*!< RFC 9460. General Purpose Service Binding */
  59. ARES_REC_TYPE_HTTPS = 65, /*!< RFC 9460. Service Binding type for use with
  60. * HTTPS */
  61. ARES_REC_TYPE_ANY = 255, /*!< Wildcard match. Not response RR. */
  62. ARES_REC_TYPE_URI = 256, /*!< RFC 7553. Uniform Resource Identifier */
  63. ARES_REC_TYPE_CAA = 257, /*!< RFC 6844. Certification Authority
  64. * Authorization. */
  65. ARES_REC_TYPE_RAW_RR = 65536 /*!< Used as an indicator that the RR record
  66. * is not parsed, but provided in wire
  67. * format */
  68. } ares_dns_rec_type_t;
  69. /*! DNS Classes for requests and responses. */
  70. typedef enum {
  71. ARES_CLASS_IN = 1, /*!< Internet */
  72. ARES_CLASS_CHAOS = 3, /*!< CHAOS */
  73. ARES_CLASS_HESOID = 4, /*!< Hesoid [Dyer 87] */
  74. ARES_CLASS_NONE = 254, /*!< RFC 2136 */
  75. ARES_CLASS_ANY = 255 /*!< Any class (requests only) */
  76. } ares_dns_class_t;
  77. /*! DNS RR Section type */
  78. typedef enum {
  79. ARES_SECTION_ANSWER = 1, /*!< Answer section */
  80. ARES_SECTION_AUTHORITY = 2, /*!< Authority section */
  81. ARES_SECTION_ADDITIONAL = 3 /*!< Additional information section */
  82. } ares_dns_section_t;
  83. /*! DNS Header opcodes */
  84. typedef enum {
  85. ARES_OPCODE_QUERY = 0, /*!< Standard query */
  86. ARES_OPCODE_IQUERY = 1, /*!< Inverse query. Obsolete. */
  87. ARES_OPCODE_STATUS = 2, /*!< Name server status query */
  88. ARES_OPCODE_NOTIFY = 4, /*!< Zone change notification (RFC 1996) */
  89. ARES_OPCODE_UPDATE = 5 /*!< Zone update message (RFC2136) */
  90. } ares_dns_opcode_t;
  91. /*! DNS Header flags */
  92. typedef enum {
  93. ARES_FLAG_QR = 1 << 0, /*!< QR. If set, is a response */
  94. ARES_FLAG_AA = 1 << 1, /*!< Authoritative Answer. If set, is authoritative */
  95. ARES_FLAG_TC = 1 << 2, /*!< Truncation. If set, is truncated response */
  96. ARES_FLAG_RD = 1 << 3, /*!< Recursion Desired. If set, recursion is desired */
  97. ARES_FLAG_RA = 1 << 4, /*!< Recursion Available. If set, server supports
  98. * recursion */
  99. ARES_FLAG_AD = 1 << 5, /*!< RFC 2065. Authentic Data bit indicates in a
  100. * response that the data included has been verified by
  101. * the server providing it */
  102. ARES_FLAG_CD = 1 << 6 /*!< RFC 2065. Checking Disabled bit indicates in a
  103. * query that non-verified data is acceptable to the
  104. * resolver sending the query. */
  105. } ares_dns_flags_t;
  106. /*! DNS Response Codes from server */
  107. typedef enum {
  108. ARES_RCODE_NOERROR = 0, /*!< Success */
  109. ARES_RCODE_FORMERR = 1, /*!< Format error. The name server was unable
  110. * to interpret the query. */
  111. ARES_RCODE_SERVFAIL = 2, /*!< Server Failure. The name server was
  112. * unable to process this query due to a
  113. * problem with the nameserver */
  114. ARES_RCODE_NXDOMAIN = 3, /*!< Name Error. Meaningful only for
  115. * responses from an authoritative name
  116. * server, this code signifies that the
  117. * domain name referenced in the query does
  118. * not exist. */
  119. ARES_RCODE_NOTIMP = 4, /*!< Not implemented. The name server does
  120. * not support the requested kind of
  121. * query */
  122. ARES_RCODE_REFUSED = 5, /*!< Refused. The name server refuses to
  123. * perform the specified operation for
  124. * policy reasons. */
  125. ARES_RCODE_YXDOMAIN = 6, /*!< RFC 2136. Some name that ought not to
  126. * exist, does exist. */
  127. ARES_RCODE_YXRRSET = 7, /*!< RFC 2136. Some RRset that ought to not
  128. * exist, does exist. */
  129. ARES_RCODE_NXRRSET = 8, /*!< RFC 2136. Some RRset that ought to exist,
  130. * does not exist. */
  131. ARES_RCODE_NOTAUTH = 9, /*!< RFC 2136. The server is not authoritative
  132. * for the zone named in the Zone section.
  133. */
  134. ARES_RCODE_NOTZONE = 10, /*!< RFC 2136. A name used in the Prerequisite
  135. * or Update Section is not within the zone
  136. * denoted by the Zone Section. */
  137. ARES_RCODE_DSOTYPEI = 11, /*!< RFC 8409. DSO-TYPE Not implemented */
  138. ARES_RCODE_BADSIG = 16, /*!< RFC 8945. TSIG Signature Failure */
  139. ARES_RCODE_BADKEY = 17, /*!< RFC 8945. Key not recognized. */
  140. ARES_RCODE_BADTIME = 18, /*!< RFC 8945. Signature out of time window. */
  141. ARES_RCODE_BADMODE = 19, /*!< RFC 2930. Bad TKEY Mode */
  142. ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */
  143. ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */
  144. ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */
  145. ARES_RCODE_BADCOOKIE = 23 /*!< RFC 7873. Bad/missing Server Cookie */
  146. } ares_dns_rcode_t;
  147. /*! Data types used */
  148. typedef enum {
  149. ARES_DATATYPE_INADDR = 1, /*!< struct in_addr * type */
  150. ARES_DATATYPE_INADDR6 = 2, /*!< struct ares_in6_addr * type */
  151. ARES_DATATYPE_U8 = 3, /*!< 8bit unsigned integer */
  152. ARES_DATATYPE_U16 = 4, /*!< 16bit unsigned integer */
  153. ARES_DATATYPE_U32 = 5, /*!< 32bit unsigned integer */
  154. ARES_DATATYPE_NAME = 6, /*!< Null-terminated string of a domain name */
  155. ARES_DATATYPE_STR = 7, /*!< Null-terminated string */
  156. ARES_DATATYPE_BIN = 8, /*!< Binary data */
  157. ARES_DATATYPE_BINP = 9, /*!< Officially defined as binary data, but likely
  158. * printable. Guaranteed to have a NULL
  159. * terminator for convenience (not included in
  160. * length) */
  161. ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN
  162. * data. */
  163. ARES_DATATYPE_ABINP = 11 /*!< Array of binary data, likely printable.
  164. * Guaranteed to have a NULL terminator for
  165. * convenience (not included in length) */
  166. } ares_dns_datatype_t;
  167. /*! Keys used for all RR Types. We take the record type and multiply by 100
  168. * to ensure we have a proper offset between keys so we can keep these sorted
  169. */
  170. typedef enum {
  171. /*! A Record. Address. Datatype: INADDR */
  172. ARES_RR_A_ADDR = (ARES_REC_TYPE_A * 100) + 1,
  173. /*! NS Record. Name. Datatype: NAME */
  174. ARES_RR_NS_NSDNAME = (ARES_REC_TYPE_NS * 100) + 1,
  175. /*! CNAME Record. CName. Datatype: NAME */
  176. ARES_RR_CNAME_CNAME = (ARES_REC_TYPE_CNAME * 100) + 1,
  177. /*! SOA Record. MNAME, Primary Source of Data. Datatype: NAME */
  178. ARES_RR_SOA_MNAME = (ARES_REC_TYPE_SOA * 100) + 1,
  179. /*! SOA Record. RNAME, Mailbox of person responsible. Datatype: NAME */
  180. ARES_RR_SOA_RNAME = (ARES_REC_TYPE_SOA * 100) + 2,
  181. /*! SOA Record. Serial, version. Datatype: U32 */
  182. ARES_RR_SOA_SERIAL = (ARES_REC_TYPE_SOA * 100) + 3,
  183. /*! SOA Record. Refresh, zone refersh interval. Datatype: U32 */
  184. ARES_RR_SOA_REFRESH = (ARES_REC_TYPE_SOA * 100) + 4,
  185. /*! SOA Record. Retry, failed refresh retry interval. Datatype: U32 */
  186. ARES_RR_SOA_RETRY = (ARES_REC_TYPE_SOA * 100) + 5,
  187. /*! SOA Record. Expire, upper limit on authority. Datatype: U32 */
  188. ARES_RR_SOA_EXPIRE = (ARES_REC_TYPE_SOA * 100) + 6,
  189. /*! SOA Record. Minimum, RR TTL. Datatype: U32 */
  190. ARES_RR_SOA_MINIMUM = (ARES_REC_TYPE_SOA * 100) + 7,
  191. /*! PTR Record. DNAME, pointer domain. Datatype: NAME */
  192. ARES_RR_PTR_DNAME = (ARES_REC_TYPE_PTR * 100) + 1,
  193. /*! HINFO Record. CPU. Datatype: STR */
  194. ARES_RR_HINFO_CPU = (ARES_REC_TYPE_HINFO * 100) + 1,
  195. /*! HINFO Record. OS. Datatype: STR */
  196. ARES_RR_HINFO_OS = (ARES_REC_TYPE_HINFO * 100) + 2,
  197. /*! MX Record. Preference. Datatype: U16 */
  198. ARES_RR_MX_PREFERENCE = (ARES_REC_TYPE_MX * 100) + 1,
  199. /*! MX Record. Exchange, domain. Datatype: NAME */
  200. ARES_RR_MX_EXCHANGE = (ARES_REC_TYPE_MX * 100) + 2,
  201. /*! TXT Record. Data. Datatype: ABINP */
  202. ARES_RR_TXT_DATA = (ARES_REC_TYPE_TXT * 100) + 1,
  203. /*! SIG Record. Type Covered. Datatype: U16 */
  204. ARES_RR_SIG_TYPE_COVERED = (ARES_REC_TYPE_SIG * 100) + 1,
  205. /*! SIG Record. Algorithm. Datatype: U8 */
  206. ARES_RR_SIG_ALGORITHM = (ARES_REC_TYPE_SIG * 100) + 2,
  207. /*! SIG Record. Labels. Datatype: U8 */
  208. ARES_RR_SIG_LABELS = (ARES_REC_TYPE_SIG * 100) + 3,
  209. /*! SIG Record. Original TTL. Datatype: U32 */
  210. ARES_RR_SIG_ORIGINAL_TTL = (ARES_REC_TYPE_SIG * 100) + 4,
  211. /*! SIG Record. Signature Expiration. Datatype: U32 */
  212. ARES_RR_SIG_EXPIRATION = (ARES_REC_TYPE_SIG * 100) + 5,
  213. /*! SIG Record. Signature Inception. Datatype: U32 */
  214. ARES_RR_SIG_INCEPTION = (ARES_REC_TYPE_SIG * 100) + 6,
  215. /*! SIG Record. Key Tag. Datatype: U16 */
  216. ARES_RR_SIG_KEY_TAG = (ARES_REC_TYPE_SIG * 100) + 7,
  217. /*! SIG Record. Signers Name. Datatype: NAME */
  218. ARES_RR_SIG_SIGNERS_NAME = (ARES_REC_TYPE_SIG * 100) + 8,
  219. /*! SIG Record. Signature. Datatype: BIN */
  220. ARES_RR_SIG_SIGNATURE = (ARES_REC_TYPE_SIG * 100) + 9,
  221. /*! AAAA Record. Address. Datatype: INADDR6 */
  222. ARES_RR_AAAA_ADDR = (ARES_REC_TYPE_AAAA * 100) + 1,
  223. /*! SRV Record. Priority. Datatype: U16 */
  224. ARES_RR_SRV_PRIORITY = (ARES_REC_TYPE_SRV * 100) + 2,
  225. /*! SRV Record. Weight. Datatype: U16 */
  226. ARES_RR_SRV_WEIGHT = (ARES_REC_TYPE_SRV * 100) + 3,
  227. /*! SRV Record. Port. Datatype: U16 */
  228. ARES_RR_SRV_PORT = (ARES_REC_TYPE_SRV * 100) + 4,
  229. /*! SRV Record. Target domain. Datatype: NAME */
  230. ARES_RR_SRV_TARGET = (ARES_REC_TYPE_SRV * 100) + 5,
  231. /*! NAPTR Record. Order. Datatype: U16 */
  232. ARES_RR_NAPTR_ORDER = (ARES_REC_TYPE_NAPTR * 100) + 1,
  233. /*! NAPTR Record. Preference. Datatype: U16 */
  234. ARES_RR_NAPTR_PREFERENCE = (ARES_REC_TYPE_NAPTR * 100) + 2,
  235. /*! NAPTR Record. Flags. Datatype: STR */
  236. ARES_RR_NAPTR_FLAGS = (ARES_REC_TYPE_NAPTR * 100) + 3,
  237. /*! NAPTR Record. Services. Datatype: STR */
  238. ARES_RR_NAPTR_SERVICES = (ARES_REC_TYPE_NAPTR * 100) + 4,
  239. /*! NAPTR Record. Regexp. Datatype: STR */
  240. ARES_RR_NAPTR_REGEXP = (ARES_REC_TYPE_NAPTR * 100) + 5,
  241. /*! NAPTR Record. Replacement. Datatype: NAME */
  242. ARES_RR_NAPTR_REPLACEMENT = (ARES_REC_TYPE_NAPTR * 100) + 6,
  243. /*! OPT Record. UDP Size. Datatype: U16 */
  244. ARES_RR_OPT_UDP_SIZE = (ARES_REC_TYPE_OPT * 100) + 1,
  245. /*! OPT Record. Version. Datatype: U8 */
  246. ARES_RR_OPT_VERSION = (ARES_REC_TYPE_OPT * 100) + 3,
  247. /*! OPT Record. Flags. Datatype: U16 */
  248. ARES_RR_OPT_FLAGS = (ARES_REC_TYPE_OPT * 100) + 4,
  249. /*! OPT Record. Options. Datatype: OPT */
  250. ARES_RR_OPT_OPTIONS = (ARES_REC_TYPE_OPT * 100) + 5,
  251. /*! TLSA Record. Certificate Usage. Datatype: U8 */
  252. ARES_RR_TLSA_CERT_USAGE = (ARES_REC_TYPE_TLSA * 100) + 1,
  253. /*! TLSA Record. Selector. Datatype: U8 */
  254. ARES_RR_TLSA_SELECTOR = (ARES_REC_TYPE_TLSA * 100) + 2,
  255. /*! TLSA Record. Matching Type. Datatype: U8 */
  256. ARES_RR_TLSA_MATCH = (ARES_REC_TYPE_TLSA * 100) + 3,
  257. /*! TLSA Record. Certificate Association Data. Datatype: BIN */
  258. ARES_RR_TLSA_DATA = (ARES_REC_TYPE_TLSA * 100) + 4,
  259. /*! SVCB Record. SvcPriority. Datatype: U16 */
  260. ARES_RR_SVCB_PRIORITY = (ARES_REC_TYPE_SVCB * 100) + 1,
  261. /*! SVCB Record. TargetName. Datatype: NAME */
  262. ARES_RR_SVCB_TARGET = (ARES_REC_TYPE_SVCB * 100) + 2,
  263. /*! SVCB Record. SvcParams. Datatype: OPT */
  264. ARES_RR_SVCB_PARAMS = (ARES_REC_TYPE_SVCB * 100) + 3,
  265. /*! HTTPS Record. SvcPriority. Datatype: U16 */
  266. ARES_RR_HTTPS_PRIORITY = (ARES_REC_TYPE_HTTPS * 100) + 1,
  267. /*! HTTPS Record. TargetName. Datatype: NAME */
  268. ARES_RR_HTTPS_TARGET = (ARES_REC_TYPE_HTTPS * 100) + 2,
  269. /*! HTTPS Record. SvcParams. Datatype: OPT */
  270. ARES_RR_HTTPS_PARAMS = (ARES_REC_TYPE_HTTPS * 100) + 3,
  271. /*! URI Record. Priority. Datatype: U16 */
  272. ARES_RR_URI_PRIORITY = (ARES_REC_TYPE_URI * 100) + 1,
  273. /*! URI Record. Weight. Datatype: U16 */
  274. ARES_RR_URI_WEIGHT = (ARES_REC_TYPE_URI * 100) + 2,
  275. /*! URI Record. Target domain. Datatype: NAME */
  276. ARES_RR_URI_TARGET = (ARES_REC_TYPE_URI * 100) + 3,
  277. /*! CAA Record. Critical flag. Datatype: U8 */
  278. ARES_RR_CAA_CRITICAL = (ARES_REC_TYPE_CAA * 100) + 1,
  279. /*! CAA Record. Tag/Property. Datatype: STR */
  280. ARES_RR_CAA_TAG = (ARES_REC_TYPE_CAA * 100) + 2,
  281. /*! CAA Record. Value. Datatype: BINP */
  282. ARES_RR_CAA_VALUE = (ARES_REC_TYPE_CAA * 100) + 3,
  283. /*! RAW Record. RR Type. Datatype: U16 */
  284. ARES_RR_RAW_RR_TYPE = (ARES_REC_TYPE_RAW_RR * 100) + 1,
  285. /*! RAW Record. RR Data. Datatype: BIN */
  286. ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2
  287. } ares_dns_rr_key_t;
  288. /*! TLSA Record ARES_RR_TLSA_CERT_USAGE known values */
  289. typedef enum {
  290. /*! Certificate Usage 0. CA Constraint. */
  291. ARES_TLSA_USAGE_CA = 0,
  292. /*! Certificate Usage 1. Service Certificate Constraint. */
  293. ARES_TLSA_USAGE_SERVICE = 1,
  294. /*! Certificate Usage 2. Trust Anchor Assertion. */
  295. ARES_TLSA_USAGE_TRUSTANCHOR = 2,
  296. /*! Certificate Usage 3. Domain-issued certificate. */
  297. ARES_TLSA_USAGE_DOMAIN = 3
  298. } ares_tlsa_usage_t;
  299. /*! TLSA Record ARES_RR_TLSA_SELECTOR known values */
  300. typedef enum {
  301. /*! Full Certificate */
  302. ARES_TLSA_SELECTOR_FULL = 0,
  303. /*! DER-encoded SubjectPublicKeyInfo */
  304. ARES_TLSA_SELECTOR_SUBJPUBKEYINFO = 1
  305. } ares_tlsa_selector_t;
  306. /*! TLSA Record ARES_RR_TLSA_MATCH known values */
  307. typedef enum {
  308. /*! Exact match */
  309. ARES_TLSA_MATCH_EXACT = 0,
  310. /*! Sha256 match */
  311. ARES_TLSA_MATCH_SHA256 = 1,
  312. /*! Sha512 match */
  313. ARES_TLSA_MATCH_SHA512 = 2
  314. } ares_tlsa_match_t;
  315. /*! SVCB (and HTTPS) RR known parameters */
  316. typedef enum {
  317. /*! Mandatory keys in this RR (RFC 9460 Section 8) */
  318. ARES_SVCB_PARAM_MANDATORY = 0,
  319. /*! Additional supported protocols (RFC 9460 Section 7.1) */
  320. ARES_SVCB_PARAM_ALPN = 1,
  321. /*! No support for default protocol (RFC 9460 Section 7.1) */
  322. ARES_SVCB_PARAM_NO_DEFAULT_ALPN = 2,
  323. /*! Port for alternative endpoint (RFC 9460 Section 7.2) */
  324. ARES_SVCB_PARAM_PORT = 3,
  325. /*! IPv4 address hints (RFC 9460 Section 7.3) */
  326. ARES_SVCB_PARAM_IPV4HINT = 4,
  327. /*! RESERVED (held for Encrypted ClientHello) */
  328. ARES_SVCB_PARAM_ECH = 5,
  329. /*! IPv6 address hints (RFC 9460 Section 7.3) */
  330. ARES_SVCB_PARAM_IPV6HINT = 6
  331. } ares_svcb_param_t;
  332. /*! OPT RR known parameters */
  333. typedef enum {
  334. /*! RFC 8764. Apple's DNS Long-Lived Queries Protocol */
  335. ARES_OPT_PARAM_LLQ = 1,
  336. /*! http://files.dns-sd.org/draft-sekar-dns-ul.txt: Update Lease */
  337. ARES_OPT_PARAM_UL = 2,
  338. /*! RFC 5001. Name Server Identification */
  339. ARES_OPT_PARAM_NSID = 3,
  340. /*! RFC 6975. DNSSEC Algorithm Understood */
  341. ARES_OPT_PARAM_DAU = 5,
  342. /*! RFC 6975. DS Hash Understood */
  343. ARES_OPT_PARAM_DHU = 6,
  344. /*! RFC 6975. NSEC3 Hash Understood */
  345. ARES_OPT_PARAM_N3U = 7,
  346. /*! RFC 7871. Client Subnet */
  347. ARES_OPT_PARAM_EDNS_CLIENT_SUBNET = 8,
  348. /*! RFC 7314. Expire Timer */
  349. ARES_OPT_PARAM_EDNS_EXPIRE = 9,
  350. /*! RFC 7873. Client and Server Cookies */
  351. ARES_OPT_PARAM_COOKIE = 10,
  352. /*! RFC 7828. TCP Keepalive timeout */
  353. ARES_OPT_PARAM_EDNS_TCP_KEEPALIVE = 11,
  354. /*! RFC 7830. Padding */
  355. ARES_OPT_PARAM_PADDING = 12,
  356. /*! RFC 7901. Chain query requests */
  357. ARES_OPT_PARAM_CHAIN = 13,
  358. /*! RFC 8145. Signaling Trust Anchor Knowledge in DNSSEC */
  359. ARES_OPT_PARAM_EDNS_KEY_TAG = 14,
  360. /*! RFC 8914. Extended ERROR code and message */
  361. ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15
  362. } ares_opt_param_t;
  363. /*! Data type for option records for keys like ARES_RR_OPT_OPTIONS and
  364. * ARES_RR_HTTPS_PARAMS returned by ares_dns_opt_get_datatype() */
  365. typedef enum {
  366. /*! No value allowed for this option */
  367. ARES_OPT_DATATYPE_NONE = 1,
  368. /*! List of strings, each prefixed with a single octet representing the length
  369. */
  370. ARES_OPT_DATATYPE_STR_LIST = 2,
  371. /*! List of 8bit integers, concatenated */
  372. ARES_OPT_DATATYPE_U8_LIST = 3,
  373. /*! 16bit integer in network byte order */
  374. ARES_OPT_DATATYPE_U16 = 4,
  375. /*! list of 16bit integer in network byte order, concatenated. */
  376. ARES_OPT_DATATYPE_U16_LIST = 5,
  377. /*! 32bit integer in network byte order */
  378. ARES_OPT_DATATYPE_U32 = 6,
  379. /*! list 32bit integer in network byte order, concatenated */
  380. ARES_OPT_DATATYPE_U32_LIST = 7,
  381. /*! List of ipv4 addresses in network byte order, concatenated */
  382. ARES_OPT_DATATYPE_INADDR4_LIST = 8,
  383. /*! List of ipv6 addresses in network byte order, concatenated */
  384. ARES_OPT_DATATYPE_INADDR6_LIST = 9,
  385. /*! Binary Data */
  386. ARES_OPT_DATATYPE_BIN = 10,
  387. /*! DNS Domain Name Format */
  388. ARES_OPT_DATATYPE_NAME = 11
  389. } ares_dns_opt_datatype_t;
  390. /*! Data type for flags to ares_dns_parse() */
  391. typedef enum {
  392. /*! Parse Answers from RFC 1035 that allow name compression as RAW */
  393. ARES_DNS_PARSE_AN_BASE_RAW = 1 << 0,
  394. /*! Parse Authority from RFC 1035 that allow name compression as RAW */
  395. ARES_DNS_PARSE_NS_BASE_RAW = 1 << 1,
  396. /*! Parse Additional from RFC 1035 that allow name compression as RAW */
  397. ARES_DNS_PARSE_AR_BASE_RAW = 1 << 2,
  398. /*! Parse Answers from later RFCs (no name compression) RAW */
  399. ARES_DNS_PARSE_AN_EXT_RAW = 1 << 3,
  400. /*! Parse Authority from later RFCs (no name compression) as RAW */
  401. ARES_DNS_PARSE_NS_EXT_RAW = 1 << 4,
  402. /*! Parse Additional from later RFCs (no name compression) as RAW */
  403. ARES_DNS_PARSE_AR_EXT_RAW = 1 << 5
  404. } ares_dns_parse_flags_t;
  405. /*! String representation of DNS Record Type
  406. *
  407. * \param[in] type DNS Record Type
  408. * \return string
  409. */
  410. CARES_EXTERN const char *ares_dns_rec_type_tostr(ares_dns_rec_type_t type);
  411. /*! String representation of DNS Class
  412. *
  413. * \param[in] qclass DNS Class
  414. * \return string
  415. */
  416. CARES_EXTERN const char *ares_dns_class_tostr(ares_dns_class_t qclass);
  417. /*! String representation of DNS OpCode
  418. *
  419. * \param[in] opcode DNS OpCode
  420. * \return string
  421. */
  422. CARES_EXTERN const char *ares_dns_opcode_tostr(ares_dns_opcode_t opcode);
  423. /*! String representation of DNS Resource Record Parameter
  424. *
  425. * \param[in] key DNS Resource Record parameter
  426. * \return string
  427. */
  428. CARES_EXTERN const char *ares_dns_rr_key_tostr(ares_dns_rr_key_t key);
  429. /*! String representation of DNS Resource Record section
  430. *
  431. * \param[in] section Section
  432. * \return string
  433. */
  434. CARES_EXTERN const char *ares_dns_section_tostr(ares_dns_section_t section);
  435. /*! Convert DNS class name as string to ares_dns_class_t
  436. *
  437. * \param[out] qclass Pointer passed by reference to write class
  438. * \param[in] str String to convert
  439. * \return ARES_TRUE on success
  440. */
  441. CARES_EXTERN ares_bool_t ares_dns_class_fromstr(ares_dns_class_t *qclass,
  442. const char *str);
  443. /*! Convert DNS record type as string to ares_dns_rec_type_t
  444. *
  445. * \param[out] qtype Pointer passed by reference to write record type
  446. * \param[in] str String to convert
  447. * \return ARES_TRUE on success
  448. */
  449. CARES_EXTERN ares_bool_t ares_dns_rec_type_fromstr(ares_dns_rec_type_t *qtype,
  450. const char *str);
  451. /*! Convert DNS response code as string to from ares_dns_rcode_t
  452. *
  453. * \param[in] rcode Response code to convert
  454. * \return ARES_TRUE on success
  455. */
  456. CARES_EXTERN const char *ares_dns_rcode_tostr(ares_dns_rcode_t rcode);
  457. /*! Convert any valid ip address (ipv4 or ipv6) into struct ares_addr and
  458. * return the starting pointer of the network byte order address and the
  459. * length of the address (4 or 16).
  460. *
  461. * \param[in] ipaddr ASCII string form of the ip address
  462. * \param[in,out] addr Must set "family" member to one of AF_UNSPEC,
  463. * AF_INET, AF_INET6 on input.
  464. * \param[out] out_len Length of binary form address
  465. * \return Pointer to start of binary address or NULL on error.
  466. */
  467. CARES_EXTERN const void *ares_dns_pton(const char *ipaddr,
  468. struct ares_addr *addr, size_t *out_len);
  469. /*! Convert an ip address into the PTR format for in-addr.arpa or in6.arpa
  470. *
  471. * \param[in] addr properly filled address structure
  472. * \return String representing PTR, use ares_free_string() to free
  473. */
  474. CARES_EXTERN char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
  475. /*! The options/parameters extensions to some RRs can be somewhat opaque, this
  476. * is a helper to return the best match for a datatype for interpreting the
  477. * option record.
  478. *
  479. * \param[in] key Key associated with options/parameters
  480. * \param[in] opt Option Key/Parameter
  481. * \return Datatype
  482. */
  483. CARES_EXTERN ares_dns_opt_datatype_t
  484. ares_dns_opt_get_datatype(ares_dns_rr_key_t key, unsigned short opt);
  485. /*! The options/parameters extensions to some RRs can be somewhat opaque, this
  486. * is a helper to return the name if the option is known.
  487. *
  488. * \param[in] key Key associated with options/parameters
  489. * \param[in] opt Option Key/Parameter
  490. * \return name, or NULL if not known.
  491. */
  492. CARES_EXTERN const char *ares_dns_opt_get_name(ares_dns_rr_key_t key,
  493. unsigned short opt);
  494. /*! Retrieve a list of Resource Record keys that can be set or retrieved for
  495. * the Resource record type.
  496. *
  497. * \param[in] type Record Type
  498. * \param[out] cnt Number of keys returned
  499. * \return array of keys associated with Resource Record
  500. */
  501. CARES_EXTERN const ares_dns_rr_key_t *
  502. ares_dns_rr_get_keys(ares_dns_rec_type_t type, size_t *cnt);
  503. /*! Retrieve the datatype associated with a Resource Record key.
  504. *
  505. * \param[in] key Resource Record Key
  506. * \return datatype
  507. */
  508. CARES_EXTERN ares_dns_datatype_t
  509. ares_dns_rr_key_datatype(ares_dns_rr_key_t key);
  510. /*! Retrieve the DNS Resource Record type associated with a Resource Record key.
  511. *
  512. * \param[in] key Resource Record Key
  513. * \return DNS Resource Record Type
  514. */
  515. CARES_EXTERN ares_dns_rec_type_t
  516. ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key);
  517. /*! Opaque data type representing a DNS RR (Resource Record) */
  518. struct ares_dns_rr;
  519. /*! Typedef for opaque data type representing a DNS RR (Resource Record) */
  520. typedef struct ares_dns_rr ares_dns_rr_t;
  521. /*! Opaque data type representing a DNS Query Data QD Packet */
  522. struct ares_dns_qd;
  523. /*! Typedef for opaque data type representing a DNS Query Data QD Packet */
  524. typedef struct ares_dns_qd ares_dns_qd_t;
  525. /*! Opaque data type representing a DNS Packet */
  526. struct ares_dns_record;
  527. /*! Typedef for opaque data type representing a DNS Packet */
  528. typedef struct ares_dns_record ares_dns_record_t;
  529. /*! Create a new DNS record object
  530. *
  531. * \param[out] dnsrec Pointer passed by reference for a newly allocated
  532. * record object. Must be ares_dns_record_destroy()'d by
  533. * caller.
  534. * \param[in] id DNS Query ID. If structuring a new query to be sent
  535. * with ares_send(), this value should be zero.
  536. * \param[in] flags DNS Flags from \ares_dns_flags_t
  537. * \param[in] opcode DNS OpCode (typically ARES_OPCODE_QUERY)
  538. * \param[in] rcode DNS RCode
  539. * \return ARES_SUCCESS on success
  540. */
  541. CARES_EXTERN ares_status_t ares_dns_record_create(ares_dns_record_t **dnsrec,
  542. unsigned short id,
  543. unsigned short flags,
  544. ares_dns_opcode_t opcode,
  545. ares_dns_rcode_t rcode);
  546. /*! Destroy a DNS record object
  547. *
  548. * \param[in] dnsrec Initialized record object
  549. */
  550. CARES_EXTERN void ares_dns_record_destroy(ares_dns_record_t *dnsrec);
  551. /*! Get the DNS Query ID
  552. *
  553. * \param[in] dnsrec Initialized record object
  554. * \return DNS query id
  555. */
  556. CARES_EXTERN unsigned short
  557. ares_dns_record_get_id(const ares_dns_record_t *dnsrec);
  558. /*! Overwrite the DNS query id
  559. *
  560. * \param[in] dnsrec Initialized record object
  561. * \param[in] id DNS query id
  562. * \return ARES_TRUE on success, ARES_FALSE on usage error
  563. */
  564. CARES_EXTERN ares_bool_t ares_dns_record_set_id(ares_dns_record_t *dnsrec,
  565. unsigned short id);
  566. /*! Get the DNS Record Flags
  567. *
  568. * \param[in] dnsrec Initialized record object
  569. * \return One or more \ares_dns_flags_t
  570. */
  571. CARES_EXTERN unsigned short
  572. ares_dns_record_get_flags(const ares_dns_record_t *dnsrec);
  573. /*! Get the DNS Record OpCode
  574. *
  575. * \param[in] dnsrec Initialized record object
  576. * \return opcode
  577. */
  578. CARES_EXTERN ares_dns_opcode_t
  579. ares_dns_record_get_opcode(const ares_dns_record_t *dnsrec);
  580. /*! Get the DNS Record RCode
  581. *
  582. * \param[in] dnsrec Initialized record object
  583. * \return rcode
  584. */
  585. CARES_EXTERN ares_dns_rcode_t
  586. ares_dns_record_get_rcode(const ares_dns_record_t *dnsrec);
  587. /*! Add a query to the DNS Record. Typically a record will have only 1
  588. * query. Most DNS servers will reject queries with more than 1 question.
  589. *
  590. * \param[in] dnsrec Initialized record object
  591. * \param[in] name Name/Hostname of request
  592. * \param[in] qtype Type of query
  593. * \param[in] qclass Class of query (typically ARES_CLASS_IN)
  594. * \return ARES_SUCCESS on success
  595. */
  596. CARES_EXTERN ares_status_t ares_dns_record_query_add(ares_dns_record_t *dnsrec,
  597. const char *name,
  598. ares_dns_rec_type_t qtype,
  599. ares_dns_class_t qclass);
  600. /*! Replace the question name with a new name. This may be used when performing
  601. * a search with aliases.
  602. *
  603. * Note that this will invalidate the name pointer returned from
  604. * ares_dns_record_query_get().
  605. *
  606. * \param[in] dnsrec Initialized record object
  607. * \param[in] idx Index of question (typically 0)
  608. * \param[in] name Name to use as replacement.
  609. * \return ARES_SUCCESS on success
  610. */
  611. CARES_EXTERN ares_status_t ares_dns_record_query_set_name(
  612. ares_dns_record_t *dnsrec, size_t idx, const char *name);
  613. /*! Replace the question type with a different type. This may be used when
  614. * needing to query more than one address class (e.g. A and AAAA)
  615. *
  616. * \param[in] dnsrec Initialized record object
  617. * \param[in] idx Index of question (typically 0)
  618. * \param[in] qtype Record Type to use as replacement.
  619. * \return ARES_SUCCESS on success
  620. */
  621. CARES_EXTERN ares_status_t ares_dns_record_query_set_type(
  622. ares_dns_record_t *dnsrec, size_t idx, ares_dns_rec_type_t qtype);
  623. /*! Get the count of queries in the DNS Record
  624. *
  625. * \param[in] dnsrec Initialized record object
  626. * \return count of queries
  627. */
  628. CARES_EXTERN size_t ares_dns_record_query_cnt(const ares_dns_record_t *dnsrec);
  629. /*! Get the data about the query at the provided index.
  630. *
  631. * \param[in] dnsrec Initialized record object
  632. * \param[in] idx Index of query
  633. * \param[out] name Optional. Returns name, may pass NULL if not desired.
  634. * This pointer will be invalided by any call to
  635. * ares_dns_record_query_set_name().
  636. * \param[out] qtype Optional. Returns record type, may pass NULL.
  637. * \param[out] qclass Optional. Returns class, may pass NULL.
  638. * \return ARES_SUCCESS on success
  639. */
  640. CARES_EXTERN ares_status_t ares_dns_record_query_get(
  641. const ares_dns_record_t *dnsrec, size_t idx, const char **name,
  642. ares_dns_rec_type_t *qtype, ares_dns_class_t *qclass);
  643. /*! Get the count of Resource Records in the provided section
  644. *
  645. * \param[in] dnsrec Initialized record object
  646. * \param[in] sect Section. ARES_SECTION_ANSWER is most used.
  647. * \return count of resource records.
  648. */
  649. CARES_EXTERN size_t ares_dns_record_rr_cnt(const ares_dns_record_t *dnsrec,
  650. ares_dns_section_t sect);
  651. /*! Add a Resource Record to the DNS Record.
  652. *
  653. * \param[out] rr_out Pointer to created resource record. This pointer
  654. * is owned by the DNS record itself, this is just made
  655. * available to facilitate adding RR-specific fields.
  656. * \param[in] dnsrec Initialized record object
  657. * \param[in] sect Section to add resource record to
  658. * \param[in] name Resource Record name/hostname
  659. * \param[in] type Record Type
  660. * \param[in] rclass Class
  661. * \param[in] ttl TTL
  662. * \return ARES_SUCCESS on success
  663. */
  664. CARES_EXTERN ares_status_t ares_dns_record_rr_add(
  665. ares_dns_rr_t **rr_out, ares_dns_record_t *dnsrec, ares_dns_section_t sect,
  666. const char *name, ares_dns_rec_type_t type, ares_dns_class_t rclass,
  667. unsigned int ttl);
  668. /*! Fetch a writable resource record based on the section and index.
  669. *
  670. * \param[in] dnsrec Initialized record object
  671. * \param[in] sect Section for resource record
  672. * \param[in] idx Index of resource record in section
  673. * \return NULL on misuse, otherwise a writable pointer to the resource record
  674. */
  675. CARES_EXTERN ares_dns_rr_t *ares_dns_record_rr_get(ares_dns_record_t *dnsrec,
  676. ares_dns_section_t sect,
  677. size_t idx);
  678. /*! Fetch a non-writeable resource record based on the section and index.
  679. *
  680. * \param[in] dnsrec Initialized record object
  681. * \param[in] sect Section for resource record
  682. * \param[in] idx Index of resource record in section
  683. * \return NULL on misuse, otherwise a const pointer to the resource record
  684. */
  685. CARES_EXTERN const ares_dns_rr_t *
  686. ares_dns_record_rr_get_const(const ares_dns_record_t *dnsrec,
  687. ares_dns_section_t sect, size_t idx);
  688. /*! Remove the resource record based on the section and index
  689. *
  690. * \param[in] dnsrec Initialized record object
  691. * \param[in] sect Section for resource record
  692. * \param[in] idx Index of resource record in section
  693. * \return ARES_SUCCESS on success, otherwise an error code.
  694. */
  695. CARES_EXTERN ares_status_t ares_dns_record_rr_del(ares_dns_record_t *dnsrec,
  696. ares_dns_section_t sect,
  697. size_t idx);
  698. /*! Retrieve the resource record Name/Hostname
  699. *
  700. * \param[in] rr Pointer to resource record
  701. * \return Name
  702. */
  703. CARES_EXTERN const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr);
  704. /*! Retrieve the resource record type
  705. *
  706. * \param[in] rr Pointer to resource record
  707. * \return type
  708. */
  709. CARES_EXTERN ares_dns_rec_type_t ares_dns_rr_get_type(const ares_dns_rr_t *rr);
  710. /*! Retrieve the resource record class
  711. *
  712. * \param[in] rr Pointer to resource record
  713. * \return class
  714. */
  715. CARES_EXTERN ares_dns_class_t ares_dns_rr_get_class(const ares_dns_rr_t *rr);
  716. /*! Retrieve the resource record TTL
  717. *
  718. * \param[in] rr Pointer to resource record
  719. * \return TTL
  720. */
  721. CARES_EXTERN unsigned int ares_dns_rr_get_ttl(const ares_dns_rr_t *rr);
  722. /*! Set ipv4 address data type for specified resource record and key. Can
  723. * only be used on keys with datatype ARES_DATATYPE_INADDR
  724. *
  725. * \param[in] dns_rr Pointer to resource record
  726. * \param[in] key DNS Resource Record Key
  727. * \param[in] addr Pointer to ipv4 address to use.
  728. * \return ARES_SUCCESS on success
  729. */
  730. CARES_EXTERN ares_status_t ares_dns_rr_set_addr(ares_dns_rr_t *dns_rr,
  731. ares_dns_rr_key_t key,
  732. const struct in_addr *addr);
  733. /*! Set ipv6 address data type for specified resource record and key. Can
  734. * only be used on keys with datatype ARES_DATATYPE_INADDR6
  735. *
  736. * \param[in] dns_rr Pointer to resource record
  737. * \param[in] key DNS Resource Record Key
  738. * \param[in] addr Pointer to ipv6 address to use.
  739. * \return ARES_SUCCESS on success
  740. */
  741. CARES_EXTERN ares_status_t
  742. ares_dns_rr_set_addr6(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
  743. const struct ares_in6_addr *addr);
  744. /*! Set string data for specified resource record and key. Can
  745. * only be used on keys with datatype ARES_DATATYPE_STR or ARES_DATATYPE_NAME.
  746. *
  747. * \param[in] dns_rr Pointer to resource record
  748. * \param[in] key DNS Resource Record Key
  749. * \param[in] val Pointer to string to set.
  750. * \return ARES_SUCCESS on success
  751. */
  752. CARES_EXTERN ares_status_t ares_dns_rr_set_str(ares_dns_rr_t *dns_rr,
  753. ares_dns_rr_key_t key,
  754. const char *val);
  755. /*! Set 8bit unsigned integer for specified resource record and key. Can
  756. * only be used on keys with datatype ARES_DATATYPE_U8
  757. *
  758. * \param[in] dns_rr Pointer to resource record
  759. * \param[in] key DNS Resource Record Key
  760. * \param[in] val 8bit unsigned integer
  761. * \return ARES_SUCCESS on success
  762. */
  763. CARES_EXTERN ares_status_t ares_dns_rr_set_u8(ares_dns_rr_t *dns_rr,
  764. ares_dns_rr_key_t key,
  765. unsigned char val);
  766. /*! Set 16bit unsigned integer for specified resource record and key. Can
  767. * only be used on keys with datatype ARES_DATATYPE_U16
  768. *
  769. * \param[in] dns_rr Pointer to resource record
  770. * \param[in] key DNS Resource Record Key
  771. * \param[in] val 16bit unsigned integer
  772. * \return ARES_SUCCESS on success
  773. */
  774. CARES_EXTERN ares_status_t ares_dns_rr_set_u16(ares_dns_rr_t *dns_rr,
  775. ares_dns_rr_key_t key,
  776. unsigned short val);
  777. /*! Set 32bit unsigned integer for specified resource record and key. Can
  778. * only be used on keys with datatype ARES_DATATYPE_U32
  779. *
  780. * \param[in] dns_rr Pointer to resource record
  781. * \param[in] key DNS Resource Record Key
  782. * \param[in] val 32bit unsigned integer
  783. * \return ARES_SUCCESS on success
  784. */
  785. CARES_EXTERN ares_status_t ares_dns_rr_set_u32(ares_dns_rr_t *dns_rr,
  786. ares_dns_rr_key_t key,
  787. unsigned int val);
  788. /*! Set binary (BIN or BINP) data for specified resource record and key. Can
  789. * only be used on keys with datatype ARES_DATATYPE_BIN or ARES_DATATYPE_BINP.
  790. *
  791. * \param[in] dns_rr Pointer to resource record
  792. * \param[in] key DNS Resource Record Key
  793. * \param[in] val Pointer to binary data.
  794. * \param[in] len Length of binary data
  795. * \return ARES_SUCCESS on success
  796. */
  797. CARES_EXTERN ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr,
  798. ares_dns_rr_key_t key,
  799. const unsigned char *val,
  800. size_t len);
  801. /*! Add binary array value (ABINP) data for specified resource record and key.
  802. * Can only be used on keys with datatype ARES_DATATYPE_ABINP. The value will
  803. * Be added as the last element in the array.
  804. *
  805. * \param[in] dns_rr Pointer to resource record
  806. * \param[in] key DNS Resource Record Key
  807. * \param[in] val Pointer to binary data.
  808. * \param[in] len Length of binary data
  809. * \return ARES_SUCCESS on success
  810. */
  811. CARES_EXTERN ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr,
  812. ares_dns_rr_key_t key,
  813. const unsigned char *val,
  814. size_t len);
  815. /*! Delete binary array value (ABINP) data for specified resource record and
  816. * key by specified index. Can only be used on keys with datatype
  817. * ARES_DATATYPE_ABINP. The value at the index will be deleted.
  818. *
  819. * \param[in] dns_rr Pointer to resource record
  820. * \param[in] key DNS Resource Record Key
  821. * \param[in] idx Index to delete
  822. * \return ARES_SUCCESS on success
  823. */
  824. CARES_EXTERN ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr,
  825. ares_dns_rr_key_t key,
  826. size_t idx);
  827. /*! Set the option for the RR
  828. *
  829. * \param[in] dns_rr Pointer to resource record
  830. * \param[in] key DNS Resource Record Key
  831. * \param[in] opt Option record key id.
  832. * \param[out] val Optional. Value to associate with option.
  833. * \param[out] val_len Length of value passed.
  834. * \return ARES_SUCCESS on success
  835. */
  836. CARES_EXTERN ares_status_t ares_dns_rr_set_opt(ares_dns_rr_t *dns_rr,
  837. ares_dns_rr_key_t key,
  838. unsigned short opt,
  839. const unsigned char *val,
  840. size_t val_len);
  841. /*! Delete the option for the RR by id
  842. *
  843. * \param[in] dns_rr Pointer to resource record
  844. * \param[in] key DNS Resource Record Key
  845. * \param[in] opt Option record key id.
  846. * \return ARES_SUCCESS if removed, ARES_ENOTFOUND if not found
  847. */
  848. CARES_EXTERN ares_status_t ares_dns_rr_del_opt_byid(ares_dns_rr_t *dns_rr,
  849. ares_dns_rr_key_t key,
  850. unsigned short opt);
  851. /*! Retrieve a pointer to the ipv4 address. Can only be used on keys with
  852. * datatype ARES_DATATYPE_INADDR.
  853. *
  854. * \param[in] dns_rr Pointer to resource record
  855. * \param[in] key DNS Resource Record Key
  856. * \return pointer to ipv4 address or NULL on error
  857. */
  858. CARES_EXTERN const struct in_addr *
  859. ares_dns_rr_get_addr(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
  860. /*! Retrieve a pointer to the ipv6 address. Can only be used on keys with
  861. * datatype ARES_DATATYPE_INADDR6.
  862. *
  863. * \param[in] dns_rr Pointer to resource record
  864. * \param[in] key DNS Resource Record Key
  865. * \return pointer to ipv6 address or NULL on error
  866. */
  867. CARES_EXTERN const struct ares_in6_addr *
  868. ares_dns_rr_get_addr6(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
  869. /*! Retrieve a pointer to the string. Can only be used on keys with
  870. * datatype ARES_DATATYPE_STR and ARES_DATATYPE_NAME.
  871. *
  872. * \param[in] dns_rr Pointer to resource record
  873. * \param[in] key DNS Resource Record Key
  874. * \return pointer string or NULL on error
  875. */
  876. CARES_EXTERN const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr,
  877. ares_dns_rr_key_t key);
  878. /*! Retrieve an 8bit unsigned integer. Can only be used on keys with
  879. * datatype ARES_DATATYPE_U8.
  880. *
  881. * \param[in] dns_rr Pointer to resource record
  882. * \param[in] key DNS Resource Record Key
  883. * \return 8bit unsigned integer
  884. */
  885. CARES_EXTERN unsigned char ares_dns_rr_get_u8(const ares_dns_rr_t *dns_rr,
  886. ares_dns_rr_key_t key);
  887. /*! Retrieve an 16bit unsigned integer. Can only be used on keys with
  888. * datatype ARES_DATATYPE_U16.
  889. *
  890. * \param[in] dns_rr Pointer to resource record
  891. * \param[in] key DNS Resource Record Key
  892. * \return 16bit unsigned integer
  893. */
  894. CARES_EXTERN unsigned short ares_dns_rr_get_u16(const ares_dns_rr_t *dns_rr,
  895. ares_dns_rr_key_t key);
  896. /*! Retrieve an 32bit unsigned integer. Can only be used on keys with
  897. * datatype ARES_DATATYPE_U32.
  898. *
  899. * \param[in] dns_rr Pointer to resource record
  900. * \param[in] key DNS Resource Record Key
  901. * \return 32bit unsigned integer
  902. */
  903. CARES_EXTERN unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr,
  904. ares_dns_rr_key_t key);
  905. /*! Retrieve a pointer to the binary data. Can only be used on keys with
  906. * datatype ARES_DATATYPE_BIN, ARES_DATATYPE_BINP, or ARES_DATATYPE_ABINP.
  907. * If BINP or ABINP, the data is guaranteed to have a NULL terminator which
  908. * is NOT included in the length.
  909. *
  910. * \param[in] dns_rr Pointer to resource record
  911. * \param[in] key DNS Resource Record Key
  912. * \param[out] len Length of binary data returned
  913. * \return pointer binary data or NULL on error
  914. */
  915. CARES_EXTERN const unsigned char *
  916. ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
  917. size_t *len);
  918. /*! Retrieve the count of the array of stored binary values. Can only be used on
  919. * keys with datatype ARES_DATATYPE_ABINP.
  920. *
  921. * \param[in] dns_rr Pointer to resource record
  922. * \param[in] key DNS Resource Record Key
  923. * \return count of values
  924. */
  925. CARES_EXTERN size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr,
  926. ares_dns_rr_key_t key);
  927. /*! Retrieve a pointer to the binary array data from the specified index. Can
  928. * only be used on keys with datatype ARES_DATATYPE_ABINP. If ABINP, the data
  929. * is guaranteed to have a NULL terminator which is NOT included in the length.
  930. * If want all array membersconcatenated, may use ares_dns_rr_get_bin()
  931. * instead.
  932. *
  933. * \param[in] dns_rr Pointer to resource record
  934. * \param[in] key DNS Resource Record Key
  935. * \param[in] idx Index of value to retrieve
  936. * \param[out] len Length of binary data returned
  937. * \return pointer binary data or NULL on error
  938. */
  939. CARES_EXTERN const unsigned char *
  940. ares_dns_rr_get_abin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
  941. size_t idx, size_t *len);
  942. /*! Retrieve the number of options stored for the RR.
  943. *
  944. * \param[in] dns_rr Pointer to resource record
  945. * \param[in] key DNS Resource Record Key
  946. * \return count, or 0 if none.
  947. */
  948. CARES_EXTERN size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
  949. ares_dns_rr_key_t key);
  950. /*! Retrieve the option for the RR by index.
  951. *
  952. * \param[in] dns_rr Pointer to resource record
  953. * \param[in] key DNS Resource Record Key
  954. * \param[in] idx Index of option record
  955. * \param[out] val Optional. Pointer passed by reference to hold value.
  956. * Options may not have values. Value if returned is
  957. * guaranteed to be NULL terminated, however in most
  958. * cases it is not printable.
  959. * \param[out] val_len Optional. Pointer passed by reference to hold value
  960. * length.
  961. * \return option key/id on success, 65535 on misuse.
  962. */
  963. CARES_EXTERN unsigned short
  964. ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
  965. size_t idx, const unsigned char **val, size_t *val_len);
  966. /*! Retrieve the option for the RR by the option key/id.
  967. *
  968. * \param[in] dns_rr Pointer to resource record
  969. * \param[in] key DNS Resource Record Key
  970. * \param[in] opt Option record key id (this is not the index).
  971. * \param[out] val Optional. Pointer passed by reference to hold value.
  972. * Options may not have values. Value if returned is
  973. * guaranteed to be NULL terminated, however in most cases
  974. * it is not printable.
  975. * \param[out] val_len Optional. Pointer passed by reference to hold value
  976. * length.
  977. * \return ARES_TRUE on success, ARES_FALSE on misuse.
  978. */
  979. CARES_EXTERN ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
  980. ares_dns_rr_key_t key,
  981. unsigned short opt,
  982. const unsigned char **val,
  983. size_t *val_len);
  984. /*! Parse a complete DNS message.
  985. *
  986. * \param[in] buf pointer to bytes to be parsed
  987. * \param[in] buf_len Length of buf provided
  988. * \param[in] flags Flags dictating how the message should be parsed.
  989. * \param[out] dnsrec Pointer passed by reference for a new DNS record object
  990. * that must be ares_dns_record_destroy()'d by caller.
  991. * \return ARES_SUCCESS on success
  992. */
  993. CARES_EXTERN ares_status_t ares_dns_parse(const unsigned char *buf,
  994. size_t buf_len, unsigned int flags,
  995. ares_dns_record_t **dnsrec);
  996. /*! Write a complete DNS message
  997. *
  998. * \param[in] dnsrec Pointer to initialized and filled DNS record object.
  999. * \param[out] buf Pointer passed by reference to be filled in with with
  1000. * DNS message. Must be ares_free()'d by caller.
  1001. * \param[out] buf_len Length of returned buffer containing DNS message.
  1002. * \return ARES_SUCCESS on success
  1003. */
  1004. CARES_EXTERN ares_status_t ares_dns_write(const ares_dns_record_t *dnsrec,
  1005. unsigned char **buf, size_t *buf_len);
  1006. /*! Duplicate a complete DNS message. This does not copy internal members
  1007. * (such as the ttl decrement capability).
  1008. *
  1009. * \param[in] dnsrec Pointer to initialized and filled DNS record object.
  1010. * \return duplicted DNS record object, or NULL on out of memory.
  1011. */
  1012. CARES_EXTERN ares_dns_record_t *
  1013. ares_dns_record_duplicate(const ares_dns_record_t *dnsrec);
  1014. /*! @} */
  1015. #ifdef __cplusplus
  1016. }
  1017. #endif
  1018. #endif /* __ARES_DNS_RECORD_H */