7 * lwip DNS resolver header file.
9 * Author: Jim Pettinato
12 * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. The name of the author may not be used to endorse or promote
23 * products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
27 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
30 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #ifndef LWIP_HDR_DNS_H
40 #define LWIP_HDR_DNS_H
46 #include "lwip/ip_addr.h"
52 /** DNS timer period */
53 #define DNS_TMR_INTERVAL 1000
55 /* DNS resolve types: */
56 #define LWIP_DNS_ADDRTYPE_IPV4 0
57 #define LWIP_DNS_ADDRTYPE_IPV6 1
58 #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
59 #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
60 #if LWIP_IPV4 && LWIP_IPV6
61 #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
62 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6
65 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4
67 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6
70 #if DNS_LOCAL_HOSTLIST
71 /** struct used for local host-list */
72 struct local_hostlist_entry {
73 /** static hostname */
75 /** static host address in network byteorder */
77 struct local_hostlist_entry *next;
79 #define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL}
80 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
81 #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
82 #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH
84 #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
85 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
86 #endif /* DNS_LOCAL_HOSTLIST */
89 extern const ip_addr_t dns_mquery_v4group;
90 #endif /* LWIP_IPV4 */
92 extern const ip_addr_t dns_mquery_v6group;
93 #endif /* LWIP_IPV6 */
95 /** Callback which is invoked when a hostname is found.
96 * A function of this type must be implemented by the application using the DNS resolver.
97 * There is support for two types of callbacks, invoked when a hostname is found.
98 * @note dns_found_callbackX type is used as a catch-all type, that needs to be cast
99 * to either dns_found_callback or dns_found_callback_multi.
101 * dns_found_callback returns at most a single IP address, even if the DNS server response contained several addresses
102 * (this callback is used to maintain backward compatibility with dns_gethostbyname)
103 * @param name pointer to the name that was looked up.
104 * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname,
105 * or NULL if the name could not be found (or on any other error).
106 * @param callback_arg a user-specified callback argument passed to dns_gethostbyname.
108 * dns_found_callback_multi returns up to numipaddrs of all the IP addresses returned by the DSN server
109 * (this callback is invoked by calling dns_gethostbyname_multi)
110 * @param name pointer to the name that was looked up.
111 * @param ipaddrs pointer to an ip_addr_t array containing the IP addresses of the hostname
112 * @note This pointer is never NULL, instead numipaddrs is set to zero.
113 * @param numipaddrs size of the ipaddrs array.
114 * @param callback_arg a user-specified callback argument passed to dns_gethostbyname_multi.
117 typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
119 #if DNS_MAX_ADDRS_PER_NAME > 1
120 typedef void (*dns_found_callbackX)(void);
121 typedef void (*dns_found_callback_multi)(const char *name, const ip_addr_t *ipaddrs, u8_t numipaddrs, void *callback_arg);
122 #define LWIP_DNS_FOUND_CALLBACK_TYPE dns_found_callbackX
123 #else // DNS_MAX_ADDRS_PER_NAME <= 1
124 #define LWIP_DNS_FOUND_CALLBACK_TYPE dns_found_callback
125 #endif // DNS_MAX_ADDRS_PER_NAME <= 1
129 void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver);
130 const ip_addr_t* dns_getserver(u8_t numdns);
131 err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr,
132 LWIP_DNS_FOUND_CALLBACK_TYPE found, void *callback_arg);
133 err_t dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,
134 LWIP_DNS_FOUND_CALLBACK_TYPE found, void *callback_arg,
137 #if DNS_LOCAL_HOSTLIST
138 size_t dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg);
139 err_t dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype);
140 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
144 void dns_setserver(u8_t numdns, ip_addr_t *dnsserver);
145 ip_addr_t dns_getserver(u8_t numdns);
147 #if DNS_MAX_ADDRS_PER_NAME > 1
148 err_t dns_gethostbyname_multi(const char *hostname, ip_addr_t *ipaddrs, u8_t *numipaddrs,
149 dns_found_callback_multi found, void *callback_arg);
150 #endif // DNS_MAX_ADDRS_PER_NAME > 1
152 int dns_local_removehost(const char *hostname, const ip_addr_t *addr);
153 err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr);
154 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
155 #endif /* DNS_LOCAL_HOSTLIST */
157 u8_t dns_cancel(LWIP_DNS_FOUND_CALLBACK_TYPE found, void *callback_arg);
160 u8_t dns_expire_asking_entries(void);
161 u8_t dns_flush_cache(void);
162 #endif // LWIP_TEST_CODE
168 #endif /* LWIP_DNS */
169 #endif /* LWIP_HDR_DNS_H */