dns.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //*****************************************************************************
  2. //
  3. //! \file dns.h
  4. //! \brief DNS APIs Header file.
  5. //! \details Send DNS query & Receive DNS reponse.
  6. //! \version 1.1.0
  7. //! \date 2013/11/18
  8. //! \par Revision history
  9. //! <2013/10/21> 1st Release
  10. //! <2013/12/20> V1.1.0
  11. //! 1. Remove secondary DNS server in DNS_run
  12. //! If 1st DNS_run failed, call DNS_run with 2nd DNS again
  13. //! 2. DNS_timerHandler -> DNS_time_handler
  14. //! 3. Move the no reference define to dns.c
  15. //! 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c
  16. //! <2013/12/20> V1.1.0
  17. //!
  18. //! \author Eric Jung & MidnightCow
  19. //! \copyright
  20. //!
  21. //! Copyright (c) 2013, WIZnet Co., LTD.
  22. //! All rights reserved.
  23. //!
  24. //! Redistribution and use in source and binary forms, with or without
  25. //! modification, are permitted provided that the following conditions
  26. //! are met:
  27. //!
  28. //! * Redistributions of source code must retain the above copyright
  29. //! notice, this list of conditions and the following disclaimer.
  30. //! * Redistributions in binary form must reproduce the above copyright
  31. //! notice, this list of conditions and the following disclaimer in the
  32. //! documentation and/or other materials provided with the distribution.
  33. //! * Neither the name of the <ORGANIZATION> nor the names of its
  34. //! contributors may be used to endorse or promote products derived
  35. //! from this software without specific prior written permission.
  36. //!
  37. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  38. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  41. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  42. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  43. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  44. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  45. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  47. //! THE POSSIBILITY OF SUCH DAMAGE.
  48. //
  49. //*****************************************************************************
  50. #ifndef _DNS_H_
  51. #define _DNS_H_
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. #include <stdint.h>
  56. /*
  57. * @brief Define it for Debug & Monitor DNS processing.
  58. * @note If defined, it dependens on <stdio.h>
  59. */
  60. //#define _DNS_DEBUG_
  61. #define MAX_DNS_BUF_SIZE 256 ///< maximum size of DNS buffer. */
  62. /*
  63. * @brief Maxium length of your queried Domain name
  64. * @todo SHOULD BE defined it equal as or greater than your Domain name lenght + null character(1)
  65. * @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
  66. */
  67. #define MAX_DOMAIN_NAME 128 // for example "www.google.com"
  68. #define MAX_DNS_RETRY 2 ///< Requery Count
  69. #define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.
  70. #define IPPORT_DOMAIN 53 ///< DNS server port number
  71. #define DNS_MSG_ID 0x1122 ///< ID for DNS message. You can be modifyed it any number
  72. /*
  73. * @brief DNS process initialize
  74. * @param s : Socket number for DNS
  75. * @param buf : Buffer for DNS message
  76. */
  77. void DNS_init(uint8_t s, uint8_t * buf);
  78. /*
  79. * @brief DNS process
  80. * @details Send DNS query and receive DNS response
  81. * @param dns_ip : DNS server ip
  82. * @param name : Domain name to be queryed
  83. * @param ip_from_dns : IP address from DNS server
  84. * @return -1 : failed. @ref MAX_DOMIN_NAME is too small \n
  85. * 0 : failed (Timeout or Parse error)\n
  86. * 1 : success
  87. * @note This funtion blocks until success or fail. max time = @ref MAX_DNS_RETRY * @ref DNS_WAIT_TIME
  88. */
  89. int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
  90. /*
  91. * @brief DNS 1s Tick Timer handler
  92. * @note SHOULD BE register to your system 1s Tick timer handler
  93. */
  94. void DNS_time_handler(void);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* _DNS_H_ */