100 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0)
101 #define DNS_RAND_TXID LWIP_RAND
103 static u16_t dns_txid;
104 #define DNS_RAND_TXID() (++dns_txid)
109 #ifndef DNS_PORT_ALLOWED
110 #define DNS_PORT_ALLOWED(port) ((port) >= 1024)
114 #ifndef DNS_MAX_RETRIES
115 #define DNS_MAX_RETRIES 4
120 #define DNS_MAX_TTL 604800
121 #elif DNS_MAX_TTL > 0x7FFFFFFF
122 #error DNS_MAX_TTL must be a positive 32-bit value
125 #if DNS_TABLE_SIZE > 255
126 #error DNS_TABLE_SIZE must fit into an u8_t
128 #if DNS_MAX_SERVERS > 255
129 #error DNS_MAX_SERVERS must fit into an u8_t
136 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0)
137 #ifndef DNS_MAX_REQUESTS
138 #define DNS_MAX_REQUESTS DNS_TABLE_SIZE
140 #if DNS_MAX_REQUESTS > 255
141 #error DNS_MAX_REQUESTS must fit into an u8_t
147 #define DNS_MAX_REQUESTS DNS_TABLE_SIZE
151 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
152 #ifndef DNS_MAX_SOURCE_PORTS
153 #define DNS_MAX_SOURCE_PORTS DNS_MAX_REQUESTS
155 #if DNS_MAX_SOURCE_PORTS > 255
156 #error DNS_MAX_SOURCE_PORTS must fit into an u8_t
160 #ifdef DNS_MAX_SOURCE_PORTS
161 #undef DNS_MAX_SOURCE_PORTS
163 #define DNS_MAX_SOURCE_PORTS 1
166 #if LWIP_IPV4 && LWIP_IPV6
167 #define LWIP_DNS_ADDRTYPE_IS_IPV6(t) (((t) == LWIP_DNS_ADDRTYPE_IPV6_IPV4) || ((t) == LWIP_DNS_ADDRTYPE_IPV6))
168 #define LWIP_DNS_ADDRTYPE_MATCH_IP(t, ip) (IP_IS_V6_VAL(ip) ? LWIP_DNS_ADDRTYPE_IS_IPV6(t) : (!LWIP_DNS_ADDRTYPE_IS_IPV6(t)))
169 #define LWIP_DNS_ADDRTYPE_ARG(x) , x
170 #define LWIP_DNS_ADDRTYPE_ARG_OR_ZERO(x) x
171 #define LWIP_DNS_SET_ADDRTYPE(x, y) do { x = y; } while(0)
174 #define LWIP_DNS_ADDRTYPE_IS_IPV6(t) 1
176 #define LWIP_DNS_ADDRTYPE_IS_IPV6(t) 0
178 #define LWIP_DNS_ADDRTYPE_MATCH_IP(t, ip) 1
179 #define LWIP_DNS_ADDRTYPE_ARG(x)
180 #define LWIP_DNS_ADDRTYPE_ARG_OR_ZERO(x) 0
181 #define LWIP_DNS_SET_ADDRTYPE(x, y)
184 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
185 #define LWIP_DNS_ISMDNS_ARG(x) , x
187 #define LWIP_DNS_ISMDNS_ARG(x)
198 #define SIZEOF_DNS_QUERY 4
210 #define SIZEOF_DNS_ANSWER 10
212 #define SIZEOF_DNS_ANSWER_ASSERT 12
216 DNS_STATE_UNUSED = 0,
218 DNS_STATE_ASKING = 2,
223 struct dns_table_entry {
232 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
236 #if LWIP_IPV4 && LWIP_IPV6
239 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
246 struct dns_req_entry {
248 dns_found_callback found;
251 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0)
254 #if LWIP_IPV4 && LWIP_IPV6
259 #if DNS_LOCAL_HOSTLIST
261 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
264 static struct local_hostlist_entry *local_hostlist_dynamic;
269 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_PRE
270 #define DNS_LOCAL_HOSTLIST_STORAGE_PRE static
274 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_POST
275 #define DNS_LOCAL_HOSTLIST_STORAGE_POST
277 DNS_LOCAL_HOSTLIST_STORAGE_PRE
struct local_hostlist_entry local_hostlist_static[]
278 DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;
282 static void dns_init_local(
void);
283 static err_t dns_lookup_local(
const char *hostname,
ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype));
288 static void dns_recv(
void *s,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr,
u16_t port);
289 static void dns_check_entries(
void);
297 static struct udp_pcb *dns_pcbs[DNS_MAX_SOURCE_PORTS];
298 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
299 static u8_t dns_last_pcb_idx;
301 static u8_t dns_seqno;
303 static struct dns_req_entry dns_requests[DNS_MAX_REQUESTS];
320 #ifdef DNS_SERVER_ADDRESS
323 DNS_SERVER_ADDRESS(&dnsserver);
324 dns_setserver(0, &dnsserver);
328 sizeof(
struct dns_query) == SIZEOF_DNS_QUERY);
330 sizeof(
struct dns_answer) <= SIZEOF_DNS_ANSWER_ASSERT);
335 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) == 0)
336 if (dns_pcbs[0] ==
NULL) {
342 LWIP_ASSERT(
"For implicit initialization to work, DNS_STATE_UNUSED needs to be 0",
343 DNS_STATE_UNUSED == 0);
347 udp_recv(dns_pcbs[0], dns_recv,
NULL);
351 #if DNS_LOCAL_HOSTLIST
367 if (dnsserver !=
NULL) {
368 dns_servers[numdns] = (*dnsserver);
370 dns_servers[numdns] = *IP_ADDR_ANY;
384 dns_getserver(
u8_t numdns)
387 return &dns_servers[numdns];
404 #if DNS_LOCAL_HOSTLIST
408 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT)
410 struct local_hostlist_entry *entry;
412 struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
415 struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
417 namelen =
strlen(init_entry->name);
418 LWIP_ASSERT(
"namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
419 entry = (
struct local_hostlist_entry *)
memp_malloc(MEMP_LOCALHOSTLIST);
422 char* entry_name = (
char*)entry +
sizeof(
struct local_hostlist_entry);
423 MEMCPY(entry_name, init_entry->name, namelen);
424 entry_name[namelen] = 0;
425 entry->name = entry_name;
426 entry->addr = init_entry->addr;
427 entry->next = local_hostlist_dynamic;
428 local_hostlist_dynamic = entry;
443 dns_local_iterate(dns_found_callback iterator_fn,
void *iterator_arg)
446 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
447 struct local_hostlist_entry *entry = local_hostlist_dynamic;
449 while (entry !=
NULL) {
450 if (iterator_fn !=
NULL) {
451 iterator_fn(entry->name, &entry->addr, iterator_arg);
458 if (iterator_fn !=
NULL) {
459 iterator_fn(local_hostlist_static[i].
name, &local_hostlist_static[i].addr, iterator_arg);
480 dns_local_lookup(
const char *hostname,
ip_addr_t *addr,
u8_t dns_addrtype)
483 return dns_lookup_local(hostname, addr LWIP_DNS_ADDRTYPE_ARG(dns_addrtype));
488 dns_lookup_local(
const char *hostname,
ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype))
490 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
491 struct local_hostlist_entry *entry = local_hostlist_dynamic;
492 while (entry !=
NULL) {
494 LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, entry->addr)) {
506 LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, local_hostlist_static[i].addr)) {
517 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
529 dns_local_removehost(
const char *hostname,
const ip_addr_t *addr)
532 struct local_hostlist_entry *entry = local_hostlist_dynamic;
533 struct local_hostlist_entry *last_entry =
NULL;
534 while (entry !=
NULL) {
537 struct local_hostlist_entry *free_entry;
538 if (last_entry !=
NULL) {
539 last_entry->next = entry->next;
541 local_hostlist_dynamic = entry->next;
545 memp_free(MEMP_LOCALHOSTLIST, free_entry);
565 dns_local_addhost(
const char *hostname,
const ip_addr_t *addr)
567 struct local_hostlist_entry *entry;
571 namelen =
strlen(hostname);
572 LWIP_ASSERT(
"namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
573 entry = (
struct local_hostlist_entry *)
memp_malloc(MEMP_LOCALHOSTLIST);
577 entry_name = (
char*)entry +
sizeof(
struct local_hostlist_entry);
578 MEMCPY(entry_name, hostname, namelen);
579 entry_name[namelen] = 0;
580 entry->name = entry_name;
582 entry->next = local_hostlist_dynamic;
583 local_hostlist_dynamic = entry;
605 dns_lookup(
const char *
name,
ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype))
608 #if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN)
610 #if DNS_LOCAL_HOSTLIST
611 if (dns_lookup_local(
name, addr LWIP_DNS_ADDRTYPE_ARG(dns_addrtype)) ==
ERR_OK) {
615 #ifdef DNS_LOOKUP_LOCAL_EXTERN
616 if (DNS_LOOKUP_LOCAL_EXTERN(
name, addr, LWIP_DNS_ADDRTYPE_ARG_OR_ZERO(dns_addrtype)) ==
ERR_OK) {
623 if ((dns_table[i].state == DNS_STATE_DONE) &&
625 LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, dns_table[i].ipaddr)) {
651 dns_compare_name(
const char *query,
struct pbuf* p,
u16_t start_offset)
654 u16_t response_offset = start_offset;
662 if ((n & 0xc0) == 0xc0) {
672 if ((*query) != (
u8_t)c) {
687 return response_offset + 1;
698 dns_skip_name(
struct pbuf* p,
u16_t query_idx)
701 u16_t offset = query_idx;
709 if ((n & 0xc0) == 0xc0) {
714 if (offset + n >= p->
tot_len) {
717 offset = (
u16_t)(offset + n);
739 struct dns_query qry;
741 u16_t query_idx, copy_len;
742 const char *hostname, *hostname_part;
745 struct dns_table_entry* entry = &dns_table[idx];
748 (
u16_t)(entry->server_idx), entry->name));
757 dns_call_found(idx,
NULL);
759 entry->state = DNS_STATE_UNUSED;
775 hostname = entry->name;
782 hostname_part = hostname;
783 for (n = 0; *hostname !=
'.' && *hostname != 0; ++hostname) {
786 copy_len = (
u16_t)(hostname - hostname_part);
788 pbuf_take_at(p, hostname_part, copy_len, query_idx + 1);
790 }
while (*hostname != 0);
795 if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype)) {
803 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
804 pcb_idx = entry->pcb_idx;
810 entry->txid, entry->name, entry->server_idx));
811 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
812 if (entry->is_mdns) {
815 if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype))
817 dst = &dns_mquery_v6group;
820 #if LWIP_IPV4 && LWIP_IPV6
825 dst = &dns_mquery_v4group;
832 dst = &dns_servers[entry->server_idx];
834 err = udp_sendto(dns_pcbs[pcb_idx], p, dst, dst_port);
845 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
846 static struct udp_pcb*
847 dns_alloc_random_port(
void)
859 if (!DNS_PORT_ALLOWED(port)) {
870 udp_recv(ret, dns_recv,
NULL);
886 for (i = 0; i < DNS_MAX_SOURCE_PORTS; i++) {
887 if (dns_pcbs[i] ==
NULL) {
891 if (i < DNS_MAX_SOURCE_PORTS) {
892 dns_pcbs[i] = dns_alloc_random_port();
893 if (dns_pcbs[i] !=
NULL) {
895 dns_last_pcb_idx = i;
901 for (i = 0, idx = dns_last_pcb_idx + 1; i < DNS_MAX_SOURCE_PORTS; i++, idx++) {
902 if (idx >= DNS_MAX_SOURCE_PORTS) {
905 if (dns_pcbs[idx] !=
NULL) {
906 dns_last_pcb_idx = idx;
910 return DNS_MAX_SOURCE_PORTS;
925 #if ((LWIP_DNS_SECURE & (LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT)) != 0)
929 #if LWIP_IPV4 && LWIP_IPV6
933 LWIP_ASSERT(
"invalid response", LWIP_DNS_ADDRTYPE_IS_IPV6(dns_table[idx].reqaddrtype));
934 dns_table[idx].reqaddrtype = LWIP_DNS_ADDRTYPE_IPV6;
936 LWIP_ASSERT(
"invalid response", !LWIP_DNS_ADDRTYPE_IS_IPV6(dns_table[idx].reqaddrtype));
937 dns_table[idx].reqaddrtype = LWIP_DNS_ADDRTYPE_IPV4;
942 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0)
943 for (i = 0; i < DNS_MAX_REQUESTS; i++) {
944 if (dns_requests[i].found && (dns_requests[i].dns_table_idx == idx)) {
945 (*dns_requests[i].found)(dns_table[idx].
name, addr, dns_requests[i].arg);
947 dns_requests[i].found =
NULL;
951 if (dns_requests[idx].found) {
952 (*dns_requests[idx].found)(dns_table[idx].
name, addr, dns_requests[idx].arg);
954 dns_requests[idx].found =
NULL;
956 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
958 for (i = 0; i < DNS_MAX_REQUESTS; i++) {
962 if (dns_table[i].state == DNS_STATE_ASKING) {
963 if (dns_table[i].pcb_idx == dns_table[idx].pcb_idx) {
965 dns_table[idx].pcb_idx = DNS_MAX_SOURCE_PORTS;
970 if (dns_table[idx].pcb_idx < DNS_MAX_SOURCE_PORTS) {
972 udp_remove(dns_pcbs[dns_table[idx].pcb_idx]);
973 dns_pcbs[dns_table[idx].pcb_idx] =
NULL;
974 dns_table[idx].pcb_idx = DNS_MAX_SOURCE_PORTS;
981 dns_create_txid(
void)
987 txid = (
u16_t)DNS_RAND_TXID();
991 if ((dns_table[i].state == DNS_STATE_ASKING) &&
992 (dns_table[i].txid == txid)) {
1011 dns_check_entry(
u8_t i)
1014 struct dns_table_entry *entry = &dns_table[i];
1018 switch (entry->state) {
1021 entry->txid = dns_create_txid();
1022 entry->state = DNS_STATE_ASKING;
1023 entry->server_idx = 0;
1031 (
"dns_send returned error: %s\n",
lwip_strerr(err)));
1034 case DNS_STATE_ASKING:
1035 if (--entry->tmr == 0) {
1036 if (++entry->retries == DNS_MAX_RETRIES) {
1043 entry->server_idx++;
1049 dns_call_found(i,
NULL);
1051 entry->state = DNS_STATE_UNUSED;
1056 entry->tmr = entry->retries;
1063 (
"dns_send returned error: %s\n",
lwip_strerr(err)));
1067 case DNS_STATE_DONE:
1069 if ((entry->ttl == 0) || (--entry->ttl == 0)) {
1072 entry->state = DNS_STATE_UNUSED;
1075 case DNS_STATE_UNUSED:
1088 dns_check_entries(
void)
1101 dns_correct_response(
u8_t idx,
u32_t ttl)
1103 struct dns_table_entry *entry = &dns_table[idx];
1105 entry->state = DNS_STATE_DONE;
1113 if (entry->ttl > DNS_MAX_TTL) {
1114 entry->ttl = DNS_MAX_TTL;
1116 dns_call_found(idx, &entry->ipaddr);
1118 if (entry->ttl == 0) {
1124 if (entry->state == DNS_STATE_DONE) {
1125 entry->state = DNS_STATE_UNUSED;
1133 dns_recv(
void *arg,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr,
u16_t port)
1139 struct dns_answer ans;
1140 struct dns_query qry;
1141 u16_t nquestions, nanswers;
1159 const struct dns_table_entry *entry = &dns_table[i];
1160 if ((entry->state == DNS_STATE_ASKING) &&
1161 (entry->txid == txid)) {
1173 if (nquestions != 1) {
1178 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
1179 if (!entry->is_mdns)
1184 if (!
ip_addr_cmp(addr, &dns_servers[entry->server_idx])) {
1192 if (res_idx == 0xFFFF) {
1198 if (
pbuf_copy_partial(p, &qry, SIZEOF_DNS_QUERY, res_idx) != SIZEOF_DNS_QUERY) {
1208 res_idx += SIZEOF_DNS_QUERY;
1214 while ((nanswers > 0) && (res_idx < p->tot_len)) {
1216 res_idx = dns_skip_name(p, res_idx);
1217 if (res_idx == 0xFFFF) {
1222 if (
pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx) != SIZEOF_DNS_ANSWER) {
1225 res_idx += SIZEOF_DNS_ANSWER;
1230 #if LWIP_IPV4 && LWIP_IPV6
1231 if (!LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype))
1236 if (
pbuf_copy_partial(p, &ip4addr,
sizeof(ip4_addr_t), res_idx) !=
sizeof(ip4_addr_t)) {
1239 ip_addr_copy_from_ip4(dns_table[i].ipaddr, ip4addr);
1242 dns_correct_response(i,
lwip_ntohl(ans.ttl));
1249 #if LWIP_IPV4 && LWIP_IPV6
1250 if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype))
1255 if (
pbuf_copy_partial(p, &ip6addr,
sizeof(ip6_addr_t), res_idx) !=
sizeof(ip6_addr_t)) {
1261 dns_correct_response(i,
lwip_ntohl(ans.ttl));
1268 if ((
int)(res_idx +
lwip_htons(ans.len)) > 0xFFFF) {
1274 #if LWIP_IPV4 && LWIP_IPV6
1275 if ((entry->reqaddrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) ||
1276 (entry->reqaddrtype == LWIP_DNS_ADDRTYPE_IPV6_IPV4)) {
1277 if (entry->reqaddrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) {
1279 dns_table[i].reqaddrtype = LWIP_DNS_ADDRTYPE_IPV6;
1282 dns_table[i].reqaddrtype = LWIP_DNS_ADDRTYPE_IPV4;
1285 dns_table[i].state = DNS_STATE_NEW;
1294 dns_call_found(i,
NULL);
1295 dns_table[i].state = DNS_STATE_UNUSED;
1317 dns_enqueue(
const char *
name,
size_t hostnamelen, dns_found_callback found,
1318 void *callback_arg LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype) LWIP_DNS_ISMDNS_ARG(
u8_t is_mdns))
1322 struct dns_table_entry *entry =
NULL;
1324 struct dns_req_entry* req;
1326 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0)
1330 if ((dns_table[i].state == DNS_STATE_ASKING) &&
1332 #if LWIP_IPV4 && LWIP_IPV6
1333 if (dns_table[i].reqaddrtype != dns_addrtype) {
1341 for (r = 0; r < DNS_MAX_REQUESTS; r++) {
1342 if (dns_requests[r].found == 0) {
1343 dns_requests[r].found = found;
1344 dns_requests[r].arg = callback_arg;
1345 dns_requests[r].dns_table_idx = i;
1346 LWIP_DNS_SET_ADDRTYPE(dns_requests[r].reqaddrtype, dns_addrtype);
1360 entry = &dns_table[i];
1362 if (entry->state == DNS_STATE_UNUSED) {
1366 if (entry->state == DNS_STATE_DONE) {
1367 u8_t age = dns_seqno - entry->seqno;
1377 if ((lseqi >=
DNS_TABLE_SIZE) || (dns_table[lseqi].state != DNS_STATE_DONE)) {
1384 entry = &dns_table[i];
1388 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0)
1391 for (r = 0; r < DNS_MAX_REQUESTS; r++) {
1392 if (dns_requests[r].found ==
NULL) {
1393 req = &dns_requests[r];
1402 req->dns_table_idx = i;
1405 req = &dns_requests[i];
1412 entry->state = DNS_STATE_NEW;
1413 entry->seqno = dns_seqno;
1414 LWIP_DNS_SET_ADDRTYPE(entry->reqaddrtype, dns_addrtype);
1415 LWIP_DNS_SET_ADDRTYPE(req->reqaddrtype, dns_addrtype);
1417 req->arg = callback_arg;
1420 entry->name[namelen] = 0;
1422 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0)
1423 entry->pcb_idx = dns_alloc_pcb();
1424 if (entry->pcb_idx >= DNS_MAX_SOURCE_PORTS) {
1427 entry->state = DNS_STATE_UNUSED;
1434 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
1435 entry->is_mdns = is_mdns;
1468 dns_gethostbyname(
const char *hostname,
ip_addr_t *addr, dns_found_callback found,
1471 return dns_gethostbyname_addrtype(hostname, addr, found, callback_arg, LWIP_DNS_ADDRTYPE_DEFAULT);
1489 dns_gethostbyname_addrtype(
const char *hostname,
ip_addr_t *addr, dns_found_callback found,
1490 void *callback_arg,
u8_t dns_addrtype)
1493 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
1498 if ((addr ==
NULL) ||
1499 (!hostname) || (!hostname[0])) {
1502 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) == 0)
1503 if (dns_pcbs[0] ==
NULL) {
1507 hostnamelen =
strlen(hostname);
1514 #if LWIP_HAVE_LOOPIF
1515 if (
strcmp(hostname,
"localhost") == 0) {
1523 #if LWIP_IPV4 && LWIP_IPV6
1524 if ((
IP_IS_V6(addr) && (dns_addrtype != LWIP_DNS_ADDRTYPE_IPV4)) ||
1525 (
IP_IS_V4(addr) && (dns_addrtype != LWIP_DNS_ADDRTYPE_IPV6)))
1532 if (dns_lookup(hostname, addr LWIP_DNS_ADDRTYPE_ARG(dns_addrtype)) ==
ERR_OK) {
1535 #if LWIP_IPV4 && LWIP_IPV6
1536 if ((dns_addrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) || (dns_addrtype == LWIP_DNS_ADDRTYPE_IPV6_IPV4)) {
1539 if (dns_addrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) {
1540 fallback = LWIP_DNS_ADDRTYPE_IPV6;
1542 fallback = LWIP_DNS_ADDRTYPE_IPV4;
1544 if (dns_lookup(hostname, addr LWIP_DNS_ADDRTYPE_ARG(fallback)) ==
ERR_OK) {
1552 #if LWIP_DNS_SUPPORT_MDNS_QUERIES
1553 if (
strstr(hostname,
".local") == &hostname[hostnamelen] - 6) {
1569 return dns_enqueue(hostname, hostnamelen, found, callback_arg LWIP_DNS_ADDRTYPE_ARG(dns_addrtype)
1570 LWIP_DNS_ISMDNS_ARG(is_mdns));