1*5d5fbe79SDavid van Moolenbroek /** 2*5d5fbe79SDavid van Moolenbroek * @file 3*5d5fbe79SDavid van Moolenbroek * DNS API 4*5d5fbe79SDavid van Moolenbroek */ 5*5d5fbe79SDavid van Moolenbroek 6*5d5fbe79SDavid van Moolenbroek /** 7*5d5fbe79SDavid van Moolenbroek * lwip DNS resolver header file. 8*5d5fbe79SDavid van Moolenbroek 9*5d5fbe79SDavid van Moolenbroek * Author: Jim Pettinato 10*5d5fbe79SDavid van Moolenbroek * April 2007 11*5d5fbe79SDavid van Moolenbroek 12*5d5fbe79SDavid van Moolenbroek * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels. 13*5d5fbe79SDavid van Moolenbroek * 14*5d5fbe79SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without 15*5d5fbe79SDavid van Moolenbroek * modification, are permitted provided that the following conditions 16*5d5fbe79SDavid van Moolenbroek * are met: 17*5d5fbe79SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright 18*5d5fbe79SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer. 19*5d5fbe79SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright 20*5d5fbe79SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the 21*5d5fbe79SDavid van Moolenbroek * documentation and/or other materials provided with the distribution. 22*5d5fbe79SDavid van Moolenbroek * 3. The name of the author may not be used to endorse or promote 23*5d5fbe79SDavid van Moolenbroek * products derived from this software without specific prior 24*5d5fbe79SDavid van Moolenbroek * written permission. 25*5d5fbe79SDavid van Moolenbroek * 26*5d5fbe79SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 27*5d5fbe79SDavid van Moolenbroek * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28*5d5fbe79SDavid van Moolenbroek * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29*5d5fbe79SDavid van Moolenbroek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 30*5d5fbe79SDavid van Moolenbroek * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31*5d5fbe79SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 32*5d5fbe79SDavid van Moolenbroek * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33*5d5fbe79SDavid van Moolenbroek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 34*5d5fbe79SDavid van Moolenbroek * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35*5d5fbe79SDavid van Moolenbroek * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36*5d5fbe79SDavid van Moolenbroek * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37*5d5fbe79SDavid van Moolenbroek */ 38*5d5fbe79SDavid van Moolenbroek 39*5d5fbe79SDavid van Moolenbroek #ifndef LWIP_HDR_DNS_H 40*5d5fbe79SDavid van Moolenbroek #define LWIP_HDR_DNS_H 41*5d5fbe79SDavid van Moolenbroek 42*5d5fbe79SDavid van Moolenbroek #include "lwip/opt.h" 43*5d5fbe79SDavid van Moolenbroek 44*5d5fbe79SDavid van Moolenbroek #if LWIP_DNS 45*5d5fbe79SDavid van Moolenbroek 46*5d5fbe79SDavid van Moolenbroek #include "lwip/ip_addr.h" 47*5d5fbe79SDavid van Moolenbroek 48*5d5fbe79SDavid van Moolenbroek #ifdef __cplusplus 49*5d5fbe79SDavid van Moolenbroek extern "C" { 50*5d5fbe79SDavid van Moolenbroek #endif 51*5d5fbe79SDavid van Moolenbroek 52*5d5fbe79SDavid van Moolenbroek /** DNS timer period */ 53*5d5fbe79SDavid van Moolenbroek #define DNS_TMR_INTERVAL 1000 54*5d5fbe79SDavid van Moolenbroek 55*5d5fbe79SDavid van Moolenbroek /* DNS resolve types: */ 56*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_IPV4 0 57*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_IPV6 1 58*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */ 59*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */ 60*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV4 && LWIP_IPV6 61*5d5fbe79SDavid van Moolenbroek #ifndef LWIP_DNS_ADDRTYPE_DEFAULT 62*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6 63*5d5fbe79SDavid van Moolenbroek #endif 64*5d5fbe79SDavid van Moolenbroek #elif LWIP_IPV4 65*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4 66*5d5fbe79SDavid van Moolenbroek #else 67*5d5fbe79SDavid van Moolenbroek #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6 68*5d5fbe79SDavid van Moolenbroek #endif 69*5d5fbe79SDavid van Moolenbroek 70*5d5fbe79SDavid van Moolenbroek #if DNS_LOCAL_HOSTLIST 71*5d5fbe79SDavid van Moolenbroek /** struct used for local host-list */ 72*5d5fbe79SDavid van Moolenbroek struct local_hostlist_entry { 73*5d5fbe79SDavid van Moolenbroek /** static hostname */ 74*5d5fbe79SDavid van Moolenbroek const char *name; 75*5d5fbe79SDavid van Moolenbroek /** static host address in network byteorder */ 76*5d5fbe79SDavid van Moolenbroek ip_addr_t addr; 77*5d5fbe79SDavid van Moolenbroek struct local_hostlist_entry *next; 78*5d5fbe79SDavid van Moolenbroek }; 79*5d5fbe79SDavid van Moolenbroek #define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL} 80*5d5fbe79SDavid van Moolenbroek #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 81*5d5fbe79SDavid van Moolenbroek #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN 82*5d5fbe79SDavid van Moolenbroek #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH 83*5d5fbe79SDavid van Moolenbroek #endif 84*5d5fbe79SDavid van Moolenbroek #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1)) 85*5d5fbe79SDavid van Moolenbroek #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 86*5d5fbe79SDavid van Moolenbroek #endif /* DNS_LOCAL_HOSTLIST */ 87*5d5fbe79SDavid van Moolenbroek 88*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV4 89*5d5fbe79SDavid van Moolenbroek extern const ip_addr_t dns_mquery_v4group; 90*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV4 */ 91*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6 92*5d5fbe79SDavid van Moolenbroek extern const ip_addr_t dns_mquery_v6group; 93*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6 */ 94*5d5fbe79SDavid van Moolenbroek 95*5d5fbe79SDavid van Moolenbroek /** Callback which is invoked when a hostname is found. 96*5d5fbe79SDavid van Moolenbroek * A function of this type must be implemented by the application using the DNS resolver. 97*5d5fbe79SDavid van Moolenbroek * @param name pointer to the name that was looked up. 98*5d5fbe79SDavid van Moolenbroek * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname, 99*5d5fbe79SDavid van Moolenbroek * or NULL if the name could not be found (or on any other error). 100*5d5fbe79SDavid van Moolenbroek * @param callback_arg a user-specified callback argument passed to dns_gethostbyname 101*5d5fbe79SDavid van Moolenbroek */ 102*5d5fbe79SDavid van Moolenbroek typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg); 103*5d5fbe79SDavid van Moolenbroek 104*5d5fbe79SDavid van Moolenbroek void dns_init(void); 105*5d5fbe79SDavid van Moolenbroek void dns_tmr(void); 106*5d5fbe79SDavid van Moolenbroek void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver); 107*5d5fbe79SDavid van Moolenbroek const ip_addr_t* dns_getserver(u8_t numdns); 108*5d5fbe79SDavid van Moolenbroek err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr, 109*5d5fbe79SDavid van Moolenbroek dns_found_callback found, void *callback_arg); 110*5d5fbe79SDavid van Moolenbroek err_t dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr, 111*5d5fbe79SDavid van Moolenbroek dns_found_callback found, void *callback_arg, 112*5d5fbe79SDavid van Moolenbroek u8_t dns_addrtype); 113*5d5fbe79SDavid van Moolenbroek 114*5d5fbe79SDavid van Moolenbroek 115*5d5fbe79SDavid van Moolenbroek #if DNS_LOCAL_HOSTLIST 116*5d5fbe79SDavid van Moolenbroek size_t dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg); 117*5d5fbe79SDavid van Moolenbroek err_t dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype); 118*5d5fbe79SDavid van Moolenbroek #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 119*5d5fbe79SDavid van Moolenbroek int dns_local_removehost(const char *hostname, const ip_addr_t *addr); 120*5d5fbe79SDavid van Moolenbroek err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr); 121*5d5fbe79SDavid van Moolenbroek #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 122*5d5fbe79SDavid van Moolenbroek #endif /* DNS_LOCAL_HOSTLIST */ 123*5d5fbe79SDavid van Moolenbroek 124*5d5fbe79SDavid van Moolenbroek #ifdef __cplusplus 125*5d5fbe79SDavid van Moolenbroek } 126*5d5fbe79SDavid van Moolenbroek #endif 127*5d5fbe79SDavid van Moolenbroek 128*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_DNS */ 129*5d5fbe79SDavid van Moolenbroek 130*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_HDR_DNS_H */ 131