1/**
2 * @file
3 * DNS API
4 */
5
6/**
7 * lwip DNS resolver header file.
8
9 * Author: Jim Pettinato
10 *   April 2007
11
12 * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
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
24 *    written permission.
25 *
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.
37 */
38
39#ifndef LWIP_HDR_DNS_H
40#define LWIP_HDR_DNS_H
41
42#include "lwip/opt.h"
43
44#if LWIP_DNS
45
46#include "lwip/ip_addr.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/** DNS timer period */
53#define DNS_TMR_INTERVAL          1000
54
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
63#endif
64#elif LWIP_IPV4
65#define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV4
66#else
67#define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV6
68#endif
69
70#if DNS_LOCAL_HOSTLIST
71/** struct used for local host-list */
72struct local_hostlist_entry {
73  /** static hostname */
74  const char *name;
75  /** static host address in network byteorder */
76  ip_addr_t addr;
77  struct local_hostlist_entry *next;
78};
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
83#endif
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 */
87
88#if LWIP_IPV4
89extern const ip_addr_t dns_mquery_v4group;
90#endif /* LWIP_IPV4 */
91#if LWIP_IPV6
92extern const ip_addr_t dns_mquery_v6group;
93#endif /* LWIP_IPV6 */
94
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 * @param name pointer to the name that was looked up.
98 * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname,
99 *        or NULL if the name could not be found (or on any other error).
100 * @param callback_arg a user-specified callback argument passed to dns_gethostbyname
101*/
102typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
103
104void             dns_init(void);
105void             dns_tmr(void);
106void             dns_setserver(u8_t numdns, const ip_addr_t *dnsserver);
107const ip_addr_t* dns_getserver(u8_t numdns);
108err_t            dns_gethostbyname(const char *hostname, ip_addr_t *addr,
109                                   dns_found_callback found, void *callback_arg);
110err_t            dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,
111                                   dns_found_callback found, void *callback_arg,
112                                   u8_t dns_addrtype);
113
114
115#if DNS_LOCAL_HOSTLIST
116size_t         dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg);
117err_t          dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype);
118#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
119int            dns_local_removehost(const char *hostname, const ip_addr_t *addr);
120err_t          dns_local_addhost(const char *hostname, const ip_addr_t *addr);
121#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
122#endif /* DNS_LOCAL_HOSTLIST */
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif /* LWIP_DNS */
129
130#endif /* LWIP_HDR_DNS_H */
131