提交 | 用户 | age
|
a7db3c
|
1 |
//*****************************************************************************
|
Q |
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 dependens on <stdio.h>
|
|
58 |
*/
|
|
59 |
//#define _DNS_DEBUG_
|
|
60 |
|
|
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 16 // for example "www.google.com"
|
|
68 |
|
|
69 |
#define MAX_DNS_RETRY 2 ///< Requery Count
|
|
70 |
#define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.
|
|
71 |
|
|
72 |
#define IPPORT_DOMAIN 53 ///< DNS server port number
|
|
73 |
|
|
74 |
#define DNS_MSG_ID 0x1122 ///< ID for DNS message. You can be modifyed it any number
|
|
75 |
/*
|
|
76 |
* @brief DNS process initialize
|
|
77 |
* @param s : Socket number for DNS
|
|
78 |
* @param buf : Buffer for DNS message
|
|
79 |
*/
|
|
80 |
void DNS_init(uint8_t s, uint8_t * buf);
|
|
81 |
|
|
82 |
/*
|
|
83 |
* @brief DNS process
|
|
84 |
* @details Send DNS query and receive DNS response
|
|
85 |
* @param dns_ip : DNS server ip
|
|
86 |
* @param name : Domain name to be queryed
|
|
87 |
* @param ip_from_dns : IP address from DNS server
|
|
88 |
* @return -1 : failed. @ref MAX_DOMIN_NAME is too small \n
|
|
89 |
* 0 : failed (Timeout or Parse error)\n
|
|
90 |
* 1 : success
|
|
91 |
* @note This funtion blocks until success or fail. max time = @ref MAX_DNS_RETRY * @ref DNS_WAIT_TIME
|
|
92 |
*/
|
|
93 |
int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
|
|
94 |
|
|
95 |
/*
|
|
96 |
* @brief DNS 1s Tick Timer handler
|
|
97 |
* @note SHOULD BE register to your system 1s Tick timer handler
|
|
98 |
*/
|
|
99 |
void DNS_time_handler(void);
|
|
100 |
|
|
101 |
#endif /* _DNS_H_ */
|