dns.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <stdint.h>
  53. /*
  54. * @brief Define it for Debug & Monitor DNS processing.
  55. * @note If defined, it dependens on <stdio.h>
  56. */
  57. //#define _DNS_DEBUG_
  58. #define MAX_DNS_BUF_SIZE 256 ///< maximum size of DNS buffer. */
  59. /*
  60. * @brief Maxium length of your queried Domain name
  61. * @todo SHOULD BE defined it equal as or greater than your Domain name lenght + null character(1)
  62. * @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
  63. */
  64. #define MAX_DOMAIN_NAME 16 // for example "www.google.com"
  65. #define MAX_DNS_RETRY 2 ///< Requery Count
  66. #define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.
  67. #define IPPORT_DOMAIN 53 ///< DNS server port number
  68. #define DNS_MSG_ID 0x1122 ///< ID for DNS message. You can be modifyed it any number
  69. /*
  70. * @brief DNS process initialize
  71. * @param s : Socket number for DNS
  72. * @param buf : Buffer for DNS message
  73. */
  74. void DNS_init(uint8_t s, uint8_t * buf);
  75. /*
  76. * @brief DNS process
  77. * @details Send DNS query and receive DNS response
  78. * @param dns_ip : DNS server ip
  79. * @param name : Domain name to be queryed
  80. * @param ip_from_dns : IP address from DNS server
  81. * @return -1 : failed. @ref MAX_DOMIN_NAME is too small \n
  82. * 0 : failed (Timeout or Parse error)\n
  83. * 1 : success
  84. * @note This funtion blocks until success or fail. max time = @ref MAX_DNS_RETRY * @ref DNS_WAIT_TIME
  85. */
  86. int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
  87. /*
  88. * @brief DNS 1s Tick Timer handler
  89. * @note SHOULD BE register to your system 1s Tick timer handler
  90. */
  91. void DNS_time_handler(void);
  92. #endif /* _DNS_H_ */