PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/include/nuttx/net/dns.h

https://bitbucket.org/hg42/nuttx
C Header | 222 lines | 108 code | 33 blank | 81 comment | 0 complexity | a4643cebe6f7858253ff49b99f826cb7 MD5 | raw file
Possible License(s): 0BSD
  1. /****************************************************************************
  2. * include/nuttx/net/dns.h
  3. * DNS resolver code header file.
  4. *
  5. * Copyright (C) 2007-2009, 2011-2012, 2014-2015 Gregory Nutt. All rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Inspired by/based on uIP logic by Adam Dunkels:
  9. *
  10. * Copyright (c) 2002-2003, Adam Dunkels. All rights reserved.
  11. * Author Adam Dunkels <adam@dunkels.com>
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. The name of the author may not be used to endorse or promote
  22. * products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  27. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  29. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  31. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  33. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ****************************************************************************/
  38. #ifndef __INCLUDE_NUTTX_NET_DNS_H
  39. #define __INCLUDE_NUTTX_NET_DNS_H
  40. /****************************************************************************
  41. * Included Files
  42. ****************************************************************************/
  43. #include <nuttx/config.h>
  44. #include <sys/socket.h>
  45. #include <netinet/in.h>
  46. #include <nuttx/net/netconfig.h>
  47. /****************************************************************************
  48. * Pre-processor Definitions
  49. ****************************************************************************/
  50. /* DNS classes */
  51. #define DNS_CLASS_IN 1 /* RFC 1035 Internet */
  52. #define DNS_CLASS CH 3 /* N/A Chaos */
  53. #define DNS_CLASS_HS 4 /* N/A Hesiod */
  54. #define DNS_CLASS_QNONE 254 /* RFC 2136 QCLASS NONE */
  55. #define DNS_CLASS_QANY 255 /* RFC 1035 QCLASS ANY */
  56. /* DNS resource record types */
  57. #define DNS_RECTYPE_A 1 /* RFC 1035 IPv4 ddress record */
  58. #define DNS_RECTYPE_AAAA 28 /* RFC 3596 IPv6 address record */
  59. #define DNS_RECTYPE_AFSDB 18 /* RFC 1183 AFS database record */
  60. #define DNS_RECTYPE_APL 42 /* RFC 3123 Address Prefix List */
  61. #define DNS_RECTYPE_CAA 257 /* RFC 6844 Certification Authority Authorization */
  62. #define DNS_RECTYPE_CDNSKEY 60 /* RFC 7344 Child DNSKEY */
  63. #define DNS_RECTYPE_CDS 59 /* RFC 7344 Child DS */
  64. #define DNS_RECTYPE_CERT 37 /* RFC 4398 Certificate record */
  65. #define DNS_RECTYPE_CNAME 5 /* RFC 1035 Canonical name record */
  66. #define DNS_RECTYPE_DHCID 49 /* RFC 4701 DHCP identifier */
  67. #define DNS_RECTYPE_DLV 32769 /* RFC 4431 DNSSEC Lookaside Validation record */
  68. #define DNS_RECTYPE_DNAME 39 /* RFC 2672 Delegation Name */
  69. #define DNS_RECTYPE_DNSKEY 48 /* RFC 4034 DNS Key record */
  70. #define DNS_RECTYPE_DS 43 /* RFC 4034 Delegation signer */
  71. #define DNS_RECTYPE_HIP 55 /* RFC 5205 Host Identity Protocol */
  72. #define DNS_RECTYPE_IPSECKEY 45 /* RFC 4025 IPsec Key */
  73. #define DNS_RECTYPE_KEY 25 /* RFC 2535 and RFC 2930 Key record */
  74. #define DNS_RECTYPE_KX 36 /* RFC 2230 Key eXchanger record */
  75. #define DNS_RECTYPE_LOC 29 /* RFC 1876 Location record */
  76. #define DNS_RECTYPE_MX 15 /* RFC 1035 Mail exchange record */
  77. #define DNS_RECTYPE_NAPTR 35 /* RFC 3403 Naming Authority Pointer */
  78. #define DNS_RECTYPE_NS 2 /* RFC 1035 Name server record */
  79. #define DNS_RECTYPE_NSEC 47 /* RFC 4034 Next-Secure record */
  80. #define DNS_RECTYPE_NSEC3 50 /* RFC 5155 NSEC record version 3 */
  81. #define DNS_RECTYPE_NSEC3PARAM 51 /* RFC 5155 NSEC3 parameters */
  82. #define DNS_RECTYPE_PTR 12 /* RFC 1035 Pointer record */
  83. #define DNS_RECTYPE_RRSIG 46 /* RFC 4034 DNSSEC signature */
  84. #define DNS_RECTYPE_RP 17 /* RFC 1183 Responsible person */
  85. #define DNS_RECTYPE_SIG 24 /* RFC 2535 Signature */
  86. #define DNS_RECTYPE_SOA 6 /* RFC 1035 and RFC 2308 Start of [a zone of] authority record */
  87. #define DNS_RECTYPE_SRV 33 /* RFC 2782 Service locator */
  88. #define DNS_RECTYPE_SSHFP 44 /* RFC 4255 SSH Public Key Fingerprint */
  89. #define DNS_RECTYPE_TA 32768 /* N/A DNSSEC Trust Authorities */
  90. #define DNS_RECTYPE_TKEY 249 /* RFC 2930 Secret key record */
  91. #define DNS_RECTYPE_TLSA 52 /* RFC 6698 TLSA certificate association */
  92. #define DNS_RECTYPE_TSIG 250 /* RFC 2845 Transaction Signature */
  93. #define DNS_RECTYPE_TXT 16 /* RFC 1035[1] Text record */
  94. #define DNS_RECTYPE_ALL 255 /* RFC 1035 All cached records */
  95. #define DNS_RECTYPE_AXFR 252 /* RFC 1035 Authoritative Zone Transfer */
  96. #define DNS_RECTYPE_IXFR 251 /* RFC 1996 Incremental Zone Transfer */
  97. #define DNS_RECTYPE_OPT 41 /* RFC 6891 Option */
  98. /* Flag1 bit definitions */
  99. #define DNS_FLAG1_RESPONSE 0x80
  100. #define DNS_FLAG1_OPCODE_STATUS 0x10
  101. #define DNS_FLAG1_OPCODE_INVERSE 0x08
  102. #define DNS_FLAG1_OPCODE_STANDARD 0x00
  103. #define DNS_FLAG1_AUTHORATIVE 0x04
  104. #define DNS_FLAG1_TRUNC 0x02
  105. #define DNS_FLAG1_RD 0x01
  106. /* Flag2 bit definitions */
  107. #define DNS_FLAG2_RA 0x80
  108. #define DNS_FLAG2_ERR_MASK 0x0f
  109. #define DNS_FLAG2_ERR_NONE 0x00
  110. #define DNS_FLAG2_ERR_NAME 0x03
  111. /* Default DNS server port number */
  112. #define DNS_DEFAULT_PORT 53
  113. /****************************************************************************
  114. * Public Type Definitions
  115. ****************************************************************************/
  116. /* The DNS message header */
  117. struct dns_header_s
  118. {
  119. uint16_t id;
  120. uint8_t flags1;
  121. uint8_t flags2;
  122. uint16_t numquestions;
  123. uint16_t numanswers;
  124. uint16_t numauthrr;
  125. uint16_t numextrarr;
  126. };
  127. /* The DNS answer message structure */
  128. struct dns_answer_s
  129. {
  130. uint16_t type;
  131. uint16_t class;
  132. uint16_t ttl[2];
  133. uint16_t len;
  134. union
  135. {
  136. #ifdef CONFIG_NET_IPv4
  137. struct in_addr ipv4;
  138. #endif
  139. #ifdef CONFIG_NET_IPv6
  140. struct in6_addr ipv6;
  141. #endif
  142. } u;
  143. };
  144. /* The type of the callback from dns_foreach_nameserver() */
  145. typedef CODE int (*dns_callback_t)(FAR void *arg,
  146. FAR struct sockaddr *addr,
  147. FAR socklen_t addrlen);
  148. /****************************************************************************
  149. * Public Function Prototypes
  150. ****************************************************************************/
  151. #undef EXTERN
  152. #if defined(__cplusplus)
  153. #define EXTERN extern "C"
  154. extern "C"
  155. {
  156. #else
  157. #define EXTERN extern
  158. #endif
  159. /****************************************************************************
  160. * Name: dns_add_nameserver
  161. *
  162. * Description:
  163. * Configure a DNS server to use for queries. Set the port number to zero
  164. * to use the default DNS server port.
  165. *
  166. ****************************************************************************/
  167. int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen);
  168. /****************************************************************************
  169. * Name: dns_del_nameserver
  170. *
  171. * Description:
  172. * Remove a DNS server so it is no longer available for further use.
  173. *
  174. ****************************************************************************/
  175. /* REVISIT: Not implemented */
  176. /****************************************************************************
  177. * Name: dns_foreach_nameserver
  178. *
  179. * Description:
  180. * Traverse each nameserver entry in the resolv.conf file and perform the
  181. * the provided callback.
  182. *
  183. ****************************************************************************/
  184. int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg);
  185. #undef EXTERN
  186. #if defined(__cplusplus)
  187. }
  188. #endif
  189. #endif /* __INCLUDE_NUTTX_NET_DNS_H */