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