mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-25 15:42:56 +00:00
Minor changes on DNS client.
This commit is contained in:
parent
6c8b3e3b58
commit
edc46281a4
@ -1029,13 +1029,13 @@ do_gethostbyname(void *arg)
|
|||||||
res = dns_gethostbyname(msg->name, msg->addr, do_dns_found, msg);
|
res = dns_gethostbyname(msg->name, msg->addr, do_dns_found, msg);
|
||||||
if (res != DNS_QUERY_QUEUED) {
|
if (res != DNS_QUERY_QUEUED) {
|
||||||
/* If not queued, return to app thread directly */
|
/* If not queued, return to app thread directly */
|
||||||
if (res == DNS_QUERY_INVALID) {
|
if (res == DNS_COMPLETE) {
|
||||||
/* some error occurred */
|
|
||||||
*msg->err = ERR_ARG;
|
|
||||||
} else if (res == DNS_COMPLETE) {
|
|
||||||
/* name was already in octet notation or cached */
|
/* name was already in octet notation or cached */
|
||||||
*msg->err = ERR_OK;
|
*msg->err = ERR_OK;
|
||||||
}
|
} else {
|
||||||
|
/* some error occurred */
|
||||||
|
*msg->err = ERR_ARG;
|
||||||
|
};
|
||||||
/* on error or immediate success, wake up the application
|
/* on error or immediate success, wake up the application
|
||||||
* task waiting in netconn_gethostbyname */
|
* task waiting in netconn_gethostbyname */
|
||||||
sys_sem_signal(msg->sem);
|
sys_sem_signal(msg->sem);
|
||||||
|
@ -1813,18 +1813,20 @@ lwip_fill_hostent(struct hostent *he, char *name, struct ip_addr **addr, char **
|
|||||||
he->h_addr_list = (char**)addr;
|
he->h_addr_list = (char**)addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct hostent*
|
struct hostent*
|
||||||
gethostbyname(const char *name)
|
lwip_gethostbyname(const char *name)
|
||||||
{
|
{
|
||||||
err_t err;
|
err_t err;
|
||||||
struct ip_addr addr;
|
struct ip_addr addr;
|
||||||
|
|
||||||
|
/* query host IP address */
|
||||||
err = netconn_gethostbyname(name, &addr);
|
err = netconn_gethostbyname(name, &addr);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fill hostent */
|
||||||
s_hostent_addr = addr;
|
s_hostent_addr = addr;
|
||||||
s_phostent_addr = &s_hostent_addr;
|
s_phostent_addr = &s_hostent_addr;
|
||||||
s_hostent.h_name = (char*)name;
|
s_hostent.h_name = (char*)name;
|
||||||
@ -1833,6 +1835,29 @@ gethostbyname(const char *name)
|
|||||||
s_hostent.h_length = sizeof(struct ip_addr);
|
s_hostent.h_length = sizeof(struct ip_addr);
|
||||||
s_hostent.h_addr_list = (char**)&s_phostent_addr;
|
s_hostent.h_addr_list = (char**)&s_phostent_addr;
|
||||||
|
|
||||||
|
#if DNS_DEBUG
|
||||||
|
/* dump hostent */
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_name == %s\n", s_hostent.h_name));
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases == 0x%08lX\n",(u32_t)(s_hostent.h_aliases)));
|
||||||
|
if (s_hostent.h_aliases != NULL) {
|
||||||
|
u8_t idx;
|
||||||
|
for ( idx=0; s_hostent.h_aliases[idx]; idx++) {
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases[%i]-> == 0x%08lX\n", idx, s_hostent.h_aliases[idx]));
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases[%i]-> == %s\n", idx, s_hostent.h_aliases[idx]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addrtype == %lu\n", (u32_t)(s_hostent.h_addrtype)));
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_length == %lu\n", (u32_t)(s_hostent.h_length)));
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list == 0x%08lX\n", s_hostent.h_addr_list));
|
||||||
|
if (s_hostent.h_addr_list != NULL) {
|
||||||
|
u8_t idx;
|
||||||
|
for ( idx=0; s_hostent.h_addr_list[idx]; idx++) {
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == 0x%08lX\n", idx, s_hostent.h_addr_list[idx]));
|
||||||
|
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, inet_ntoa(*((struct in_addr*)(s_hostent.h_addr_list[idx])))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* DNS_DEBUG */
|
||||||
|
|
||||||
return &s_hostent;
|
return &s_hostent;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_DNS*/
|
#endif /* LWIP_DNS*/
|
||||||
|
@ -400,13 +400,13 @@ dns_send(const char* name, u8_t id)
|
|||||||
|
|
||||||
memcpy( query, dns_endquery, sizeof(dns_endquery));
|
memcpy( query, dns_endquery, sizeof(dns_endquery));
|
||||||
|
|
||||||
// resize pbuf to the exact dns query
|
/* resize pbuf to the exact dns query */
|
||||||
pbuf_realloc(p, (query+sizeof(dns_endquery))-((char*)(p->payload)));
|
pbuf_realloc(p, (query+sizeof(dns_endquery))-((char*)(p->payload)));
|
||||||
|
|
||||||
// send dns packet
|
/* send dns packet */
|
||||||
udp_send(dns_pcb, p);
|
udp_send(dns_pcb, p);
|
||||||
|
|
||||||
// free pbuf
|
/* free pbuf */
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -486,6 +486,8 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
|||||||
struct dns_table_entry *pEntry;
|
struct dns_table_entry *pEntry;
|
||||||
u8_t nquestions, nanswers;
|
u8_t nquestions, nanswers;
|
||||||
|
|
||||||
|
LWIP_ASSERT("dns_recv: pbuf chain not yet supported", (p->next==NULL));
|
||||||
|
|
||||||
hdr = (struct dns_hdr *)p->payload;
|
hdr = (struct dns_hdr *)p->payload;
|
||||||
|
|
||||||
/* The ID in the DNS header should be our entry into the name table. */
|
/* The ID in the DNS header should be our entry into the name table. */
|
||||||
@ -514,7 +516,7 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
|||||||
nquestions = htons(hdr->numquestions);
|
nquestions = htons(hdr->numquestions);
|
||||||
nanswers = htons(hdr->numanswers);
|
nanswers = htons(hdr->numanswers);
|
||||||
|
|
||||||
/* Skip the name in the question. XXX: This should really be checked
|
/* Skip the name in the "question" part. This should really be checked
|
||||||
agains the name in the question, to be sure that they match. */
|
agains the name in the question, to be sure that they match. */
|
||||||
pHostname = (char *) dns_parse_name((unsigned char *)p->payload + sizeof(struct dns_hdr)) + 4/*type(2)+class(2)*/;
|
pHostname = (char *) dns_parse_name((unsigned char *)p->payload + sizeof(struct dns_hdr)) + 4/*type(2)+class(2)*/;
|
||||||
|
|
||||||
@ -524,7 +526,6 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
|||||||
if(*pHostname & 0xc0) {
|
if(*pHostname & 0xc0) {
|
||||||
/* Compressed name. */
|
/* Compressed name. */
|
||||||
pHostname +=2;
|
pHostname +=2;
|
||||||
/* printf("Compressed anwser\n");*/
|
|
||||||
} else {
|
} else {
|
||||||
/* Not compressed name. */
|
/* Not compressed name. */
|
||||||
pHostname = (char *) dns_parse_name((unsigned char *)pHostname);
|
pHostname = (char *) dns_parse_name((unsigned char *)pHostname);
|
||||||
@ -532,9 +533,6 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
|||||||
|
|
||||||
/* TODO: isn't it any problem to access to dns_answer fields since pHostname's length can be unaligned? */
|
/* TODO: isn't it any problem to access to dns_answer fields since pHostname's length can be unaligned? */
|
||||||
ans = (struct dns_answer *)pHostname;
|
ans = (struct dns_answer *)pHostname;
|
||||||
/* printf("Answer: type %x, class %x, ttl %x, length %x\n",
|
|
||||||
htons(ans->type), htons(ans->class), (htons(ans->ttl[0])
|
|
||||||
<< 16) | htons(ans->ttl[1]), htons(ans->len));*/
|
|
||||||
|
|
||||||
/* Check for IP address type and Internet class. Others are discarded. */
|
/* Check for IP address type and Internet class. Others are discarded. */
|
||||||
if((ntohs(ans->type) == DNS_RRTYPE_A) && (ntohs(ans->class) == DNS_RRCLASS_IN) && (ntohs(ans->len) == 4/*IPv4 address*/) ) {
|
if((ntohs(ans->type) == DNS_RRTYPE_A) && (ntohs(ans->class) == DNS_RRCLASS_IN) && (ntohs(ans->len) == 4/*IPv4 address*/) ) {
|
||||||
@ -548,7 +546,7 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
|||||||
(*pEntry->found)(pEntry->name, &pEntry->ipaddr, pEntry->arg);
|
(*pEntry->found)(pEntry->name, &pEntry->ipaddr, pEntry->arg);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
pHostname = pHostname + 10 + htons(ans->len);
|
pHostname = pHostname + 10 /*type(2)+class(2)+ttl(4)+len(2)*/ + htons(ans->len);
|
||||||
}
|
}
|
||||||
--nanswers;
|
--nanswers;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +194,10 @@ lwip_sanity_check(void)
|
|||||||
if (TCP_WND < TCP_MSS)
|
if (TCP_WND < TCP_MSS)
|
||||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
|
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
|
||||||
#endif /* LWIP_TCP */
|
#endif /* LWIP_TCP */
|
||||||
|
#if LWIP_DNS
|
||||||
|
if (PBUF_POOL_BUFSIZE<(PBUF_LINK_HLEN+PBUF_IP_HLEN+PBUF_TRANSPORT_HLEN+DNS_MSG_SIZE))
|
||||||
|
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: UDP messages for DNS could need until 512 bytes\n"));
|
||||||
|
#endif /* LWIP_DNS */
|
||||||
}
|
}
|
||||||
#else /* LWIP_DEBUG */
|
#else /* LWIP_DEBUG */
|
||||||
#define lwip_sanity_check()
|
#define lwip_sanity_check()
|
||||||
|
@ -43,6 +43,9 @@
|
|||||||
#define DNS_TMR_INTERVAL 1000
|
#define DNS_TMR_INTERVAL 1000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** DNS message max. size */
|
||||||
|
#define DNS_MSG_SIZE 512
|
||||||
|
|
||||||
/* enumerated list of possible result values returned by dns_gethostname() */
|
/* enumerated list of possible result values returned by dns_gethostname() */
|
||||||
typedef enum dns_result {
|
typedef enum dns_result {
|
||||||
DNS_QUERY_INVALID,
|
DNS_QUERY_INVALID,
|
||||||
|
@ -314,7 +314,7 @@ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptse
|
|||||||
int lwip_ioctl(int s, long cmd, void *argp);
|
int lwip_ioctl(int s, long cmd, void *argp);
|
||||||
|
|
||||||
#if LWIP_DNS
|
#if LWIP_DNS
|
||||||
struct hostent *gethostbyname(const char *name);
|
struct hostent *lwip_gethostbyname(const char *name);
|
||||||
#endif /* LWIP_DNS */
|
#endif /* LWIP_DNS */
|
||||||
|
|
||||||
#if LWIP_COMPAT_SOCKETS
|
#if LWIP_COMPAT_SOCKETS
|
||||||
@ -335,6 +335,7 @@ struct hostent *gethostbyname(const char *name);
|
|||||||
#define socket(a,b,c) lwip_socket(a,b,c)
|
#define socket(a,b,c) lwip_socket(a,b,c)
|
||||||
#define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
|
#define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
|
||||||
#define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
|
#define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
|
||||||
|
#define gethostbyname(a) lwip_gethostbyname(a)
|
||||||
|
|
||||||
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
||||||
#define read(a,b,c) lwip_read(a,b,c)
|
#define read(a,b,c) lwip_read(a,b,c)
|
||||||
|
Loading…
Reference in New Issue
Block a user