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
168struct dns_table_entry {
179 dns_found_callback found;
183#if DNS_LOCAL_HOSTLIST
185#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
188static 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
201DNS_LOCAL_HOSTLIST_STORAGE_PRE
struct local_hostlist_entry local_hostlist_static[]
202 DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;
206static void dns_init_local();
212static void dns_check_entries(
void);
219static struct udp_pcb *dns_pcb;
220static u8_t dns_seqno;
225static 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);
289dns_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;
348dns_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;
387 struct local_hostlist_entry *free_entry;
388 if (last_entry !=
NULL) {
391 local_hostlist_dynamic =
entry->next;
395 memp_free(MEMP_LOCALHOSTLIST, free_entry);
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;
450dns_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
493dns_compare_name(
unsigned char *
query,
unsigned char *response)
500 if ((
n & 0xc0) == 0xc0) {
506 if ((*
query) != (*response)) {
515 }
while (*response != 0);
527static unsigned char *
528dns_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);
636dns_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:
718dns_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;
860dns_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);
int strcmp(const char *String1, const char *String2)
ACPI_SIZE strlen(const char *String)
#define LWIP_UNUSED_ARG(x)
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_FIELD(x)
#define PACK_STRUCT_STRUCT
#define LWIP_DEBUGF(debug, message)
#define LWIP_DBG_LEVEL_WARNING
#define LWIP_ASSERT(message, assertion)
#define LWIP_MEM_ALIGN_BUFFER(size)
#define LWIP_MEM_ALIGN(addr)
GLuint GLuint GLsizei GLenum type
GLenum const GLvoid * addr
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
u32_t ipaddr_addr(const char *cp)
#define ip_addr_cmp(addr1, addr2)
#define ip_addr_isany(addr1)
#define ip_addr_copy(dest, src)
#define ip_addr_set_loopback(ipaddr)
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
#define ip4_addr_get_u32(src_ipaddr)
#define ip4_addr_set_u32(dest_ipaddr, src_u32)
#define ip_addr_debug_print(debug, ipaddr)
#define MEMCPY(DST, SRC, BYTES)
void * memp_malloc(memp_t type)
void memp_free(memp_t type, void *mem)
#define DNS_MAX_NAME_LENGTH
#define SMEMCPY(dst, src, len)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
u8_t pbuf_free(struct pbuf *p)