Bonjour/Zerconf library

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:54:31 2010 +0000
Revision:
5:8e53abda9900
Parent:
0:355018f44c9f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dirkx 0:355018f44c9f 1 /**
dirkx 0:355018f44c9f 2 * @file
dirkx 0:355018f44c9f 3 * DNS - host name to IP address resolver.
dirkx 0:355018f44c9f 4 *
dirkx 0:355018f44c9f 5 */
dirkx 0:355018f44c9f 6
dirkx 0:355018f44c9f 7 /**
dirkx 0:355018f44c9f 8
dirkx 0:355018f44c9f 9 * This file implements a DNS host name to IP address resolver.
dirkx 0:355018f44c9f 10
dirkx 0:355018f44c9f 11 * Port to lwIP from uIP
dirkx 0:355018f44c9f 12 * by Jim Pettinato April 2007
dirkx 0:355018f44c9f 13
dirkx 0:355018f44c9f 14 * uIP version Copyright (c) 2002-2003, Adam Dunkels.
dirkx 0:355018f44c9f 15 * All rights reserved.
dirkx 0:355018f44c9f 16 *
dirkx 0:355018f44c9f 17 * Redistribution and use in source and binary forms, with or without
dirkx 0:355018f44c9f 18 * modification, are permitted provided that the following conditions
dirkx 0:355018f44c9f 19 * are met:
dirkx 0:355018f44c9f 20 * 1. Redistributions of source code must retain the above copyright
dirkx 0:355018f44c9f 21 * notice, this list of conditions and the following disclaimer.
dirkx 0:355018f44c9f 22 * 2. Redistributions in binary form must reproduce the above copyright
dirkx 0:355018f44c9f 23 * notice, this list of conditions and the following disclaimer in the
dirkx 0:355018f44c9f 24 * documentation and/or other materials provided with the distribution.
dirkx 0:355018f44c9f 25 * 3. The name of the author may not be used to endorse or promote
dirkx 0:355018f44c9f 26 * products derived from this software without specific prior
dirkx 0:355018f44c9f 27 * written permission.
dirkx 0:355018f44c9f 28 *
dirkx 0:355018f44c9f 29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
dirkx 0:355018f44c9f 30 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
dirkx 0:355018f44c9f 31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dirkx 0:355018f44c9f 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
dirkx 0:355018f44c9f 33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dirkx 0:355018f44c9f 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dirkx 0:355018f44c9f 35 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dirkx 0:355018f44c9f 36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
dirkx 0:355018f44c9f 37 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dirkx 0:355018f44c9f 38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dirkx 0:355018f44c9f 39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dirkx 0:355018f44c9f 40 *
dirkx 0:355018f44c9f 41 *
dirkx 0:355018f44c9f 42 * DNS.C
dirkx 0:355018f44c9f 43 *
dirkx 0:355018f44c9f 44 * The lwIP DNS resolver functions are used to lookup a host name and
dirkx 0:355018f44c9f 45 * map it to a numerical IP address. It maintains a list of resolved
dirkx 0:355018f44c9f 46 * hostnames that can be queried with the dns_lookup() function.
dirkx 0:355018f44c9f 47 * New hostnames can be resolved using the dns_query() function.
dirkx 0:355018f44c9f 48 *
dirkx 0:355018f44c9f 49 * The lwIP version of the resolver also adds a non-blocking version of
dirkx 0:355018f44c9f 50 * gethostbyname() that will work with a raw API application. This function
dirkx 0:355018f44c9f 51 * checks for an IP address string first and converts it if it is valid.
dirkx 0:355018f44c9f 52 * gethostbyname() then does a dns_lookup() to see if the name is
dirkx 0:355018f44c9f 53 * already in the table. If so, the IP is returned. If not, a query is
dirkx 0:355018f44c9f 54 * issued and the function returns with a ERR_INPROGRESS status. The app
dirkx 0:355018f44c9f 55 * using the dns client must then go into a waiting state.
dirkx 0:355018f44c9f 56 *
dirkx 0:355018f44c9f 57 * Once a hostname has been resolved (or found to be non-existent),
dirkx 0:355018f44c9f 58 * the resolver code calls a specified callback function (which
dirkx 0:355018f44c9f 59 * must be implemented by the module that uses the resolver).
dirkx 0:355018f44c9f 60 */
dirkx 0:355018f44c9f 61
dirkx 0:355018f44c9f 62 /*-----------------------------------------------------------------------------
dirkx 0:355018f44c9f 63 * RFC 1035 - Domain names - implementation and specification
dirkx 0:355018f44c9f 64 * RFC 2181 - Clarifications to the DNS Specification
dirkx 0:355018f44c9f 65 *----------------------------------------------------------------------------*/
dirkx 0:355018f44c9f 66
dirkx 0:355018f44c9f 67 /** @todo: define good default values (rfc compliance) */
dirkx 0:355018f44c9f 68 /** @todo: improve answer parsing, more checkings... */
dirkx 0:355018f44c9f 69 /** @todo: check RFC1035 - 7.3. Processing responses */
dirkx 0:355018f44c9f 70
dirkx 0:355018f44c9f 71 /*-----------------------------------------------------------------------------
dirkx 0:355018f44c9f 72 * Includes
dirkx 0:355018f44c9f 73 *----------------------------------------------------------------------------*/
dirkx 0:355018f44c9f 74
dirkx 0:355018f44c9f 75 #include "lwip/opt.h"
dirkx 0:355018f44c9f 76
dirkx 0:355018f44c9f 77 #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
dirkx 0:355018f44c9f 78
dirkx 0:355018f44c9f 79 #include "lwip/udp.h"
dirkx 0:355018f44c9f 80 #include "lwip/mem.h"
dirkx 0:355018f44c9f 81 #include "lwip/memp.h"
dirkx 0:355018f44c9f 82 #include "lwip/dns.h"
dirkx 0:355018f44c9f 83 #include "lwip/debug.h"
dirkx 0:355018f44c9f 84
dirkx 0:355018f44c9f 85 #include <string.h>
dirkx 0:355018f44c9f 86
dirkx 0:355018f44c9f 87 /** DNS server IP address */
dirkx 0:355018f44c9f 88 #ifndef DNS_SERVER_ADDRESS
dirkx 0:355018f44c9f 89 #define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
dirkx 0:355018f44c9f 90 #endif
dirkx 0:355018f44c9f 91
dirkx 0:355018f44c9f 92 /** DNS server port address */
dirkx 0:355018f44c9f 93 #ifndef DNS_SERVER_PORT
dirkx 0:355018f44c9f 94 #define DNS_SERVER_PORT 53
dirkx 0:355018f44c9f 95 #endif
dirkx 0:355018f44c9f 96
dirkx 0:355018f44c9f 97 /** DNS maximum number of retries when asking for a name, before "timeout". */
dirkx 0:355018f44c9f 98 #ifndef DNS_MAX_RETRIES
dirkx 0:355018f44c9f 99 #define DNS_MAX_RETRIES 4
dirkx 0:355018f44c9f 100 #endif
dirkx 0:355018f44c9f 101
dirkx 0:355018f44c9f 102 /** DNS resource record max. TTL (one week as default) */
dirkx 0:355018f44c9f 103 #ifndef DNS_MAX_TTL
dirkx 0:355018f44c9f 104 #define DNS_MAX_TTL 604800
dirkx 0:355018f44c9f 105 #endif
dirkx 0:355018f44c9f 106
dirkx 0:355018f44c9f 107 /* DNS protocol flags */
dirkx 0:355018f44c9f 108 #define DNS_FLAG1_RESPONSE 0x80
dirkx 0:355018f44c9f 109 #define DNS_FLAG1_OPCODE_STATUS 0x10
dirkx 0:355018f44c9f 110 #define DNS_FLAG1_OPCODE_INVERSE 0x08
dirkx 0:355018f44c9f 111 #define DNS_FLAG1_OPCODE_STANDARD 0x00
dirkx 0:355018f44c9f 112 #define DNS_FLAG1_AUTHORATIVE 0x04
dirkx 0:355018f44c9f 113 #define DNS_FLAG1_TRUNC 0x02
dirkx 0:355018f44c9f 114 #define DNS_FLAG1_RD 0x01
dirkx 0:355018f44c9f 115 #define DNS_FLAG2_RA 0x80
dirkx 0:355018f44c9f 116 #define DNS_FLAG2_ERR_MASK 0x0f
dirkx 0:355018f44c9f 117 #define DNS_FLAG2_ERR_NONE 0x00
dirkx 0:355018f44c9f 118 #define DNS_FLAG2_ERR_NAME 0x03
dirkx 0:355018f44c9f 119
dirkx 0:355018f44c9f 120 /* DNS protocol states */
dirkx 0:355018f44c9f 121 #define DNS_STATE_UNUSED 0
dirkx 0:355018f44c9f 122 #define DNS_STATE_NEW 1
dirkx 0:355018f44c9f 123 #define DNS_STATE_ASKING 2
dirkx 0:355018f44c9f 124 #define DNS_STATE_DONE 3
dirkx 0:355018f44c9f 125
dirkx 0:355018f44c9f 126 #ifdef PACK_STRUCT_USE_INCLUDES
dirkx 0:355018f44c9f 127 # include "arch/bpstruct.h"
dirkx 0:355018f44c9f 128 #endif
dirkx 0:355018f44c9f 129 PACK_STRUCT_BEGIN
dirkx 0:355018f44c9f 130 /** DNS message header */
dirkx 0:355018f44c9f 131 struct dns_hdr {
dirkx 0:355018f44c9f 132 PACK_STRUCT_FIELD(u16_t id);
dirkx 0:355018f44c9f 133 PACK_STRUCT_FIELD(u8_t flags1);
dirkx 0:355018f44c9f 134 PACK_STRUCT_FIELD(u8_t flags2);
dirkx 0:355018f44c9f 135 PACK_STRUCT_FIELD(u16_t numquestions);
dirkx 0:355018f44c9f 136 PACK_STRUCT_FIELD(u16_t numanswers);
dirkx 0:355018f44c9f 137 PACK_STRUCT_FIELD(u16_t numauthrr);
dirkx 0:355018f44c9f 138 PACK_STRUCT_FIELD(u16_t numextrarr);
dirkx 0:355018f44c9f 139 } PACK_STRUCT_STRUCT;
dirkx 0:355018f44c9f 140 PACK_STRUCT_END
dirkx 0:355018f44c9f 141 #ifdef PACK_STRUCT_USE_INCLUDES
dirkx 0:355018f44c9f 142 # include "arch/epstruct.h"
dirkx 0:355018f44c9f 143 #endif
dirkx 0:355018f44c9f 144 #define SIZEOF_DNS_HDR 12
dirkx 0:355018f44c9f 145
dirkx 0:355018f44c9f 146 /** DNS query message structure.
dirkx 0:355018f44c9f 147 No packing needed: only used locally on the stack. */
dirkx 0:355018f44c9f 148 struct dns_query {
dirkx 0:355018f44c9f 149 /* DNS query record starts with either a domain name or a pointer
dirkx 0:355018f44c9f 150 to a name already present somewhere in the packet. */
dirkx 0:355018f44c9f 151 u16_t type;
dirkx 0:355018f44c9f 152 u16_t cls;
dirkx 0:355018f44c9f 153 };
dirkx 0:355018f44c9f 154 #define SIZEOF_DNS_QUERY 4
dirkx 0:355018f44c9f 155
dirkx 0:355018f44c9f 156 /** DNS answer message structure.
dirkx 0:355018f44c9f 157 No packing needed: only used locally on the stack. */
dirkx 0:355018f44c9f 158 struct dns_answer {
dirkx 0:355018f44c9f 159 /* DNS answer record starts with either a domain name or a pointer
dirkx 0:355018f44c9f 160 to a name already present somewhere in the packet. */
dirkx 0:355018f44c9f 161 u16_t type;
dirkx 0:355018f44c9f 162 u16_t cls;
dirkx 0:355018f44c9f 163 u32_t ttl;
dirkx 0:355018f44c9f 164 u16_t len;
dirkx 0:355018f44c9f 165 };
dirkx 0:355018f44c9f 166 #define SIZEOF_DNS_ANSWER 10
dirkx 0:355018f44c9f 167
dirkx 0:355018f44c9f 168 /** DNS table entry */
dirkx 0:355018f44c9f 169 struct dns_table_entry {
dirkx 0:355018f44c9f 170 u8_t state;
dirkx 0:355018f44c9f 171 u8_t numdns;
dirkx 0:355018f44c9f 172 u8_t tmr;
dirkx 0:355018f44c9f 173 u8_t retries;
dirkx 0:355018f44c9f 174 u8_t seqno;
dirkx 0:355018f44c9f 175 u8_t err;
dirkx 0:355018f44c9f 176 u32_t ttl;
dirkx 0:355018f44c9f 177 char name[DNS_MAX_NAME_LENGTH];
dirkx 0:355018f44c9f 178 ip_addr_t ipaddr;
dirkx 0:355018f44c9f 179 /* pointer to callback on DNS query done */
dirkx 0:355018f44c9f 180 dns_found_callback found;
dirkx 0:355018f44c9f 181 void *arg;
dirkx 0:355018f44c9f 182 };
dirkx 0:355018f44c9f 183
dirkx 0:355018f44c9f 184 #if DNS_LOCAL_HOSTLIST
dirkx 0:355018f44c9f 185
dirkx 0:355018f44c9f 186 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
dirkx 0:355018f44c9f 187 /** Local host-list. For hostnames in this list, no
dirkx 0:355018f44c9f 188 * external name resolution is performed */
dirkx 0:355018f44c9f 189 static struct local_hostlist_entry *local_hostlist_dynamic;
dirkx 0:355018f44c9f 190 #else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
dirkx 0:355018f44c9f 191
dirkx 0:355018f44c9f 192 /** Defining this allows the local_hostlist_static to be placed in a different
dirkx 0:355018f44c9f 193 * linker section (e.g. FLASH) */
dirkx 0:355018f44c9f 194 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_PRE
dirkx 0:355018f44c9f 195 #define DNS_LOCAL_HOSTLIST_STORAGE_PRE static
dirkx 0:355018f44c9f 196 #endif /* DNS_LOCAL_HOSTLIST_STORAGE_PRE */
dirkx 0:355018f44c9f 197 /** Defining this allows the local_hostlist_static to be placed in a different
dirkx 0:355018f44c9f 198 * linker section (e.g. FLASH) */
dirkx 0:355018f44c9f 199 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_POST
dirkx 0:355018f44c9f 200 #define DNS_LOCAL_HOSTLIST_STORAGE_POST
dirkx 0:355018f44c9f 201 #endif /* DNS_LOCAL_HOSTLIST_STORAGE_POST */
dirkx 0:355018f44c9f 202 DNS_LOCAL_HOSTLIST_STORAGE_PRE struct local_hostlist_entry local_hostlist_static[]
dirkx 0:355018f44c9f 203 DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;
dirkx 0:355018f44c9f 204
dirkx 0:355018f44c9f 205 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
dirkx 0:355018f44c9f 206
dirkx 0:355018f44c9f 207 static void dns_init_local();
dirkx 0:355018f44c9f 208 #endif /* DNS_LOCAL_HOSTLIST */
dirkx 0:355018f44c9f 209
dirkx 0:355018f44c9f 210
dirkx 0:355018f44c9f 211 /* forward declarations */
dirkx 0:355018f44c9f 212 static void dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port);
dirkx 0:355018f44c9f 213 static void dns_check_entries(void);
dirkx 0:355018f44c9f 214
dirkx 0:355018f44c9f 215 /*-----------------------------------------------------------------------------
dirkx 0:355018f44c9f 216 * Globales
dirkx 0:355018f44c9f 217 *----------------------------------------------------------------------------*/
dirkx 0:355018f44c9f 218
dirkx 0:355018f44c9f 219 /* DNS variables */
dirkx 0:355018f44c9f 220 static struct udp_pcb *dns_pcb;
dirkx 0:355018f44c9f 221 static u8_t dns_seqno;
dirkx 0:355018f44c9f 222 static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
dirkx 0:355018f44c9f 223 static ip_addr_t dns_servers[DNS_MAX_SERVERS];
dirkx 0:355018f44c9f 224 /** Contiguous buffer for processing responses */
dirkx 0:355018f44c9f 225 static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];
dirkx 0:355018f44c9f 226 static u8_t* dns_payload;
dirkx 0:355018f44c9f 227
dirkx 0:355018f44c9f 228 /**
dirkx 0:355018f44c9f 229 * Initialize the resolver: set up the UDP pcb and configure the default server
dirkx 0:355018f44c9f 230 * (DNS_SERVER_ADDRESS).
dirkx 0:355018f44c9f 231 */
dirkx 0:355018f44c9f 232 void
dirkx 0:355018f44c9f 233 dns_init()
dirkx 0:355018f44c9f 234 {
dirkx 0:355018f44c9f 235 ip_addr_t dnsserver;
dirkx 0:355018f44c9f 236
dirkx 0:355018f44c9f 237 dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
dirkx 0:355018f44c9f 238
dirkx 0:355018f44c9f 239 /* initialize default DNS server address */
dirkx 0:355018f44c9f 240 DNS_SERVER_ADDRESS(&dnsserver);
dirkx 0:355018f44c9f 241
dirkx 0:355018f44c9f 242 LWIP_DEBUGF(DNS_DEBUG, ("dns_init: initializing\n"));
dirkx 0:355018f44c9f 243
dirkx 0:355018f44c9f 244 /* if dns client not yet initialized... */
dirkx 0:355018f44c9f 245 if (dns_pcb == NULL) {
dirkx 0:355018f44c9f 246 dns_pcb = udp_new();
dirkx 0:355018f44c9f 247
dirkx 0:355018f44c9f 248 if (dns_pcb != NULL) {
dirkx 0:355018f44c9f 249 /* initialize DNS table not needed (initialized to zero since it is a
dirkx 0:355018f44c9f 250 * global variable) */
dirkx 0:355018f44c9f 251 LWIP_ASSERT("For implicit initialization to work, DNS_STATE_UNUSED needs to be 0",
dirkx 0:355018f44c9f 252 DNS_STATE_UNUSED == 0);
dirkx 0:355018f44c9f 253
dirkx 0:355018f44c9f 254 /* initialize DNS client */
dirkx 0:355018f44c9f 255 udp_bind(dns_pcb, IP_ADDR_ANY, 0);
dirkx 0:355018f44c9f 256 udp_recv(dns_pcb, dns_recv, NULL);
dirkx 0:355018f44c9f 257
dirkx 0:355018f44c9f 258 /* initialize default DNS primary server */
dirkx 0:355018f44c9f 259 dns_setserver(0, &dnsserver);
dirkx 0:355018f44c9f 260 }
dirkx 0:355018f44c9f 261 }
dirkx 0:355018f44c9f 262 #if DNS_LOCAL_HOSTLIST
dirkx 0:355018f44c9f 263 dns_init_local();
dirkx 0:355018f44c9f 264 #endif
dirkx 0:355018f44c9f 265 }
dirkx 0:355018f44c9f 266
dirkx 0:355018f44c9f 267 /**
dirkx 0:355018f44c9f 268 * Initialize one of the DNS servers.
dirkx 0:355018f44c9f 269 *
dirkx 0:355018f44c9f 270 * @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
dirkx 0:355018f44c9f 271 * @param dnsserver IP address of the DNS server to set
dirkx 0:355018f44c9f 272 */
dirkx 0:355018f44c9f 273 void
dirkx 0:355018f44c9f 274 dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
dirkx 0:355018f44c9f 275 {
dirkx 0:355018f44c9f 276 if ((numdns < DNS_MAX_SERVERS) && (dns_pcb != NULL) &&
dirkx 0:355018f44c9f 277 (dnsserver != NULL) && !ip_addr_isany(dnsserver)) {
dirkx 0:355018f44c9f 278 dns_servers[numdns] = (*dnsserver);
dirkx 0:355018f44c9f 279 }
dirkx 0:355018f44c9f 280 }
dirkx 0:355018f44c9f 281
dirkx 0:355018f44c9f 282 /**
dirkx 0:355018f44c9f 283 * Obtain one of the currently configured DNS server.
dirkx 0:355018f44c9f 284 *
dirkx 0:355018f44c9f 285 * @param numdns the index of the DNS server
dirkx 0:355018f44c9f 286 * @return IP address of the indexed DNS server or "ip_addr_any" if the DNS
dirkx 0:355018f44c9f 287 * server has not been configured.
dirkx 0:355018f44c9f 288 */
dirkx 0:355018f44c9f 289 ip_addr_t
dirkx 0:355018f44c9f 290 dns_getserver(u8_t numdns)
dirkx 0:355018f44c9f 291 {
dirkx 0:355018f44c9f 292 if (numdns < DNS_MAX_SERVERS) {
dirkx 0:355018f44c9f 293 return dns_servers[numdns];
dirkx 0:355018f44c9f 294 } else {
dirkx 0:355018f44c9f 295 return *IP_ADDR_ANY;
dirkx 0:355018f44c9f 296 }
dirkx 0:355018f44c9f 297 }
dirkx 0:355018f44c9f 298
dirkx 0:355018f44c9f 299 /**
dirkx 0:355018f44c9f 300 * The DNS resolver client timer - handle retries and timeouts and should
dirkx 0:355018f44c9f 301 * be called every DNS_TMR_INTERVAL milliseconds (every second by default).
dirkx 0:355018f44c9f 302 */
dirkx 0:355018f44c9f 303 void
dirkx 0:355018f44c9f 304 dns_tmr(void)
dirkx 0:355018f44c9f 305 {
dirkx 0:355018f44c9f 306 if (dns_pcb != NULL) {
dirkx 0:355018f44c9f 307 LWIP_DEBUGF(DNS_DEBUG, ("dns_tmr: dns_check_entries\n"));
dirkx 0:355018f44c9f 308 dns_check_entries();
dirkx 0:355018f44c9f 309 }
dirkx 0:355018f44c9f 310 }
dirkx 0:355018f44c9f 311
dirkx 0:355018f44c9f 312 #if DNS_LOCAL_HOSTLIST
dirkx 0:355018f44c9f 313 static void
dirkx 0:355018f44c9f 314 dns_init_local()
dirkx 0:355018f44c9f 315 {
dirkx 0:355018f44c9f 316 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT)
dirkx 0:355018f44c9f 317 int i;
dirkx 0:355018f44c9f 318 struct local_hostlist_entry *entry;
dirkx 0:355018f44c9f 319 /* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */
dirkx 0:355018f44c9f 320 struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
dirkx 0:355018f44c9f 321 size_t namelen;
dirkx 0:355018f44c9f 322 for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) {
dirkx 0:355018f44c9f 323 struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
dirkx 0:355018f44c9f 324 LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL);
dirkx 0:355018f44c9f 325 namelen = strlen(init_entry->name);
dirkx 0:355018f44c9f 326 LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
dirkx 0:355018f44c9f 327 entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
dirkx 0:355018f44c9f 328 LWIP_ASSERT("mem-error in dns_init_local", entry != NULL);
dirkx 0:355018f44c9f 329 if (entry != NULL) {
dirkx 0:355018f44c9f 330 entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
dirkx 0:355018f44c9f 331 MEMCPY((char*)entry->name, init_entry->name, namelen);
dirkx 0:355018f44c9f 332 ((char*)entry->name)[namelen] = 0;
dirkx 0:355018f44c9f 333 entry->addr = init_entry->addr;
dirkx 0:355018f44c9f 334 entry->next = local_hostlist_dynamic;
dirkx 0:355018f44c9f 335 local_hostlist_dynamic = entry;
dirkx 0:355018f44c9f 336 }
dirkx 0:355018f44c9f 337 }
dirkx 0:355018f44c9f 338 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT) */
dirkx 0:355018f44c9f 339 }
dirkx 0:355018f44c9f 340
dirkx 0:355018f44c9f 341 /**
dirkx 0:355018f44c9f 342 * Scans the local host-list for a hostname.
dirkx 0:355018f44c9f 343 *
dirkx 0:355018f44c9f 344 * @param hostname Hostname to look for in the local host-list
dirkx 0:355018f44c9f 345 * @return The first IP address for the hostname in the local host-list or
dirkx 0:355018f44c9f 346 * IPADDR_NONE if not found.
dirkx 0:355018f44c9f 347 */
dirkx 0:355018f44c9f 348 static u32_t
dirkx 0:355018f44c9f 349 dns_lookup_local(const char *hostname)
dirkx 0:355018f44c9f 350 {
dirkx 0:355018f44c9f 351 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
dirkx 0:355018f44c9f 352 struct local_hostlist_entry *entry = local_hostlist_dynamic;
dirkx 0:355018f44c9f 353 while(entry != NULL) {
dirkx 0:355018f44c9f 354 if(strcmp(entry->name, hostname) == 0) {
dirkx 0:355018f44c9f 355 return ip4_addr_get_u32(&entry->addr);
dirkx 0:355018f44c9f 356 }
dirkx 0:355018f44c9f 357 entry = entry->next;
dirkx 0:355018f44c9f 358 }
dirkx 0:355018f44c9f 359 #else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
dirkx 0:355018f44c9f 360 int i;
dirkx 0:355018f44c9f 361 for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) {
dirkx 0:355018f44c9f 362 if(strcmp(local_hostlist_static[i].name, hostname) == 0) {
dirkx 0:355018f44c9f 363 return ip4_addr_get_u32(&local_hostlist_static[i].addr);
dirkx 0:355018f44c9f 364 }
dirkx 0:355018f44c9f 365 }
dirkx 0:355018f44c9f 366 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
dirkx 0:355018f44c9f 367 return IPADDR_NONE;
dirkx 0:355018f44c9f 368 }
dirkx 0:355018f44c9f 369
dirkx 0:355018f44c9f 370 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
dirkx 0:355018f44c9f 371 /** Remove all entries from the local host-list for a specific hostname
dirkx 0:355018f44c9f 372 * and/or IP addess
dirkx 0:355018f44c9f 373 *
dirkx 0:355018f44c9f 374 * @param hostname hostname for which entries shall be removed from the local
dirkx 0:355018f44c9f 375 * host-list
dirkx 0:355018f44c9f 376 * @param addr address for which entries shall be removed from the local host-list
dirkx 0:355018f44c9f 377 * @return the number of removed entries
dirkx 0:355018f44c9f 378 */
dirkx 0:355018f44c9f 379 int
dirkx 0:355018f44c9f 380 dns_local_removehost(const char *hostname, const ip_addr_t *addr)
dirkx 0:355018f44c9f 381 {
dirkx 0:355018f44c9f 382 int removed = 0;
dirkx 0:355018f44c9f 383 struct local_hostlist_entry *entry = local_hostlist_dynamic;
dirkx 0:355018f44c9f 384 struct local_hostlist_entry *last_entry = NULL;
dirkx 0:355018f44c9f 385 while (entry != NULL) {
dirkx 0:355018f44c9f 386 if (((hostname == NULL) || !strcmp(entry->name, hostname)) &&
dirkx 0:355018f44c9f 387 ((addr == NULL) || ip_addr_cmp(&entry->addr, addr))) {
dirkx 0:355018f44c9f 388 struct local_hostlist_entry *free_entry;
dirkx 0:355018f44c9f 389 if (last_entry != NULL) {
dirkx 0:355018f44c9f 390 last_entry->next = entry->next;
dirkx 0:355018f44c9f 391 } else {
dirkx 0:355018f44c9f 392 local_hostlist_dynamic = entry->next;
dirkx 0:355018f44c9f 393 }
dirkx 0:355018f44c9f 394 free_entry = entry;
dirkx 0:355018f44c9f 395 entry = entry->next;
dirkx 0:355018f44c9f 396 memp_free(MEMP_LOCALHOSTLIST, free_entry);
dirkx 0:355018f44c9f 397 removed++;
dirkx 0:355018f44c9f 398 } else {
dirkx 0:355018f44c9f 399 last_entry = entry;
dirkx 0:355018f44c9f 400 entry = entry->next;
dirkx 0:355018f44c9f 401 }
dirkx 0:355018f44c9f 402 }
dirkx 0:355018f44c9f 403 return removed;
dirkx 0:355018f44c9f 404 }
dirkx 0:355018f44c9f 405
dirkx 0:355018f44c9f 406 /**
dirkx 0:355018f44c9f 407 * Add a hostname/IP address pair to the local host-list.
dirkx 0:355018f44c9f 408 * Duplicates are not checked.
dirkx 0:355018f44c9f 409 *
dirkx 0:355018f44c9f 410 * @param hostname hostname of the new entry
dirkx 0:355018f44c9f 411 * @param addr IP address of the new entry
dirkx 0:355018f44c9f 412 * @return ERR_OK if succeeded or ERR_MEM on memory error
dirkx 0:355018f44c9f 413 */
dirkx 0:355018f44c9f 414 err_t
dirkx 0:355018f44c9f 415 dns_local_addhost(const char *hostname, const ip_addr_t *addr)
dirkx 0:355018f44c9f 416 {
dirkx 0:355018f44c9f 417 struct local_hostlist_entry *entry;
dirkx 0:355018f44c9f 418 size_t namelen;
dirkx 0:355018f44c9f 419 LWIP_ASSERT("invalid host name (NULL)", hostname != NULL);
dirkx 0:355018f44c9f 420 namelen = strlen(hostname);
dirkx 0:355018f44c9f 421 LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
dirkx 0:355018f44c9f 422 entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
dirkx 0:355018f44c9f 423 if (entry == NULL) {
dirkx 0:355018f44c9f 424 return ERR_MEM;
dirkx 0:355018f44c9f 425 }
dirkx 0:355018f44c9f 426 entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
dirkx 0:355018f44c9f 427 MEMCPY((char*)entry->name, hostname, namelen);
dirkx 0:355018f44c9f 428 ((char*)entry->name)[namelen] = 0;
dirkx 0:355018f44c9f 429 ip_addr_copy(entry->addr, *addr);
dirkx 0:355018f44c9f 430 entry->next = local_hostlist_dynamic;
dirkx 0:355018f44c9f 431 local_hostlist_dynamic = entry;
dirkx 0:355018f44c9f 432 return ERR_OK;
dirkx 0:355018f44c9f 433 }
dirkx 0:355018f44c9f 434 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC*/
dirkx 0:355018f44c9f 435 #endif /* DNS_LOCAL_HOSTLIST */
dirkx 0:355018f44c9f 436
dirkx 0:355018f44c9f 437 /**
dirkx 0:355018f44c9f 438 * Look up a hostname in the array of known hostnames.
dirkx 0:355018f44c9f 439 *
dirkx 0:355018f44c9f 440 * @note This function only looks in the internal array of known
dirkx 0:355018f44c9f 441 * hostnames, it does not send out a query for the hostname if none
dirkx 0:355018f44c9f 442 * was found. The function dns_enqueue() can be used to send a query
dirkx 0:355018f44c9f 443 * for a hostname.
dirkx 0:355018f44c9f 444 *
dirkx 0:355018f44c9f 445 * @param name the hostname to look up
dirkx 0:355018f44c9f 446 * @return the hostname's IP address, as u32_t (instead of ip_addr_t to
dirkx 0:355018f44c9f 447 * better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
dirkx 0:355018f44c9f 448 * was not found in the cached dns_table.
dirkx 0:355018f44c9f 449 */
dirkx 0:355018f44c9f 450 static u32_t
dirkx 0:355018f44c9f 451 dns_lookup(const char *name)
dirkx 0:355018f44c9f 452 {
dirkx 0:355018f44c9f 453 u8_t i;
dirkx 0:355018f44c9f 454 #if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN)
dirkx 0:355018f44c9f 455 u32_t addr;
dirkx 0:355018f44c9f 456 #endif /* DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) */
dirkx 0:355018f44c9f 457 #if DNS_LOCAL_HOSTLIST
dirkx 0:355018f44c9f 458 if ((addr = dns_lookup_local(name)) != IPADDR_NONE) {
dirkx 0:355018f44c9f 459 return addr;
dirkx 0:355018f44c9f 460 }
dirkx 0:355018f44c9f 461 #endif /* DNS_LOCAL_HOSTLIST */
dirkx 0:355018f44c9f 462 #ifdef DNS_LOOKUP_LOCAL_EXTERN
dirkx 0:355018f44c9f 463 if((addr = DNS_LOOKUP_LOCAL_EXTERN(name)) != IPADDR_NONE) {
dirkx 0:355018f44c9f 464 return addr;
dirkx 0:355018f44c9f 465 }
dirkx 0:355018f44c9f 466 #endif /* DNS_LOOKUP_LOCAL_EXTERN */
dirkx 0:355018f44c9f 467
dirkx 0:355018f44c9f 468 /* Walk through name list, return entry if found. If not, return NULL. */
dirkx 0:355018f44c9f 469 for (i = 0; i < DNS_TABLE_SIZE; ++i) {
dirkx 0:355018f44c9f 470 if ((dns_table[i].state == DNS_STATE_DONE) &&
dirkx 0:355018f44c9f 471 (strcmp(name, dns_table[i].name) == 0)) {
dirkx 0:355018f44c9f 472 LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
dirkx 0:355018f44c9f 473 ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
dirkx 0:355018f44c9f 474 LWIP_DEBUGF(DNS_DEBUG, ("\n"));
dirkx 0:355018f44c9f 475 return ip4_addr_get_u32(&dns_table[i].ipaddr);
dirkx 0:355018f44c9f 476 }
dirkx 0:355018f44c9f 477 }
dirkx 0:355018f44c9f 478
dirkx 0:355018f44c9f 479 return IPADDR_NONE;
dirkx 0:355018f44c9f 480 }
dirkx 0:355018f44c9f 481
dirkx 0:355018f44c9f 482 #if DNS_DOES_NAME_CHECK
dirkx 0:355018f44c9f 483 /**
dirkx 0:355018f44c9f 484 * Compare the "dotted" name "query" with the encoded name "response"
dirkx 0:355018f44c9f 485 * to make sure an answer from the DNS server matches the current dns_table
dirkx 0:355018f44c9f 486 * entry (otherwise, answers might arrive late for hostname not on the list
dirkx 0:355018f44c9f 487 * any more).
dirkx 0:355018f44c9f 488 *
dirkx 0:355018f44c9f 489 * @param query hostname (not encoded) from the dns_table
dirkx 0:355018f44c9f 490 * @param response encoded hostname in the DNS response
dirkx 0:355018f44c9f 491 * @return 0: names equal; 1: names differ
dirkx 0:355018f44c9f 492 */
dirkx 0:355018f44c9f 493 static u8_t
dirkx 0:355018f44c9f 494 dns_compare_name(unsigned char *query, unsigned char *response)
dirkx 0:355018f44c9f 495 {
dirkx 0:355018f44c9f 496 unsigned char n;
dirkx 0:355018f44c9f 497
dirkx 0:355018f44c9f 498 do {
dirkx 0:355018f44c9f 499 n = *response++;
dirkx 0:355018f44c9f 500 /** @see RFC 1035 - 4.1.4. Message compression */
dirkx 0:355018f44c9f 501 if ((n & 0xc0) == 0xc0) {
dirkx 0:355018f44c9f 502 /* Compressed name */
dirkx 0:355018f44c9f 503 break;
dirkx 0:355018f44c9f 504 } else {
dirkx 0:355018f44c9f 505 /* Not compressed name */
dirkx 0:355018f44c9f 506 while (n > 0) {
dirkx 0:355018f44c9f 507 if ((*query) != (*response)) {
dirkx 0:355018f44c9f 508 return 1;
dirkx 0:355018f44c9f 509 }
dirkx 0:355018f44c9f 510 ++response;
dirkx 0:355018f44c9f 511 ++query;
dirkx 0:355018f44c9f 512 --n;
dirkx 0:355018f44c9f 513 };
dirkx 0:355018f44c9f 514 ++query;
dirkx 0:355018f44c9f 515 }
dirkx 0:355018f44c9f 516 } while (*response != 0);
dirkx 0:355018f44c9f 517
dirkx 0:355018f44c9f 518 return 0;
dirkx 0:355018f44c9f 519 }
dirkx 0:355018f44c9f 520 #endif /* DNS_DOES_NAME_CHECK */
dirkx 0:355018f44c9f 521
dirkx 0:355018f44c9f 522 /**
dirkx 0:355018f44c9f 523 * Walk through a compact encoded DNS name and return the end of the name.
dirkx 0:355018f44c9f 524 *
dirkx 0:355018f44c9f 525 * @param query encoded DNS name in the DNS server response
dirkx 0:355018f44c9f 526 * @return end of the name
dirkx 0:355018f44c9f 527 */
dirkx 0:355018f44c9f 528 static unsigned char *
dirkx 0:355018f44c9f 529 dns_parse_name(unsigned char *query)
dirkx 0:355018f44c9f 530 {
dirkx 0:355018f44c9f 531 unsigned char n;
dirkx 0:355018f44c9f 532
dirkx 0:355018f44c9f 533 do {
dirkx 0:355018f44c9f 534 n = *query++;
dirkx 0:355018f44c9f 535 /** @see RFC 1035 - 4.1.4. Message compression */
dirkx 0:355018f44c9f 536 if ((n & 0xc0) == 0xc0) {
dirkx 0:355018f44c9f 537 /* Compressed name */
dirkx 0:355018f44c9f 538 break;
dirkx 0:355018f44c9f 539 } else {
dirkx 0:355018f44c9f 540 /* Not compressed name */
dirkx 0:355018f44c9f 541 while (n > 0) {
dirkx 0:355018f44c9f 542 ++query;
dirkx 0:355018f44c9f 543 --n;
dirkx 0:355018f44c9f 544 };
dirkx 0:355018f44c9f 545 }
dirkx 0:355018f44c9f 546 } while (*query != 0);
dirkx 0:355018f44c9f 547
dirkx 0:355018f44c9f 548 return query + 1;
dirkx 0:355018f44c9f 549 }
dirkx 0:355018f44c9f 550
dirkx 0:355018f44c9f 551 /**
dirkx 0:355018f44c9f 552 * Send a DNS query packet.
dirkx 0:355018f44c9f 553 *
dirkx 0:355018f44c9f 554 * @param numdns index of the DNS server in the dns_servers table
dirkx 0:355018f44c9f 555 * @param name hostname to query
dirkx 0:355018f44c9f 556 * @param id index of the hostname in dns_table, used as transaction ID in the
dirkx 0:355018f44c9f 557 * DNS query packet
dirkx 0:355018f44c9f 558 * @return ERR_OK if packet is sent; an err_t indicating the problem otherwise
dirkx 0:355018f44c9f 559 */
dirkx 0:355018f44c9f 560 static err_t
dirkx 0:355018f44c9f 561 dns_send(u8_t numdns, const char* name, u8_t id)
dirkx 0:355018f44c9f 562 {
dirkx 0:355018f44c9f 563 err_t err;
dirkx 0:355018f44c9f 564 struct dns_hdr *hdr;
dirkx 0:355018f44c9f 565 struct dns_query qry;
dirkx 0:355018f44c9f 566 struct pbuf *p;
dirkx 0:355018f44c9f 567 char *query, *nptr;
dirkx 0:355018f44c9f 568 const char *pHostname;
dirkx 0:355018f44c9f 569 u8_t n;
dirkx 0:355018f44c9f 570
dirkx 0:355018f44c9f 571 LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
dirkx 0:355018f44c9f 572 (u16_t)(numdns), name));
dirkx 0:355018f44c9f 573 LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS);
dirkx 0:355018f44c9f 574 LWIP_ASSERT("dns server has no IP address set", !ip_addr_isany(&dns_servers[numdns]));
dirkx 0:355018f44c9f 575
dirkx 0:355018f44c9f 576 /* if here, we have either a new query or a retry on a previous query to process */
dirkx 0:355018f44c9f 577 p = pbuf_alloc(PBUF_TRANSPORT, SIZEOF_DNS_HDR + DNS_MAX_NAME_LENGTH +
dirkx 0:355018f44c9f 578 SIZEOF_DNS_QUERY, PBUF_RAM);
dirkx 0:355018f44c9f 579 if (p != NULL) {
dirkx 0:355018f44c9f 580 LWIP_ASSERT("pbuf must be in one piece", p->next == NULL);
dirkx 0:355018f44c9f 581 /* fill dns header */
dirkx 0:355018f44c9f 582 hdr = (struct dns_hdr*)p->payload;
dirkx 0:355018f44c9f 583 memset(hdr, 0, SIZEOF_DNS_HDR);
dirkx 0:355018f44c9f 584 hdr->id = htons(id);
dirkx 0:355018f44c9f 585 hdr->flags1 = DNS_FLAG1_RD;
dirkx 0:355018f44c9f 586 hdr->numquestions = PP_HTONS(1);
dirkx 0:355018f44c9f 587 query = (char*)hdr + SIZEOF_DNS_HDR;
dirkx 0:355018f44c9f 588 pHostname = name;
dirkx 0:355018f44c9f 589 --pHostname;
dirkx 0:355018f44c9f 590
dirkx 0:355018f44c9f 591 /* convert hostname into suitable query format. */
dirkx 0:355018f44c9f 592 do {
dirkx 0:355018f44c9f 593 ++pHostname;
dirkx 0:355018f44c9f 594 nptr = query;
dirkx 0:355018f44c9f 595 ++query;
dirkx 0:355018f44c9f 596 for(n = 0; *pHostname != '.' && *pHostname != 0; ++pHostname) {
dirkx 0:355018f44c9f 597 *query = *pHostname;
dirkx 0:355018f44c9f 598 ++query;
dirkx 0:355018f44c9f 599 ++n;
dirkx 0:355018f44c9f 600 }
dirkx 0:355018f44c9f 601 *nptr = n;
dirkx 0:355018f44c9f 602 } while(*pHostname != 0);
dirkx 0:355018f44c9f 603 *query++='\0';
dirkx 0:355018f44c9f 604
dirkx 0:355018f44c9f 605 /* fill dns query */
dirkx 0:355018f44c9f 606 qry.type = PP_HTONS(DNS_RRTYPE_A);
dirkx 0:355018f44c9f 607 qry.cls = PP_HTONS(DNS_RRCLASS_IN);
dirkx 0:355018f44c9f 608 SMEMCPY(query, &qry, SIZEOF_DNS_QUERY);
dirkx 0:355018f44c9f 609
dirkx 0:355018f44c9f 610 /* resize pbuf to the exact dns query */
dirkx 0:355018f44c9f 611 pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload))));
dirkx 0:355018f44c9f 612
dirkx 0:355018f44c9f 613 /* connect to the server for faster receiving */
dirkx 0:355018f44c9f 614 udp_connect(dns_pcb, &dns_servers[numdns], DNS_SERVER_PORT);
dirkx 0:355018f44c9f 615 /* send dns packet */
dirkx 0:355018f44c9f 616 err = udp_sendto(dns_pcb, p, &dns_servers[numdns], DNS_SERVER_PORT);
dirkx 0:355018f44c9f 617
dirkx 0:355018f44c9f 618 /* free pbuf */
dirkx 0:355018f44c9f 619 pbuf_free(p);
dirkx 0:355018f44c9f 620 } else {
dirkx 0:355018f44c9f 621 err = ERR_MEM;
dirkx 0:355018f44c9f 622 }
dirkx 0:355018f44c9f 623
dirkx 0:355018f44c9f 624 return err;
dirkx 0:355018f44c9f 625 }
dirkx 0:355018f44c9f 626
dirkx 0:355018f44c9f 627 /**
dirkx 0:355018f44c9f 628 * dns_check_entry() - see if pEntry has not yet been queried and, if so, sends out a query.
dirkx 0:355018f44c9f 629 * Check an entry in the dns_table:
dirkx 0:355018f44c9f 630 * - send out query for new entries
dirkx 0:355018f44c9f 631 * - retry old pending entries on timeout (also with different servers)
dirkx 0:355018f44c9f 632 * - remove completed entries from the table if their TTL has expired
dirkx 0:355018f44c9f 633 *
dirkx 0:355018f44c9f 634 * @param i index of the dns_table entry to check
dirkx 0:355018f44c9f 635 */
dirkx 0:355018f44c9f 636 static void
dirkx 0:355018f44c9f 637 dns_check_entry(u8_t i)
dirkx 0:355018f44c9f 638 {
dirkx 0:355018f44c9f 639 err_t err;
dirkx 0:355018f44c9f 640 struct dns_table_entry *pEntry = &dns_table[i];
dirkx 0:355018f44c9f 641
dirkx 0:355018f44c9f 642 LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE);
dirkx 0:355018f44c9f 643
dirkx 0:355018f44c9f 644 switch(pEntry->state) {
dirkx 0:355018f44c9f 645
dirkx 0:355018f44c9f 646 case DNS_STATE_NEW: {
dirkx 0:355018f44c9f 647 /* initialize new entry */
dirkx 0:355018f44c9f 648 pEntry->state = DNS_STATE_ASKING;
dirkx 0:355018f44c9f 649 pEntry->numdns = 0;
dirkx 0:355018f44c9f 650 pEntry->tmr = 1;
dirkx 0:355018f44c9f 651 pEntry->retries = 0;
dirkx 0:355018f44c9f 652
dirkx 0:355018f44c9f 653 /* send DNS packet for this entry */
dirkx 0:355018f44c9f 654 err = dns_send(pEntry->numdns, pEntry->name, i);
dirkx 0:355018f44c9f 655 if (err != ERR_OK) {
dirkx 0:355018f44c9f 656 LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
dirkx 0:355018f44c9f 657 ("dns_send returned error: %d\n", err));
dirkx 0:355018f44c9f 658 }
dirkx 0:355018f44c9f 659 break;
dirkx 0:355018f44c9f 660 }
dirkx 0:355018f44c9f 661
dirkx 0:355018f44c9f 662 case DNS_STATE_ASKING: {
dirkx 0:355018f44c9f 663 if (--pEntry->tmr == 0) {
dirkx 0:355018f44c9f 664 if (++pEntry->retries == DNS_MAX_RETRIES) {
dirkx 0:355018f44c9f 665 if ((pEntry->numdns+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[pEntry->numdns+1])) {
dirkx 0:355018f44c9f 666 /* change of server */
dirkx 0:355018f44c9f 667 pEntry->numdns++;
dirkx 0:355018f44c9f 668 pEntry->tmr = 1;
dirkx 0:355018f44c9f 669 pEntry->retries = 0;
dirkx 0:355018f44c9f 670 break;
dirkx 0:355018f44c9f 671 } else {
dirkx 0:355018f44c9f 672 LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": timeout\n", pEntry->name));
dirkx 0:355018f44c9f 673 /* call specified callback function if provided */
dirkx 0:355018f44c9f 674 if (pEntry->found)
dirkx 0:355018f44c9f 675 (*pEntry->found)(pEntry->name, NULL, pEntry->arg);
dirkx 0:355018f44c9f 676 /* flush this entry */
dirkx 0:355018f44c9f 677 pEntry->state = DNS_STATE_UNUSED;
dirkx 0:355018f44c9f 678 pEntry->found = NULL;
dirkx 0:355018f44c9f 679 break;
dirkx 0:355018f44c9f 680 }
dirkx 0:355018f44c9f 681 }
dirkx 0:355018f44c9f 682
dirkx 0:355018f44c9f 683 /* wait longer for the next retry */
dirkx 0:355018f44c9f 684 pEntry->tmr = pEntry->retries;
dirkx 0:355018f44c9f 685
dirkx 0:355018f44c9f 686 /* send DNS packet for this entry */
dirkx 0:355018f44c9f 687 err = dns_send(pEntry->numdns, pEntry->name, i);
dirkx 0:355018f44c9f 688 if (err != ERR_OK) {
dirkx 0:355018f44c9f 689 LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
dirkx 0:355018f44c9f 690 ("dns_send returned error: %d\n", err));
dirkx 0:355018f44c9f 691 }
dirkx 0:355018f44c9f 692 }
dirkx 0:355018f44c9f 693 break;
dirkx 0:355018f44c9f 694 }
dirkx 0:355018f44c9f 695
dirkx 0:355018f44c9f 696 case DNS_STATE_DONE: {
dirkx 0:355018f44c9f 697 /* if the time to live is nul */
dirkx 0:355018f44c9f 698 if (--pEntry->ttl == 0) {
dirkx 0:355018f44c9f 699 LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
dirkx 0:355018f44c9f 700 /* flush this entry */
dirkx 0:355018f44c9f 701 pEntry->state = DNS_STATE_UNUSED;
dirkx 0:355018f44c9f 702 pEntry->found = NULL;
dirkx 0:355018f44c9f 703 }
dirkx 0:355018f44c9f 704 break;
dirkx 0:355018f44c9f 705 }
dirkx 0:355018f44c9f 706 case DNS_STATE_UNUSED:
dirkx 0:355018f44c9f 707 /* nothing to do */
dirkx 0:355018f44c9f 708 break;
dirkx 0:355018f44c9f 709 default:
dirkx 0:355018f44c9f 710 LWIP_ASSERT("unknown dns_table entry state:", 0);
dirkx 0:355018f44c9f 711 break;
dirkx 0:355018f44c9f 712 }
dirkx 0:355018f44c9f 713 }
dirkx 0:355018f44c9f 714
dirkx 0:355018f44c9f 715 /**
dirkx 0:355018f44c9f 716 * Call dns_check_entry for each entry in dns_table - check all entries.
dirkx 0:355018f44c9f 717 */
dirkx 0:355018f44c9f 718 static void
dirkx 0:355018f44c9f 719 dns_check_entries(void)
dirkx 0:355018f44c9f 720 {
dirkx 0:355018f44c9f 721 u8_t i;
dirkx 0:355018f44c9f 722
dirkx 0:355018f44c9f 723 for (i = 0; i < DNS_TABLE_SIZE; ++i) {
dirkx 0:355018f44c9f 724 dns_check_entry(i);
dirkx 0:355018f44c9f 725 }
dirkx 0:355018f44c9f 726 }
dirkx 0:355018f44c9f 727
dirkx 0:355018f44c9f 728 /**
dirkx 0:355018f44c9f 729 * Receive input function for DNS response packets arriving for the dns UDP pcb.
dirkx 0:355018f44c9f 730 *
dirkx 0:355018f44c9f 731 * @params see udp.h
dirkx 0:355018f44c9f 732 */
dirkx 0:355018f44c9f 733 static void
dirkx 0:355018f44c9f 734 dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port)
dirkx 0:355018f44c9f 735 {
dirkx 0:355018f44c9f 736 u16_t i;
dirkx 0:355018f44c9f 737 char *pHostname;
dirkx 0:355018f44c9f 738 struct dns_hdr *hdr;
dirkx 0:355018f44c9f 739 struct dns_answer ans;
dirkx 0:355018f44c9f 740 struct dns_table_entry *pEntry;
dirkx 0:355018f44c9f 741 u16_t nquestions, nanswers;
dirkx 0:355018f44c9f 742
dirkx 0:355018f44c9f 743 LWIP_UNUSED_ARG(arg);
dirkx 0:355018f44c9f 744 LWIP_UNUSED_ARG(pcb);
dirkx 0:355018f44c9f 745 LWIP_UNUSED_ARG(addr);
dirkx 0:355018f44c9f 746 LWIP_UNUSED_ARG(port);
dirkx 0:355018f44c9f 747
dirkx 0:355018f44c9f 748 /* is the dns message too big ? */
dirkx 0:355018f44c9f 749 if (p->tot_len > DNS_MSG_SIZE) {
dirkx 0:355018f44c9f 750 LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: pbuf too big\n"));
dirkx 0:355018f44c9f 751 /* free pbuf and return */
dirkx 0:355018f44c9f 752 goto memerr;
dirkx 0:355018f44c9f 753 }
dirkx 0:355018f44c9f 754
dirkx 0:355018f44c9f 755 /* is the dns message big enough ? */
dirkx 0:355018f44c9f 756 if (p->tot_len < (SIZEOF_DNS_HDR + SIZEOF_DNS_QUERY + SIZEOF_DNS_ANSWER)) {
dirkx 0:355018f44c9f 757 LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: pbuf too small\n"));
dirkx 0:355018f44c9f 758 /* free pbuf and return */
dirkx 0:355018f44c9f 759 goto memerr;
dirkx 0:355018f44c9f 760 }
dirkx 0:355018f44c9f 761
dirkx 0:355018f44c9f 762 /* copy dns payload inside static buffer for processing */
dirkx 0:355018f44c9f 763 if (pbuf_copy_partial(p, dns_payload, p->tot_len, 0) == p->tot_len) {
dirkx 0:355018f44c9f 764 /* The ID in the DNS header should be our entry into the name table. */
dirkx 0:355018f44c9f 765 hdr = (struct dns_hdr*)dns_payload;
dirkx 0:355018f44c9f 766 i = htons(hdr->id);
dirkx 0:355018f44c9f 767 if (i < DNS_TABLE_SIZE) {
dirkx 0:355018f44c9f 768 pEntry = &dns_table[i];
dirkx 0:355018f44c9f 769 if(pEntry->state == DNS_STATE_ASKING) {
dirkx 0:355018f44c9f 770 /* This entry is now completed. */
dirkx 0:355018f44c9f 771 pEntry->state = DNS_STATE_DONE;
dirkx 0:355018f44c9f 772 pEntry->err = hdr->flags2 & DNS_FLAG2_ERR_MASK;
dirkx 0:355018f44c9f 773
dirkx 0:355018f44c9f 774 /* We only care about the question(s) and the answers. The authrr
dirkx 0:355018f44c9f 775 and the extrarr are simply discarded. */
dirkx 0:355018f44c9f 776 nquestions = htons(hdr->numquestions);
dirkx 0:355018f44c9f 777 nanswers = htons(hdr->numanswers);
dirkx 0:355018f44c9f 778
dirkx 0:355018f44c9f 779 /* Check for error. If so, call callback to inform. */
dirkx 0:355018f44c9f 780 if (((hdr->flags1 & DNS_FLAG1_RESPONSE) == 0) || (pEntry->err != 0) || (nquestions != 1)) {
dirkx 0:355018f44c9f 781 LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in flags\n", pEntry->name));
dirkx 0:355018f44c9f 782 /* call callback to indicate error, clean up memory and return */
dirkx 0:355018f44c9f 783 goto responseerr;
dirkx 0:355018f44c9f 784 }
dirkx 0:355018f44c9f 785
dirkx 0:355018f44c9f 786 #if DNS_DOES_NAME_CHECK
dirkx 0:355018f44c9f 787 /* Check if the name in the "question" part match with the name in the entry. */
dirkx 0:355018f44c9f 788 if (dns_compare_name((unsigned char *)(pEntry->name), (unsigned char *)dns_payload + SIZEOF_DNS_HDR) != 0) {
dirkx 0:355018f44c9f 789 LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", pEntry->name));
dirkx 0:355018f44c9f 790 /* call callback to indicate error, clean up memory and return */
dirkx 0:355018f44c9f 791 goto responseerr;
dirkx 0:355018f44c9f 792 }
dirkx 0:355018f44c9f 793 #endif /* DNS_DOES_NAME_CHECK */
dirkx 0:355018f44c9f 794
dirkx 0:355018f44c9f 795 /* Skip the name in the "question" part */
dirkx 0:355018f44c9f 796 pHostname = (char *) dns_parse_name((unsigned char *)dns_payload + SIZEOF_DNS_HDR) + SIZEOF_DNS_QUERY;
dirkx 0:355018f44c9f 797
dirkx 0:355018f44c9f 798 while (nanswers > 0) {
dirkx 0:355018f44c9f 799 /* skip answer resource record's host name */
dirkx 0:355018f44c9f 800 pHostname = (char *) dns_parse_name((unsigned char *)pHostname);
dirkx 0:355018f44c9f 801
dirkx 0:355018f44c9f 802 /* Check for IP address type and Internet class. Others are discarded. */
dirkx 0:355018f44c9f 803 SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
dirkx 0:355018f44c9f 804 if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) &&
dirkx 0:355018f44c9f 805 (ans.len == PP_HTONS(sizeof(ip_addr_t))) ) {
dirkx 0:355018f44c9f 806 /* read the answer resource record's TTL, and maximize it if needed */
dirkx 0:355018f44c9f 807 pEntry->ttl = ntohl(ans.ttl);
dirkx 0:355018f44c9f 808 if (pEntry->ttl > DNS_MAX_TTL) {
dirkx 0:355018f44c9f 809 pEntry->ttl = DNS_MAX_TTL;
dirkx 0:355018f44c9f 810 }
dirkx 0:355018f44c9f 811 /* read the IP address after answer resource record's header */
dirkx 0:355018f44c9f 812 SMEMCPY(&(pEntry->ipaddr), (pHostname+SIZEOF_DNS_ANSWER), sizeof(ip_addr_t));
dirkx 0:355018f44c9f 813 LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response = ", pEntry->name));
dirkx 0:355018f44c9f 814 ip_addr_debug_print(DNS_DEBUG, (&(pEntry->ipaddr)));
dirkx 0:355018f44c9f 815 LWIP_DEBUGF(DNS_DEBUG, ("\n"));
dirkx 0:355018f44c9f 816 /* call specified callback function if provided */
dirkx 0:355018f44c9f 817 if (pEntry->found) {
dirkx 0:355018f44c9f 818 (*pEntry->found)(pEntry->name, &pEntry->ipaddr, pEntry->arg);
dirkx 0:355018f44c9f 819 }
dirkx 0:355018f44c9f 820 /* deallocate memory and return */
dirkx 0:355018f44c9f 821 goto memerr;
dirkx 0:355018f44c9f 822 } else {
dirkx 0:355018f44c9f 823 pHostname = pHostname + SIZEOF_DNS_ANSWER + htons(ans.len);
dirkx 0:355018f44c9f 824 }
dirkx 0:355018f44c9f 825 --nanswers;
dirkx 0:355018f44c9f 826 }
dirkx 0:355018f44c9f 827 LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in response\n", pEntry->name));
dirkx 0:355018f44c9f 828 /* call callback to indicate error, clean up memory and return */
dirkx 0:355018f44c9f 829 goto responseerr;
dirkx 0:355018f44c9f 830 }
dirkx 0:355018f44c9f 831 }
dirkx 0:355018f44c9f 832 }
dirkx 0:355018f44c9f 833
dirkx 0:355018f44c9f 834 /* deallocate memory and return */
dirkx 0:355018f44c9f 835 goto memerr;
dirkx 0:355018f44c9f 836
dirkx 0:355018f44c9f 837 responseerr:
dirkx 0:355018f44c9f 838 /* ERROR: call specified callback function with NULL as name to indicate an error */
dirkx 0:355018f44c9f 839 if (pEntry->found) {
dirkx 0:355018f44c9f 840 (*pEntry->found)(pEntry->name, NULL, pEntry->arg);
dirkx 0:355018f44c9f 841 }
dirkx 0:355018f44c9f 842 /* flush this entry */
dirkx 0:355018f44c9f 843 pEntry->state = DNS_STATE_UNUSED;
dirkx 0:355018f44c9f 844 pEntry->found = NULL;
dirkx 0:355018f44c9f 845
dirkx 0:355018f44c9f 846 memerr:
dirkx 0:355018f44c9f 847 /* free pbuf */
dirkx 0:355018f44c9f 848 pbuf_free(p);
dirkx 0:355018f44c9f 849 return;
dirkx 0:355018f44c9f 850 }
dirkx 0:355018f44c9f 851
dirkx 0:355018f44c9f 852 /**
dirkx 0:355018f44c9f 853 * Queues a new hostname to resolve and sends out a DNS query for that hostname
dirkx 0:355018f44c9f 854 *
dirkx 0:355018f44c9f 855 * @param name the hostname that is to be queried
dirkx 0:355018f44c9f 856 * @param found a callback founction to be called on success, failure or timeout
dirkx 0:355018f44c9f 857 * @param callback_arg argument to pass to the callback function
dirkx 0:355018f44c9f 858 * @return @return a err_t return code.
dirkx 0:355018f44c9f 859 */
dirkx 0:355018f44c9f 860 static err_t
dirkx 0:355018f44c9f 861 dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
dirkx 0:355018f44c9f 862 {
dirkx 0:355018f44c9f 863 u8_t i;
dirkx 0:355018f44c9f 864 u8_t lseq, lseqi;
dirkx 0:355018f44c9f 865 struct dns_table_entry *pEntry = NULL;
dirkx 0:355018f44c9f 866 size_t namelen;
dirkx 0:355018f44c9f 867
dirkx 0:355018f44c9f 868 /* search an unused entry, or the oldest one */
dirkx 0:355018f44c9f 869 lseq = lseqi = 0;
dirkx 0:355018f44c9f 870 for (i = 0; i < DNS_TABLE_SIZE; ++i) {
dirkx 0:355018f44c9f 871 pEntry = &dns_table[i];
dirkx 0:355018f44c9f 872 /* is it an unused entry ? */
dirkx 0:355018f44c9f 873 if (pEntry->state == DNS_STATE_UNUSED)
dirkx 0:355018f44c9f 874 break;
dirkx 0:355018f44c9f 875
dirkx 0:355018f44c9f 876 /* check if this is the oldest completed entry */
dirkx 0:355018f44c9f 877 if (pEntry->state == DNS_STATE_DONE) {
dirkx 0:355018f44c9f 878 if ((dns_seqno - pEntry->seqno) > lseq) {
dirkx 0:355018f44c9f 879 lseq = dns_seqno - pEntry->seqno;
dirkx 0:355018f44c9f 880 lseqi = i;
dirkx 0:355018f44c9f 881 }
dirkx 0:355018f44c9f 882 }
dirkx 0:355018f44c9f 883 }
dirkx 0:355018f44c9f 884
dirkx 0:355018f44c9f 885 /* if we don't have found an unused entry, use the oldest completed one */
dirkx 0:355018f44c9f 886 if (i == DNS_TABLE_SIZE) {
dirkx 0:355018f44c9f 887 if ((lseqi >= DNS_TABLE_SIZE) || (dns_table[lseqi].state != DNS_STATE_DONE)) {
dirkx 0:355018f44c9f 888 /* no entry can't be used now, table is full */
dirkx 0:355018f44c9f 889 LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": DNS entries table is full\n", name));
dirkx 0:355018f44c9f 890 return ERR_MEM;
dirkx 0:355018f44c9f 891 } else {
dirkx 0:355018f44c9f 892 /* use the oldest completed one */
dirkx 0:355018f44c9f 893 i = lseqi;
dirkx 0:355018f44c9f 894 pEntry = &dns_table[i];
dirkx 0:355018f44c9f 895 }
dirkx 0:355018f44c9f 896 }
dirkx 0:355018f44c9f 897
dirkx 0:355018f44c9f 898 /* use this entry */
dirkx 0:355018f44c9f 899 LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
dirkx 0:355018f44c9f 900
dirkx 0:355018f44c9f 901 /* fill the entry */
dirkx 0:355018f44c9f 902 pEntry->state = DNS_STATE_NEW;
dirkx 0:355018f44c9f 903 pEntry->seqno = dns_seqno++;
dirkx 0:355018f44c9f 904 pEntry->found = found;
dirkx 0:355018f44c9f 905 pEntry->arg = callback_arg;
dirkx 0:355018f44c9f 906 namelen = LWIP_MIN(strlen(name), DNS_MAX_NAME_LENGTH-1);
dirkx 0:355018f44c9f 907 MEMCPY(pEntry->name, name, namelen);
dirkx 0:355018f44c9f 908 pEntry->name[namelen] = 0;
dirkx 0:355018f44c9f 909
dirkx 0:355018f44c9f 910 /* force to send query without waiting timer */
dirkx 0:355018f44c9f 911 dns_check_entry(i);
dirkx 0:355018f44c9f 912
dirkx 0:355018f44c9f 913 /* dns query is enqueued */
dirkx 0:355018f44c9f 914 return ERR_INPROGRESS;
dirkx 0:355018f44c9f 915 }
dirkx 0:355018f44c9f 916
dirkx 0:355018f44c9f 917 /**
dirkx 0:355018f44c9f 918 * Resolve a hostname (string) into an IP address.
dirkx 0:355018f44c9f 919 * NON-BLOCKING callback version for use with raw API!!!
dirkx 0:355018f44c9f 920 *
dirkx 0:355018f44c9f 921 * Returns immediately with one of err_t return codes:
dirkx 0:355018f44c9f 922 * - ERR_OK if hostname is a valid IP address string or the host
dirkx 0:355018f44c9f 923 * name is already in the local names table.
dirkx 0:355018f44c9f 924 * - ERR_INPROGRESS enqueue a request to be sent to the DNS server
dirkx 0:355018f44c9f 925 * for resolution if no errors are present.
dirkx 0:355018f44c9f 926 *
dirkx 0:355018f44c9f 927 * @param hostname the hostname that is to be queried
dirkx 0:355018f44c9f 928 * @param addr pointer to a ip_addr_t where to store the address if it is already
dirkx 0:355018f44c9f 929 * cached in the dns_table (only valid if ERR_OK is returned!)
dirkx 0:355018f44c9f 930 * @param found a callback function to be called on success, failure or timeout (only if
dirkx 0:355018f44c9f 931 * ERR_INPROGRESS is returned!)
dirkx 0:355018f44c9f 932 * @param callback_arg argument to pass to the callback function
dirkx 0:355018f44c9f 933 * @return a err_t return code.
dirkx 0:355018f44c9f 934 */
dirkx 0:355018f44c9f 935 err_t
dirkx 0:355018f44c9f 936 dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback found,
dirkx 0:355018f44c9f 937 void *callback_arg)
dirkx 0:355018f44c9f 938 {
dirkx 0:355018f44c9f 939 u32_t ipaddr;
dirkx 0:355018f44c9f 940 /* not initialized or no valid server yet, or invalid addr pointer
dirkx 0:355018f44c9f 941 * or invalid hostname or invalid hostname length */
dirkx 0:355018f44c9f 942 if ((dns_pcb == NULL) || (addr == NULL) ||
dirkx 0:355018f44c9f 943 (!hostname) || (!hostname[0]) ||
dirkx 0:355018f44c9f 944 (strlen(hostname) >= DNS_MAX_NAME_LENGTH)) {
dirkx 0:355018f44c9f 945 return ERR_VAL;
dirkx 0:355018f44c9f 946 }
dirkx 0:355018f44c9f 947
dirkx 0:355018f44c9f 948 #if LWIP_HAVE_LOOPIF
dirkx 0:355018f44c9f 949 if (strcmp(hostname, "localhost")==0) {
dirkx 0:355018f44c9f 950 ip_addr_set_loopback(addr);
dirkx 0:355018f44c9f 951 return ERR_OK;
dirkx 0:355018f44c9f 952 }
dirkx 0:355018f44c9f 953 #endif /* LWIP_HAVE_LOOPIF */
dirkx 0:355018f44c9f 954
dirkx 0:355018f44c9f 955 /* host name already in octet notation? set ip addr and return ERR_OK */
dirkx 0:355018f44c9f 956 ipaddr = ipaddr_addr(hostname);
dirkx 0:355018f44c9f 957 if (ipaddr == IPADDR_NONE) {
dirkx 0:355018f44c9f 958 /* already have this address cached? */
dirkx 0:355018f44c9f 959 ipaddr = dns_lookup(hostname);
dirkx 0:355018f44c9f 960 }
dirkx 0:355018f44c9f 961 if (ipaddr != IPADDR_NONE) {
dirkx 0:355018f44c9f 962 ip4_addr_set_u32(addr, ipaddr);
dirkx 0:355018f44c9f 963 return ERR_OK;
dirkx 0:355018f44c9f 964 }
dirkx 0:355018f44c9f 965
dirkx 0:355018f44c9f 966 /* queue query with specified callback */
dirkx 0:355018f44c9f 967 return dns_enqueue(hostname, found, callback_arg);
dirkx 0:355018f44c9f 968 }
dirkx 0:355018f44c9f 969
dirkx 0:355018f44c9f 970 #endif /* LWIP_DNS */