87 #ifndef DNS_SERVER_ADDRESS 88 #define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) 92 #ifndef DNS_SERVER_PORT 93 #define DNS_SERVER_PORT 53 97 #ifndef DNS_MAX_RETRIES 98 #define DNS_MAX_RETRIES 4 103 #define DNS_MAX_TTL 604800 107 #define DNS_FLAG1_RESPONSE 0x80 108 #define DNS_FLAG1_OPCODE_STATUS 0x10 109 #define DNS_FLAG1_OPCODE_INVERSE 0x08 110 #define DNS_FLAG1_OPCODE_STANDARD 0x00 111 #define DNS_FLAG1_AUTHORATIVE 0x04 112 #define DNS_FLAG1_TRUNC 0x02 113 #define DNS_FLAG1_RD 0x01 114 #define DNS_FLAG2_RA 0x80 115 #define DNS_FLAG2_ERR_MASK 0x0f 116 #define DNS_FLAG2_ERR_NONE 0x00 117 #define DNS_FLAG2_ERR_NAME 0x03 120 #define DNS_STATE_UNUSED 0 121 #define DNS_STATE_NEW 1 122 #define DNS_STATE_ASKING 2 123 #define DNS_STATE_DONE 3 125 #ifdef PACK_STRUCT_USE_INCLUDES 140 #ifdef PACK_STRUCT_USE_INCLUDES 143 #define SIZEOF_DNS_HDR 12 153 #define SIZEOF_DNS_QUERY 4 165 #define SIZEOF_DNS_ANSWER 10 168 struct dns_table_entry {
179 dns_found_callback found;
183 #if DNS_LOCAL_HOSTLIST 185 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 188 static struct local_hostlist_entry *local_hostlist_dynamic;
193 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_PRE 194 #define DNS_LOCAL_HOSTLIST_STORAGE_PRE static 198 #ifndef DNS_LOCAL_HOSTLIST_STORAGE_POST 199 #define DNS_LOCAL_HOSTLIST_STORAGE_POST 201 DNS_LOCAL_HOSTLIST_STORAGE_PRE
struct local_hostlist_entry local_hostlist_static[]
202 DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;
206 static void dns_init_local();
212 static void dns_check_entries(
void);
219 static struct udp_pcb *dns_pcb;
220 static u8_t dns_seqno;
225 static u8_t* dns_payload;
239 DNS_SERVER_ADDRESS(&dnsserver);
244 if (dns_pcb ==
NULL) {
247 if (dns_pcb !=
NULL) {
250 LWIP_ASSERT(
"For implicit initialization to work, DNS_STATE_UNUSED needs to be 0",
251 DNS_STATE_UNUSED == 0);
255 udp_recv(dns_pcb, dns_recv,
NULL);
258 dns_setserver(0, &dnsserver);
261 #if DNS_LOCAL_HOSTLIST 277 dns_servers[numdns] = (*dnsserver);
289 dns_getserver(
u8_t numdns)
292 return dns_servers[numdns];
305 if (dns_pcb !=
NULL) {
311 #if DNS_LOCAL_HOSTLIST 315 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT) 317 struct local_hostlist_entry *
entry;
319 struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
321 for (
i = 0;
i <
sizeof(local_hostlist_init) /
sizeof(
struct local_hostlist_entry);
i++) {
322 struct local_hostlist_entry *init_entry = &local_hostlist_init[
i];
325 LWIP_ASSERT(
"namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN",
namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
329 entry->name = (
char*)
entry +
sizeof(
struct local_hostlist_entry);
332 entry->addr = init_entry->addr;
333 entry->next = local_hostlist_dynamic;
334 local_hostlist_dynamic =
entry;
348 dns_lookup_local(
const char *
hostname)
350 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 351 struct local_hostlist_entry *
entry = local_hostlist_dynamic;
360 for (
i = 0;
i <
sizeof(local_hostlist_static) /
sizeof(
struct local_hostlist_entry);
i++) {
369 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 382 struct local_hostlist_entry *
entry = local_hostlist_dynamic;
383 struct local_hostlist_entry *last_entry =
NULL;
388 if (last_entry !=
NULL) {
389 last_entry->next =
entry->next;
391 local_hostlist_dynamic =
entry->next;
416 struct local_hostlist_entry *
entry;
420 LWIP_ASSERT(
"namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN",
namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
425 entry->name = (
char*)
entry +
sizeof(
struct local_hostlist_entry);
429 entry->next = local_hostlist_dynamic;
430 local_hostlist_dynamic =
entry;
450 dns_lookup(
const char *
name)
453 #if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) 456 #if DNS_LOCAL_HOSTLIST 461 #ifdef DNS_LOOKUP_LOCAL_EXTERN 469 if ((dns_table[
i].
state == DNS_STATE_DONE) &&
481 #if DNS_DOES_NAME_CHECK 493 dns_compare_name(
unsigned char *
query,
unsigned char *response)
500 if ((
n & 0xc0) == 0xc0) {
506 if ((*
query) != (*response)) {
515 }
while (*response != 0);
527 static unsigned char *
528 dns_parse_name(
unsigned char *
query)
535 if ((
n & 0xc0) == 0xc0) {
545 }
while (*
query != 0);
564 struct dns_query qry;
567 const char *pHostname;
581 hdr = (
struct dns_hdr*)
p->payload;
584 hdr->flags1 = DNS_FLAG1_RD;
586 query = (
char*)
hdr + SIZEOF_DNS_HDR;
595 for(
n = 0; *pHostname !=
'.' && *pHostname != 0; ++pHostname) {
601 }
while(*pHostname != 0);
613 udp_connect(dns_pcb, &dns_servers[numdns], DNS_SERVER_PORT);
615 err = udp_sendto(dns_pcb,
p, &dns_servers[numdns], DNS_SERVER_PORT);
636 dns_check_entry(
u8_t i)
639 struct dns_table_entry *
pEntry = &dns_table[
i];
645 case DNS_STATE_NEW: {
647 pEntry->state = DNS_STATE_ASKING;
661 case DNS_STATE_ASKING: {
663 if (++
pEntry->retries == DNS_MAX_RETRIES) {
676 pEntry->state = DNS_STATE_UNUSED;
695 case DNS_STATE_DONE: {
700 pEntry->state = DNS_STATE_UNUSED;
705 case DNS_STATE_UNUSED:
718 dns_check_entries(
void)
738 struct dns_answer ans;
739 struct dns_table_entry *
pEntry;
740 u16_t nquestions, nanswers;
755 if (
p->tot_len < (SIZEOF_DNS_HDR + SIZEOF_DNS_QUERY + SIZEOF_DNS_ANSWER)) {
764 hdr = (
struct dns_hdr*)dns_payload;
768 if(
pEntry->state == DNS_STATE_ASKING) {
770 pEntry->state = DNS_STATE_DONE;
771 pEntry->err =
hdr->flags2 & DNS_FLAG2_ERR_MASK;
775 nquestions =
htons(
hdr->numquestions);
779 if (((
hdr->flags1 & DNS_FLAG1_RESPONSE) == 0) || (
pEntry->err != 0) || (nquestions != 1)) {
785 #if DNS_DOES_NAME_CHECK 787 if (dns_compare_name((
unsigned char *)(
pEntry->name), (
unsigned char *)dns_payload + SIZEOF_DNS_HDR) != 0) {
795 pHostname = (
char *) dns_parse_name((
unsigned char *)dns_payload + SIZEOF_DNS_HDR) + SIZEOF_DNS_QUERY;
797 while (nanswers > 0) {
799 pHostname = (
char *) dns_parse_name((
unsigned char *)pHostname);
802 SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
803 if((ans.type ==
PP_HTONS(DNS_RRTYPE_A)) && (ans.cls ==
PP_HTONS(DNS_RRCLASS_IN)) &&
807 if (
pEntry->ttl > DNS_MAX_TTL) {
808 pEntry->ttl = DNS_MAX_TTL;
822 pHostname = pHostname + SIZEOF_DNS_ANSWER +
htons(ans.len);
842 pEntry->state = DNS_STATE_UNUSED;
860 dns_enqueue(
const char *
name, dns_found_callback found,
void *callback_arg)
872 if (
pEntry->state == DNS_STATE_UNUSED)
876 if (
pEntry->state == DNS_STATE_DONE) {
877 if ((dns_seqno -
pEntry->seqno) > lseq) {
878 lseq = dns_seqno -
pEntry->seqno;
901 pEntry->state = DNS_STATE_NEW;
902 pEntry->seqno = dns_seqno++;
904 pEntry->arg = callback_arg;
967 return dns_enqueue(
hostname, found, callback_arg);
#define DNS_MAX_NAME_LENGTH
#define ip_addr_copy(dest, src)
#define SMEMCPY(dst, src, len)
ACPI_SIZE strlen(const char *String)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
#define LWIP_ASSERT(message, assertion)
#define PACK_STRUCT_FIELD(x)
#define ip_addr_set_loopback(ipaddr)
void memp_free(memp_t type, void *mem)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define PACK_STRUCT_STRUCT
u8_t pbuf_free(struct pbuf *p)
#define LWIP_DEBUGF(debug, message)
static void free_entry(Entry *entry)
#define MEMCPY(DST, SRC, BYTES)
#define ip_addr_debug_print(debug, ipaddr)
#define LWIP_DBG_LEVEL_WARNING
GLenum const GLvoid * addr
u32_t ipaddr_addr(const char *cp)
#define PACK_STRUCT_BEGIN
#define LWIP_MEM_ALIGN_BUFFER(size)
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define ip4_addr_set_u32(dest_ipaddr, src_u32)
#define ip_addr_isany(addr1)
#define ip_addr_cmp(addr1, addr2)
#define LWIP_MEM_ALIGN(addr)
int strcmp(const char *String1, const char *String2)
GLuint GLuint GLsizei GLenum type
void * memp_malloc(memp_t type)
#define LWIP_UNUSED_ARG(x)
#define ip4_addr_get_u32(src_ipaddr)
GLuint const GLchar * name