Mistake on this page?
Report an issue in GitHub or email us
dns.h
Go to the documentation of this file.
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 #include "lwip/err.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 struct dns_server_interface {
54  char interface_name [INTERFACE_NAME_MAX_SIZE];
55  ip_addr_t dns_servers[DNS_MAX_SERVERS];
56  struct dns_server_interface *next;
57 };
58 
59 /** DNS timer period */
60 #define DNS_TMR_INTERVAL 1000
61 
62 /* DNS resolve types: */
63 #define LWIP_DNS_ADDRTYPE_IPV4 0
64 #define LWIP_DNS_ADDRTYPE_IPV6 1
65 #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
66 #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
67 #if LWIP_IPV4 && LWIP_IPV6
68 #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
69 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6
70 #endif
71 #elif LWIP_IPV4
72 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4
73 #else
74 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6
75 #endif
76 
77 #if DNS_LOCAL_HOSTLIST
78 /** struct used for local host-list */
79 struct local_hostlist_entry {
80  /** static hostname */
81  const char *name;
82  /** static host address in network byteorder */
83  ip_addr_t addr;
84  struct local_hostlist_entry *next;
85 };
86 #define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL}
87 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
88 #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
89 #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH
90 #endif
91 #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
92 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
93 #endif /* DNS_LOCAL_HOSTLIST */
94 
95 #if LWIP_IPV4
96 extern const ip_addr_t dns_mquery_v4group;
97 #endif /* LWIP_IPV4 */
98 #if LWIP_IPV6
99 extern const ip_addr_t dns_mquery_v6group;
100 #endif /* LWIP_IPV6 */
101 
102 /** Callback which is invoked when a hostname is found.
103  * A function of this type must be implemented by the application using the DNS resolver.
104  * @param name pointer to the name that was looked up.
105  * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname,
106  * or NULL if the name could not be found (or on any other error).
107  * @param callback_arg a user-specified callback argument passed to dns_gethostbyname
108 */
109 typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
110 
111 void dns_init(void);
112 void dns_tmr(void);
113 void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver, struct netif *netif);
114 const ip_addr_t* dns_getserver(u8_t numdns, const char *interface_name);
115 void dns_add_interface_server(u8_t numdns, const char *interface_name, const ip_addr_t *dnsserver);
116 void dns_remove_interface_servers(const char *interface_name);
117 const ip_addr_t* dns_get_interface_server(u8_t numdns, const char *interface_name);
118 err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr,
119  dns_found_callback found, void *callback_arg);
120 err_t dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,
121  dns_found_callback found, void *callback_arg,
122  u8_t dns_addrtype);
123 
124 
125 #if DNS_LOCAL_HOSTLIST
126 size_t dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg);
127 err_t dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype);
128 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
129 int dns_local_removehost(const char *hostname, const ip_addr_t *addr);
130 err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr);
131 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
132 #endif /* DNS_LOCAL_HOSTLIST */
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif /* LWIP_DNS */
139 
140 #endif /* LWIP_HDR_DNS_H */
lwIP Options Configuration
#define DNS_MAX_SERVERS
The maximum of DNS servers The first server can be initialized automatically by defining DNS_SERVER_A...
Definition: opt.h:1113
lwIP Error codes
Generic data structure used for all lwIP network interfaces.
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:235
IP address API (common IPv4 and IPv6)
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.