The Pedigree Project  0.1
dns.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
58 #ifndef LWIP_HDR_DNS_H
59 #define LWIP_HDR_DNS_H
60 
61 #include "lwip/opt.h"
62 
63 #if LWIP_DNS
64 
65 #include "lwip/ip_addr.h"
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
72 #define DNS_TMR_INTERVAL 1000
73 
74 /* DNS resolve types: */
75 #define LWIP_DNS_ADDRTYPE_IPV4 0
76 #define LWIP_DNS_ADDRTYPE_IPV6 1
77 #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
78 #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
79 #if LWIP_IPV4 && LWIP_IPV6
80 #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
81 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6
82 #endif
83 #elif LWIP_IPV4
84 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4
85 #else
86 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6
87 #endif
88 
89 #if DNS_LOCAL_HOSTLIST
90 
91 struct local_hostlist_entry {
93  const char *name;
95  ip_addr_t addr;
96  struct local_hostlist_entry *next;
97 };
98 #define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL}
99 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
100 #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
101 #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH
102 #endif
103 #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
104 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
105 #endif /* DNS_LOCAL_HOSTLIST */
106 
107 #if LWIP_IPV4
108 extern const ip_addr_t dns_mquery_v4group;
109 #endif /* LWIP_IPV4 */
110 #if LWIP_IPV6
111 extern const ip_addr_t dns_mquery_v6group;
112 #endif /* LWIP_IPV6 */
113 
121 typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
122 
123 void dns_init(void);
124 void dns_tmr(void);
125 void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver);
126 const ip_addr_t* dns_getserver(u8_t numdns);
127 err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr,
128  dns_found_callback found, void *callback_arg);
129 err_t dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,
130  dns_found_callback found, void *callback_arg,
131  u8_t dns_addrtype);
132 
133 
134 #if DNS_LOCAL_HOSTLIST
135 size_t dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg);
136 err_t dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype);
137 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
138 int dns_local_removehost(const char *hostname, const ip_addr_t *addr);
139 err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr);
140 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
141 #endif /* DNS_LOCAL_HOSTLIST */
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* LWIP_DNS */
148 
149 #endif /* LWIP_HDR_DNS_H */
s8_t err_t
Definition: err.h:76