Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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 #include "lwip/err.h"
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 struct dns_server_interface {
00054     char interface_name [INTERFACE_NAME_MAX_SIZE];
00055     ip_addr_t dns_servers[DNS_MAX_SERVERS];
00056     struct dns_server_interface *next;
00057 };
00058 
00059 /** DNS timer period */
00060 #define DNS_TMR_INTERVAL          1000
00061 
00062 /* DNS resolve types: */
00063 #define LWIP_DNS_ADDRTYPE_IPV4      0
00064 #define LWIP_DNS_ADDRTYPE_IPV6      1
00065 #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
00066 #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
00067 #if LWIP_IPV4 && LWIP_IPV6
00068 #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
00069 #define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV4_IPV6
00070 #endif
00071 #elif LWIP_IPV4
00072 #define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV4
00073 #else
00074 #define LWIP_DNS_ADDRTYPE_DEFAULT   LWIP_DNS_ADDRTYPE_IPV6
00075 #endif
00076 
00077 #if DNS_LOCAL_HOSTLIST
00078 /** struct used for local host-list */
00079 struct local_hostlist_entry {
00080   /** static hostname */
00081   const char *name;
00082   /** static host address in network byteorder */
00083   ip_addr_t addr;
00084   struct local_hostlist_entry *next;
00085 };
00086 #define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL}
00087 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
00088 #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
00089 #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN  DNS_MAX_NAME_LENGTH
00090 #endif
00091 #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
00092 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
00093 #endif /* DNS_LOCAL_HOSTLIST */
00094 
00095 #if LWIP_IPV4
00096 extern const ip_addr_t dns_mquery_v4group;
00097 #endif /* LWIP_IPV4 */
00098 #if LWIP_IPV6
00099 extern const ip_addr_t dns_mquery_v6group;
00100 #endif /* LWIP_IPV6 */
00101 
00102 /** Callback which is invoked when a hostname is found.
00103  * A function of this type must be implemented by the application using the DNS resolver.
00104  * @param name pointer to the name that was looked up.
00105  * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname,
00106  *        or NULL if the name could not be found (or on any other error).
00107  * @param callback_arg a user-specified callback argument passed to dns_gethostbyname
00108 */
00109 typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
00110 
00111 void             dns_init(void);
00112 void             dns_tmr(void);
00113 void             dns_setserver(u8_t numdns, const ip_addr_t *dnsserver, struct netif *netif);
00114 const ip_addr_t* dns_getserver(u8_t numdns, const char *interface_name);
00115 void             dns_add_interface_server(u8_t numdns, const char *interface_name, const ip_addr_t *dnsserver);
00116 void             dns_remove_interface_servers(const char *interface_name);
00117 const ip_addr_t* dns_get_interface_server(u8_t numdns, const char *interface_name);
00118 err_t            dns_gethostbyname(const char *hostname, ip_addr_t *addr,
00119                                    dns_found_callback found, void *callback_arg);
00120 err_t            dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,
00121                                    dns_found_callback found, void *callback_arg,
00122                                    u8_t dns_addrtype);
00123 
00124 
00125 #if DNS_LOCAL_HOSTLIST
00126 size_t         dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg);
00127 err_t          dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype);
00128 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
00129 int            dns_local_removehost(const char *hostname, const ip_addr_t *addr);
00130 err_t          dns_local_addhost(const char *hostname, const ip_addr_t *addr);
00131 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
00132 #endif /* DNS_LOCAL_HOSTLIST */
00133 
00134 #ifdef __cplusplus
00135 }
00136 #endif
00137 
00138 #endif /* LWIP_DNS */
00139 
00140 #endif /* LWIP_HDR_DNS_H */