mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-06 13:13:25 +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);
|
||||
if (res != DNS_QUERY_QUEUED) {
|
||||
/* If not queued, return to app thread directly */
|
||||
if (res == DNS_QUERY_INVALID) {
|
||||
/* some error occurred */
|
||||
*msg->err = ERR_ARG;
|
||||
} else if (res == DNS_COMPLETE) {
|
||||
if (res == DNS_COMPLETE) {
|
||||
/* name was already in octet notation or cached */
|
||||
*msg->err = ERR_OK;
|
||||
}
|
||||
} else {
|
||||
/* some error occurred */
|
||||
*msg->err = ERR_ARG;
|
||||
};
|
||||
/* on error or immediate success, wake up the application
|
||||
* task waiting in netconn_gethostbyname */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
struct hostent*
|
||||
gethostbyname(const char *name)
|
||||
lwip_gethostbyname(const char *name)
|
||||
{
|
||||
err_t err;
|
||||
struct ip_addr addr;
|
||||
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &addr);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* fill hostent */
|
||||
s_hostent_addr = addr;
|
||||
s_phostent_addr = &s_hostent_addr;
|
||||
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_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;
|
||||
}
|
||||
#endif /* LWIP_DNS*/
|
||||
|
@ -400,13 +400,13 @@ dns_send(const char* name, u8_t id)
|
||||
|
||||
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)));
|
||||
|
||||
// send dns packet
|
||||
/* send dns packet */
|
||||
udp_send(dns_pcb, p);
|
||||
|
||||
// free pbuf
|
||||
/* free pbuf */
|
||||
pbuf_free(p);
|
||||
|
||||
return ERR_OK;
|
||||
@ -485,6 +485,8 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
||||
struct dns_hdr *hdr;
|
||||
struct dns_table_entry *pEntry;
|
||||
u8_t nquestions, nanswers;
|
||||
|
||||
LWIP_ASSERT("dns_recv: pbuf chain not yet supported", (p->next==NULL));
|
||||
|
||||
hdr = (struct dns_hdr *)p->payload;
|
||||
|
||||
@ -514,7 +516,7 @@ dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16
|
||||
nquestions = htons(hdr->numquestions);
|
||||
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. */
|
||||
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) {
|
||||
/* Compressed name. */
|
||||
pHostname +=2;
|
||||
/* printf("Compressed anwser\n");*/
|
||||
} else {
|
||||
/* Not compressed name. */
|
||||
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? */
|
||||
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. */
|
||||
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);
|
||||
return;
|
||||
} else {
|
||||
pHostname = pHostname + 10 + htons(ans->len);
|
||||
pHostname = pHostname + 10 /*type(2)+class(2)+ttl(4)+len(2)*/ + htons(ans->len);
|
||||
}
|
||||
--nanswers;
|
||||
}
|
||||
|
@ -194,6 +194,10 @@ lwip_sanity_check(void)
|
||||
if (TCP_WND < TCP_MSS)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
|
||||
#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 */
|
||||
#define lwip_sanity_check()
|
||||
|
@ -43,6 +43,9 @@
|
||||
#define DNS_TMR_INTERVAL 1000
|
||||
#endif
|
||||
|
||||
/** DNS message max. size */
|
||||
#define DNS_MSG_SIZE 512
|
||||
|
||||
/* enumerated list of possible result values returned by dns_gethostname() */
|
||||
typedef enum dns_result {
|
||||
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);
|
||||
|
||||
#if LWIP_DNS
|
||||
struct hostent *gethostbyname(const char *name);
|
||||
struct hostent *lwip_gethostbyname(const char *name);
|
||||
#endif /* LWIP_DNS */
|
||||
|
||||
#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 select(a,b,c,d,e) lwip_select(a,b,c,d,e)
|
||||
#define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
|
||||
#define gethostbyname(a) lwip_gethostbyname(a)
|
||||
|
||||
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
||||
#define read(a,b,c) lwip_read(a,b,c)
|
||||
|
Loading…
x
Reference in New Issue
Block a user