Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dns.h Source File

dns.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * DNS API
00004  */
00005 
00006 /**
00007  * lwip DNS resolver header file.
00008 
00009  * Author: Jim Pettinato
00010  *   April 2007
00011 
00012  * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions
00016  * are met:
00017  * 1. Redistributions of source code must retain the above copyright
00018  *    notice, this list of conditions and the following disclaimer.
00019  * 2. Redistributions in binary form must reproduce the above copyright
00020  *    notice, this list of conditions and the following disclaimer in the
00021  *    documentation and/or other materials provided with the distribution.
00022  * 3. The name of the author may not be used to endorse or promote
00023  *    products derived from this software without specific prior
00024  *    written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00027  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00028  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00030  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00032  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00034  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 #ifndef LWIP_HDR_DNS_H
00040 #define LWIP_HDR_DNS_H
00041 
00042 #include "lwip/opt.h"
00043 
00044 #if LWIP_DNS
00045 
00046 #include "lwip/ip_addr.h"
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 /** DNS timer period */
00053 #define DNS_TMR_INTERVAL          1000
00054 
00055 /* DNS resolve types: */
00056 #define LWIP_DNS_ADDRTYPE_IPV4      0
00057 #define LWIP_DNS_ADDRTYPE_IPV6      1
00058 #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
00059 #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
00060 #if LWIP_IPV4 && LWIP_IPV6
00061 #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
00062 #define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV4_IPV6
00063 #endif
00064 #elif LWIP_IPV4
00065 #define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV4
00066 #else
00067 #define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV6
00068 #endif
00069 
00070 #if DNS_LOCAL_HOSTLIST
00071 /** struct used for local host-list */
00072 struct local_hostlist_entry {
00073   /** static hostname */
00074   const char *name;
00075   /** static host address in network byteorder */
00076   ip_addr_t addr;
00077   struct local_hostlist_entry *next;
00078 };
00079 #define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL}
00080 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
00081 #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
00082 #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN  DNS_MAX_NAME_LENGTH
00083 #endif
00084 #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
00085 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
00086 #endif /* DNS_LOCAL_HOSTLIST */
00087 
00088 #if LWIP_IPV4
00089 extern const ip_addr_t dns_mquery_v4group;
00090 #endif /* LWIP_IPV4 */
00091 #if LWIP_IPV6
00092 extern const ip_addr_t dns_mquery_v6group;
00093 #endif /* LWIP_IPV6 */
00094 
00095 /** Callback which is invoked when a hostname is found.
00096  * A function of this type must be implemented by the application using the DNS resolver.
00097  * @param name pointer to the name that was looked up.
00098  * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname,
00099  *        or NULL if the name could not be found (or on any other error).
00100  * @param callback_arg a user-specified callback argument passed to dns_gethostbyname
00101 */
00102 typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
00103 
00104 void             dns_init(void);
00105 void             dns_tmr(void);
00106 void             dns_setserver(u8_t numdns, const ip_addr_t *dnsserver);
00107 const ip_addr_t* dns_getserver(u8_t numdns);
00108 err_t            dns_gethostbyname(const char *hostname, ip_addr_t *addr,
00109                                    dns_found_callback found, void *callback_arg);
00110 err_t            dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,
00111                                    dns_found_callback found, void *callback_arg,
00112                                    u8_t dns_addrtype);
00113 
00114 
00115 #if DNS_LOCAL_HOSTLIST
00116 size_t         dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg);
00117 err_t          dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype);
00118 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
00119 int            dns_local_removehost(const char *hostname, const ip_addr_t *addr);
00120 err_t          dns_local_addhost(const char *hostname, const ip_addr_t *addr);
00121 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
00122 #endif /* DNS_LOCAL_HOSTLIST */
00123 
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127 
00128 #endif /* LWIP_DNS */
00129 
00130 #endif /* LWIP_HDR_DNS_H */