90 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0) 91 #define DNS_RAND_TXID LWIP_RAND 93 static u16_t dns_txid;
94 #define DNS_RAND_TXID() (++dns_txid) 99 #ifndef DNS_PORT_ALLOWED 100 #define DNS_PORT_ALLOWED(port) ((port) >= 1024) 104 #ifndef DNS_SERVER_PORT 105 #define DNS_SERVER_PORT 53 109 #ifndef DNS_MAX_RETRIES 110 #define DNS_MAX_RETRIES 4 115 #define DNS_MAX_TTL 604800 122 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0) 123 #ifndef DNS_MAX_REQUESTS 124 #define DNS_MAX_REQUESTS DNS_TABLE_SIZE 129 #define DNS_MAX_REQUESTS DNS_TABLE_SIZE 133 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 134 #ifndef DNS_MAX_SOURCE_PORTS 135 #define DNS_MAX_SOURCE_PORTS DNS_MAX_REQUESTS 138 #ifdef DNS_MAX_SOURCE_PORTS 139 #undef DNS_MAX_SOURCE_PORTS 141 #define DNS_MAX_SOURCE_PORTS 1 144 #if LWIP_IPV4 && LWIP_IPV6 145 #define LWIP_DNS_ADDRTYPE_IS_IPV6(t) (((t) == LWIP_DNS_ADDRTYPE_IPV6_IPV4) || ((t) == LWIP_DNS_ADDRTYPE_IPV6)) 146 #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))) 147 #define LWIP_DNS_ADDRTYPE_ARG(x) , x 148 #define LWIP_DNS_ADDRTYPE_ARG_OR_ZERO(x) x 149 #define LWIP_DNS_SET_ADDRTYPE(x, y) do { x = y; } while(0) 152 #define LWIP_DNS_ADDRTYPE_IS_IPV6(t) 1 154 #define LWIP_DNS_ADDRTYPE_IS_IPV6(t) 0 156 #define LWIP_DNS_ADDRTYPE_MATCH_IP(t, ip) 1 157 #define LWIP_DNS_ADDRTYPE_ARG(x) 158 #define LWIP_DNS_ADDRTYPE_ARG_OR_ZERO(x) 0 159 #define LWIP_DNS_SET_ADDRTYPE(x, y) 163 #define DNS_RRTYPE_A 1 164 #define DNS_RRTYPE_NS 2 165 #define DNS_RRTYPE_MD 3 166 #define DNS_RRTYPE_MF 4 167 #define DNS_RRTYPE_CNAME 5 168 #define DNS_RRTYPE_SOA 6 169 #define DNS_RRTYPE_MB 7 170 #define DNS_RRTYPE_MG 8 171 #define DNS_RRTYPE_MR 9 172 #define DNS_RRTYPE_NULL 10 173 #define DNS_RRTYPE_WKS 11 174 #define DNS_RRTYPE_PTR 12 175 #define DNS_RRTYPE_HINFO 13 176 #define DNS_RRTYPE_MINFO 14 177 #define DNS_RRTYPE_MX 15 178 #define DNS_RRTYPE_TXT 16 179 #define DNS_RRTYPE_AAAA 28 182 #define DNS_RRCLASS_IN 1 183 #define DNS_RRCLASS_CS 2 184 #define DNS_RRCLASS_CH 3 185 #define DNS_RRCLASS_HS 4 186 #define DNS_RRCLASS_FLUSH 0x800 189 #define DNS_FLAG1_RESPONSE 0x80 190 #define DNS_FLAG1_OPCODE_STATUS 0x10 191 #define DNS_FLAG1_OPCODE_INVERSE 0x08 192 #define DNS_FLAG1_OPCODE_STANDARD 0x00 193 #define DNS_FLAG1_AUTHORATIVE 0x04 194 #define DNS_FLAG1_TRUNC 0x02 195 #define DNS_FLAG1_RD 0x01 196 #define DNS_FLAG2_RA 0x80 197 #define DNS_FLAG2_ERR_MASK 0x0f 198 #define DNS_FLAG2_ERR_NONE 0x00 199 #define DNS_FLAG2_ERR_NAME 0x03 202 #define DNS_STATE_UNUSED 0 203 #define DNS_STATE_NEW 1 204 #define DNS_STATE_ASKING 2 205 #define DNS_STATE_DONE 3 207 #ifdef PACK_STRUCT_USE_INCLUDES 222 #ifdef PACK_STRUCT_USE_INCLUDES 225 #define SIZEOF_DNS_HDR 12 235 #define SIZEOF_DNS_QUERY 4 247 #define SIZEOF_DNS_ANSWER 10 249 #define SIZEOF_DNS_ANSWER_ASSERT 12 252 struct dns_table_entry {
261 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 265 #if LWIP_IPV4 && LWIP_IPV6 272 struct dns_req_entry {
274 dns_found_callback found;
277 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0) 280 #if LWIP_IPV4 && LWIP_IPV6 285 #if DNS_LOCAL_HOSTLIST 287 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 290 static struct local_hostlist_entry *local_hostlist_dynamic;
295 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_PRE 296 #define DNS_LOCAL_HOSTLIST_STORAGE_PRE static 300 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_POST 301 #define DNS_LOCAL_HOSTLIST_STORAGE_POST 303 DNS_LOCAL_HOSTLIST_STORAGE_PRE
struct local_hostlist_entry local_hostlist_static[]
304 DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;
308 static void dns_init_local(
void);
313 static void dns_recv(
void *s,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr,
u16_t port);
314 static void dns_check_entries(
void);
322 static struct udp_pcb *dns_pcbs[DNS_MAX_SOURCE_PORTS];
323 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 324 static u8_t dns_last_pcb_idx;
326 static u8_t dns_seqno;
328 static struct dns_req_entry dns_requests[DNS_MAX_REQUESTS];
331 #ifndef LWIP_DNS_STRICMP 332 #define LWIP_DNS_STRICMP(str1, str2) dns_stricmp(str1, str2) 337 dns_stricmp(
const char* str1,
const char* str2)
345 char c1_upc = c1 | 0x20;
346 if ((c1_upc >=
'a') && (c1_upc <=
'z')) {
349 char c2_upc = c2 | 0x20;
350 if (c1_upc != c2_upc) {
372 #ifdef DNS_SERVER_ADDRESS 375 DNS_SERVER_ADDRESS(&dnsserver);
376 dns_setserver(0, &dnsserver);
380 sizeof(
struct dns_query) == SIZEOF_DNS_QUERY);
382 sizeof(
struct dns_answer) <= SIZEOF_DNS_ANSWER_ASSERT);
387 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) == 0) 388 if (dns_pcbs[0] ==
NULL) {
389 dns_pcbs[0] = udp_new();
394 LWIP_ASSERT(
"For implicit initialization to work, DNS_STATE_UNUSED needs to be 0",
395 DNS_STATE_UNUSED == 0);
398 udp_bind(dns_pcbs[0], IP_ADDR_ANY, 0);
399 udp_recv(dns_pcbs[0], dns_recv,
NULL);
403 #if DNS_LOCAL_HOSTLIST 418 if (dnsserver !=
NULL) {
419 dns_servers[numdns] = (*dnsserver);
421 dns_servers[numdns] = *IP_ADDR_ANY;
434 dns_getserver(
u8_t numdns)
437 return dns_servers[numdns];
454 #if DNS_LOCAL_HOSTLIST 458 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT) 460 struct local_hostlist_entry *entry;
462 struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
464 for (i = 0; i <
sizeof(local_hostlist_init) /
sizeof(
struct local_hostlist_entry); i++) {
465 struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
467 namelen = strlen(init_entry->name);
468 LWIP_ASSERT(
"namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
469 entry = (
struct local_hostlist_entry *)
memp_malloc(MEMP_LOCALHOSTLIST);
472 char* entry_name = (
char*)entry +
sizeof(
struct local_hostlist_entry);
473 MEMCPY(entry_name, init_entry->name, namelen);
474 entry_name[namelen] = 0;
475 entry->name = entry_name;
476 entry->addr = init_entry->addr;
477 entry->next = local_hostlist_dynamic;
478 local_hostlist_dynamic = entry;
493 dns_lookup_local(
const char *hostname,
ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype))
495 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 496 struct local_hostlist_entry *entry = local_hostlist_dynamic;
497 while (entry !=
NULL) {
498 if ((LWIP_DNS_STRICMP(entry->name, hostname) == 0) &&
499 LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, entry->addr)) {
509 for (i = 0; i <
sizeof(local_hostlist_static) /
sizeof(
struct local_hostlist_entry); i++) {
510 if ((LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) &&
511 LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, local_hostlist_static[i].addr)) {
522 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 532 dns_local_removehost(
const char *hostname,
const ip_addr_t *addr)
535 struct local_hostlist_entry *entry = local_hostlist_dynamic;
536 struct local_hostlist_entry *last_entry =
NULL;
537 while (entry !=
NULL) {
538 if (((hostname ==
NULL) || !LWIP_DNS_STRICMP(entry->name, hostname)) &&
540 struct local_hostlist_entry *free_entry;
541 if (last_entry !=
NULL) {
542 last_entry->next = entry->next;
544 local_hostlist_dynamic = entry->next;
548 memp_free(MEMP_LOCALHOSTLIST, free_entry);
567 dns_local_addhost(
const char *hostname,
const ip_addr_t *addr)
569 struct local_hostlist_entry *entry;
573 namelen = strlen(hostname);
574 LWIP_ASSERT(
"namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
575 entry = (
struct local_hostlist_entry *)
memp_malloc(MEMP_LOCALHOSTLIST);
579 entry_name = (
char*)entry +
sizeof(
struct local_hostlist_entry);
580 MEMCPY(entry_name, hostname, namelen);
581 entry_name[namelen] = 0;
582 entry->name = entry_name;
584 entry->next = local_hostlist_dynamic;
585 local_hostlist_dynamic = entry;
606 dns_lookup(
const char *name,
ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype))
609 #if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) 611 #if DNS_LOCAL_HOSTLIST 612 if (dns_lookup_local(name, addr LWIP_DNS_ADDRTYPE_ARG(dns_addrtype)) ==
ERR_OK) {
616 #ifdef DNS_LOOKUP_LOCAL_EXTERN 617 if (DNS_LOOKUP_LOCAL_EXTERN(name, addr, LWIP_DNS_ADDRTYPE_ARG_OR_ZERO(dns_addrtype))) {
624 if ((dns_table[i].state == DNS_STATE_DONE) &&
625 (LWIP_DNS_STRICMP(name, dns_table[i].name) == 0) &&
626 LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, dns_table[i].ipaddr)) {
652 dns_compare_name(
char *query,
struct pbuf* p,
u16_t start_offset)
655 u16_t response_offset = start_offset;
660 if ((n & 0xc0) == 0xc0) {
677 return response_offset + 1;
688 dns_parse_name(
struct pbuf* p,
u16_t query_idx)
695 if ((n & 0xc0) == 0xc0) {
707 return query_idx + 1;
721 struct dns_query qry;
723 u16_t query_idx, copy_len;
724 const char *hostname, *hostname_part;
727 struct dns_table_entry* entry = &dns_table[
idx];
730 (
u16_t)(entry->server_idx), entry->name));
735 dns_call_found(idx,
NULL);
737 entry->state = DNS_STATE_UNUSED;
746 memset(&hdr, 0, SIZEOF_DNS_HDR);
747 hdr.id =
htons(entry->txid);
748 hdr.flags1 = DNS_FLAG1_RD;
751 hostname = entry->name;
755 query_idx = SIZEOF_DNS_HDR;
758 hostname_part = hostname;
759 for (n = 0; *hostname !=
'.' && *hostname != 0; ++hostname) {
762 copy_len = (
u16_t)(hostname - hostname_part);
764 pbuf_take_at(p, hostname_part, copy_len, query_idx + 1);
766 }
while (*hostname != 0);
771 if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype)) {
772 qry.type =
PP_HTONS(DNS_RRTYPE_AAAA);
779 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 780 pcb_idx = entry->pcb_idx;
786 entry->txid, entry->name, entry->server_idx));
787 err = udp_sendto(dns_pcbs[pcb_idx], p, &dns_servers[entry->server_idx], DNS_SERVER_PORT);
798 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 799 static struct udp_pcb*
800 dns_alloc_random_port(
void)
812 if (!DNS_PORT_ALLOWED(port)) {
817 err = udp_bind(ret, IP_ADDR_ANY, port);
823 udp_recv(ret, dns_recv,
NULL);
839 for (i = 0; i < DNS_MAX_SOURCE_PORTS; i++) {
840 if (dns_pcbs[i] ==
NULL) {
844 if (i < DNS_MAX_SOURCE_PORTS) {
845 dns_pcbs[i] = dns_alloc_random_port();
846 if (dns_pcbs[i] !=
NULL) {
848 dns_last_pcb_idx = i;
854 for (i = 0, idx = dns_last_pcb_idx + 1; i < DNS_MAX_SOURCE_PORTS; i++, idx++) {
855 if (idx >= DNS_MAX_SOURCE_PORTS) {
858 if (dns_pcbs[idx] !=
NULL) {
859 dns_last_pcb_idx =
idx;
863 return DNS_MAX_SOURCE_PORTS;
878 #if ((LWIP_DNS_SECURE & (LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT)) != 0) 882 #if LWIP_IPV4 && LWIP_IPV6 886 LWIP_ASSERT(
"invalid response", LWIP_DNS_ADDRTYPE_IS_IPV6(dns_table[idx].reqaddrtype));
887 dns_table[
idx].reqaddrtype = LWIP_DNS_ADDRTYPE_IPV6;
889 LWIP_ASSERT(
"invalid response", !LWIP_DNS_ADDRTYPE_IS_IPV6(dns_table[idx].reqaddrtype));
890 dns_table[
idx].reqaddrtype = LWIP_DNS_ADDRTYPE_IPV4;
895 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0) 896 for (i = 0; i < DNS_MAX_REQUESTS; i++) {
897 if (dns_requests[i].found && (dns_requests[i].dns_table_idx == idx)) {
898 (*dns_requests[i].found)(dns_table[idx].name, addr, dns_requests[i].arg);
900 dns_requests[i].found =
NULL;
904 if (dns_requests[idx].found) {
905 (*dns_requests[
idx].found)(dns_table[idx].name, addr, dns_requests[idx].arg);
907 dns_requests[
idx].found =
NULL;
909 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 911 for (i = 0; i < DNS_MAX_REQUESTS; i++) {
915 if (dns_table[i].state == DNS_STATE_ASKING) {
916 if (dns_table[i].pcb_idx == dns_table[idx].pcb_idx) {
918 dns_table[
idx].pcb_idx = DNS_MAX_SOURCE_PORTS;
923 if (dns_table[idx].pcb_idx < DNS_MAX_SOURCE_PORTS) {
925 udp_remove(dns_pcbs[dns_table[idx].pcb_idx]);
926 dns_pcbs[dns_table[
idx].pcb_idx] =
NULL;
927 dns_table[
idx].pcb_idx = DNS_MAX_SOURCE_PORTS;
934 dns_create_txid(
void)
940 txid = (
u16_t)DNS_RAND_TXID();
944 if ((dns_table[i].state == DNS_STATE_ASKING) &&
945 (dns_table[i].txid == txid)) {
964 dns_check_entry(
u8_t i)
967 struct dns_table_entry *entry = &dns_table[i];
969 LWIP_ASSERT(
"array index out of bounds", i < DNS_TABLE_SIZE);
971 switch (entry->state) {
973 case DNS_STATE_NEW: {
976 txid = dns_create_txid();
978 entry->state = DNS_STATE_ASKING;
979 entry->server_idx = 0;
987 (
"dns_send returned error: %s\n",
lwip_strerr(err)));
992 case DNS_STATE_ASKING:
993 if (--entry->tmr == 0) {
994 if (++entry->retries == DNS_MAX_RETRIES) {
1003 dns_call_found(i,
NULL);
1005 entry->state = DNS_STATE_UNUSED;
1010 entry->tmr = entry->retries;
1017 (
"dns_send returned error: %s\n",
lwip_strerr(err)));
1021 case DNS_STATE_DONE:
1023 if ((entry->ttl == 0) || (--entry->ttl == 0)) {
1026 entry->state = DNS_STATE_UNUSED;
1029 case DNS_STATE_UNUSED:
1042 dns_check_entries(
void)
1057 dns_recv(
void *arg,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr,
u16_t port)
1063 struct dns_answer ans;
1064 struct dns_query qry;
1065 u16_t nquestions, nanswers;
1072 if (p->
tot_len < (SIZEOF_DNS_HDR + SIZEOF_DNS_QUERY)) {
1081 txid =
htons(hdr.id);
1083 struct dns_table_entry *entry = &dns_table[i];
1085 if ((entry->state == DNS_STATE_ASKING) &&
1086 (entry->txid == txid)) {
1089 entry->state = DNS_STATE_DONE;
1090 dns_err = hdr.flags2 & DNS_FLAG2_ERR_MASK;
1094 nquestions =
htons(hdr.numquestions);
1095 nanswers =
htons(hdr.numanswers);
1098 if (((hdr.flags1 & DNS_FLAG1_RESPONSE) == 0) || (dns_err != 0) || (nquestions != 1)) {
1106 if (!
ip_addr_cmp(addr, &dns_servers[entry->server_idx])) {
1113 res_idx = dns_compare_name(entry->name, p, SIZEOF_DNS_HDR);
1114 if (res_idx == 0xFFFF) {
1122 if ((qry.cls !=
PP_HTONS(DNS_RRCLASS_IN)) ||
1123 (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type !=
PP_HTONS(DNS_RRTYPE_AAAA))) ||
1124 (!LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type !=
PP_HTONS(DNS_RRTYPE_A)))) {
1130 res_idx += SIZEOF_DNS_QUERY;
1132 while ((nanswers > 0) && (res_idx < p->tot_len)) {
1134 res_idx = dns_parse_name(p, res_idx);
1138 if (ans.cls ==
PP_HTONS(DNS_RRCLASS_IN)) {
1140 if ((ans.type ==
PP_HTONS(DNS_RRTYPE_A)) && (ans.len ==
PP_HTONS(
sizeof(ip4_addr_t)))) {
1141 #if LWIP_IPV4 && LWIP_IPV6 1142 if (!LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype))
1146 res_idx += SIZEOF_DNS_ANSWER;
1148 entry->ttl =
ntohl(ans.ttl);
1149 if (entry->ttl > DNS_MAX_TTL) {
1150 entry->ttl = DNS_MAX_TTL;
1154 ip_addr_copy_from_ip4(entry->ipaddr, ip4addr);
1159 dns_call_found(entry_idx, &entry->ipaddr);
1160 if (entry->ttl == 0) {
1173 if ((ans.type ==
PP_HTONS(DNS_RRTYPE_AAAA)) && (ans.len ==
PP_HTONS(
sizeof(ip6_addr_t)))) {
1174 #if LWIP_IPV4 && LWIP_IPV6 1175 if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype))
1179 res_idx += SIZEOF_DNS_ANSWER;
1181 entry->ttl =
ntohl(ans.ttl);
1182 if (entry->ttl > DNS_MAX_TTL) {
1183 entry->ttl = DNS_MAX_TTL;
1192 dns_call_found(entry_idx, &entry->ipaddr);
1193 if (entry->ttl == 0) {
1207 res_idx += SIZEOF_DNS_ANSWER +
htons(ans.len);
1210 #if LWIP_IPV4 && LWIP_IPV6 1211 if ((entry->reqaddrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) ||
1212 (entry->reqaddrtype == LWIP_DNS_ADDRTYPE_IPV6_IPV4)) {
1213 if (entry->reqaddrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) {
1215 entry->reqaddrtype = LWIP_DNS_ADDRTYPE_IPV6;
1218 entry->reqaddrtype = LWIP_DNS_ADDRTYPE_IPV4;
1221 entry->state = DNS_STATE_NEW;
1222 dns_check_entry(entry_idx);
1238 dns_call_found(entry_idx,
NULL);
1241 dns_table[entry_idx].state = DNS_STATE_UNUSED;
1259 dns_enqueue(
const char *name,
size_t hostnamelen, dns_found_callback found,
1260 void *callback_arg LWIP_DNS_ADDRTYPE_ARG(
u8_t dns_addrtype))
1264 struct dns_table_entry *entry =
NULL;
1266 struct dns_req_entry* req;
1268 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0) 1272 if ((dns_table[i].state == DNS_STATE_ASKING) &&
1273 (LWIP_DNS_STRICMP(name, dns_table[i].name) == 0)) {
1274 #if LWIP_IPV4 && LWIP_IPV6 1275 if (dns_table[i].reqaddrtype != dns_addrtype) {
1283 for (r = 0; r < DNS_MAX_REQUESTS; r++) {
1284 if (dns_requests[r].found == 0) {
1285 dns_requests[r].found = found;
1286 dns_requests[r].arg = callback_arg;
1287 dns_requests[r].dns_table_idx = i;
1288 LWIP_DNS_SET_ADDRTYPE(dns_requests[r].reqaddrtype, dns_addrtype);
1302 entry = &dns_table[i];
1304 if (entry->state == DNS_STATE_UNUSED) {
1308 if (entry->state == DNS_STATE_DONE) {
1309 if ((
u8_t)(dns_seqno - entry->seqno) > lseq) {
1310 lseq = dns_seqno - entry->seqno;
1317 if (i == DNS_TABLE_SIZE) {
1318 if ((lseqi >= DNS_TABLE_SIZE) || (dns_table[lseqi].state != DNS_STATE_DONE)) {
1325 entry = &dns_table[i];
1329 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0) 1332 for (r = 0; r < DNS_MAX_REQUESTS; r++) {
1333 if (dns_requests[r].found ==
NULL) {
1334 req = &dns_requests[r];
1343 req->dns_table_idx = i;
1346 req = &dns_requests[i];
1353 entry->state = DNS_STATE_NEW;
1354 entry->seqno = dns_seqno;
1355 LWIP_DNS_SET_ADDRTYPE(entry->reqaddrtype, dns_addrtype);
1356 LWIP_DNS_SET_ADDRTYPE(req->reqaddrtype, dns_addrtype);
1358 req->arg = callback_arg;
1360 MEMCPY(entry->name, name, namelen);
1361 entry->name[namelen] = 0;
1363 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) != 0) 1364 entry->pcb_idx = dns_alloc_pcb();
1365 if (entry->pcb_idx >= DNS_MAX_SOURCE_PORTS) {
1368 entry->state = DNS_STATE_UNUSED;
1404 dns_gethostbyname(
const char *hostname,
ip_addr_t *addr, dns_found_callback found,
1407 return dns_gethostbyname_addrtype(hostname, addr, found, callback_arg, LWIP_DNS_ADDRTYPE_DEFAULT);
1417 dns_gethostbyname_addrtype(
const char *hostname,
ip_addr_t *addr, dns_found_callback found,
1418 void *callback_arg,
u8_t dns_addrtype)
1423 if ((addr ==
NULL) ||
1424 (!hostname) || (!hostname[0])) {
1427 #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_SRC_PORT) == 0) 1428 if (dns_pcbs[0] ==
NULL) {
1432 hostnamelen = strlen(hostname);
1439 #if LWIP_HAVE_LOOPIF 1440 if (strcmp(hostname,
"localhost") == 0) {
1448 #if LWIP_IPV4 && LWIP_IPV6 1449 if ((
IP_IS_V6(addr) && (dns_addrtype != LWIP_DNS_ADDRTYPE_IPV4)) ||
1450 (!
IP_IS_V6(addr) && (dns_addrtype != LWIP_DNS_ADDRTYPE_IPV6)))
1457 if (dns_lookup(hostname, addr LWIP_DNS_ADDRTYPE_ARG(dns_addrtype)) ==
ERR_OK) {
1460 #if LWIP_IPV4 && LWIP_IPV6 1461 if ((dns_addrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) || (dns_addrtype == LWIP_DNS_ADDRTYPE_IPV6_IPV4)) {
1464 if (dns_addrtype == LWIP_DNS_ADDRTYPE_IPV4_IPV6) {
1465 fallback = LWIP_DNS_ADDRTYPE_IPV6;
1467 fallback = LWIP_DNS_ADDRTYPE_IPV4;
1469 if (dns_lookup(hostname, addr LWIP_DNS_ADDRTYPE_ARG(fallback)) ==
ERR_OK) {
1478 return dns_enqueue(hostname, hostnamelen, found, callback_arg LWIP_DNS_ADDRTYPE_ARG(dns_addrtype));
#define DNS_MAX_NAME_LENGTH
#define PACK_STRUCT_STRUCT
#define LWIP_DBG_LEVEL_WARNING
#define ip_addr_isany_val(ipaddr)
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
#define PACK_STRUCT_FLD_8(x)
#define MEMCPY(dst, src, len)
#define PACK_STRUCT_FIELD(x)
void memp_free(memp_t type, void *mem)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u8_t pbuf_free(struct pbuf *p)
#define ip_addr_copy(dest, src)
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
#define IP_IS_V6_VAL(ipaddr)
#define ip_addr_cmp(addr1, addr2)
#define LWIP_ASSERT(message, assertion)
#define ip_addr_debug_print(debug, ipaddr)
#define ipaddr_aton(cp, addr)
#define PACK_STRUCT_BEGIN
#define ip_addr_copy_from_ip6(dest, src)
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
u8_t pbuf_get_at(struct pbuf *p, u16_t offset)
#define ip_addr_set_loopback(is_ipv6, ipaddr)
void * memp_malloc(memp_t type)
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
#define LWIP_DEBUGF(debug, message)
#define LWIP_UNUSED_ARG(x)