Use pointers instead of using SMEMCPY

This commit is contained in:
goldsimon 2010-02-14 12:51:53 +00:00
parent 7b24a6360c
commit 10abe8aba2

View File

@ -579,7 +579,7 @@ dns_send(u8_t numdns, const char* name, u8_t id)
{ {
err_t err; err_t err;
struct dns_hdr *hdr; struct dns_hdr *hdr;
struct dns_query qry; struct dns_query *qry;
struct pbuf *p; struct pbuf *p;
char *query, *nptr; char *query, *nptr;
const char *pHostname; const char *pHostname;
@ -620,9 +620,9 @@ dns_send(u8_t numdns, const char* name, u8_t id)
*query++='\0'; *query++='\0';
/* fill dns query */ /* fill dns query */
qry.type = htons(DNS_RRTYPE_A); qry = (struct dns_query *)query;
qry.cls = htons(DNS_RRCLASS_IN); qry->type = htons(DNS_RRTYPE_A);
SMEMCPY(query, &qry, SIZEOF_DNS_QUERY); qry->cls = htons(DNS_RRCLASS_IN);
/* resize pbuf to the exact dns query */ /* resize pbuf to the exact dns query */
pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload)))); pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload))));
@ -744,7 +744,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
u16_t i; u16_t i;
char *pHostname; char *pHostname;
struct dns_hdr *hdr; struct dns_hdr *hdr;
struct dns_answer ans; struct dns_answer *ans;
struct dns_table_entry *pEntry; struct dns_table_entry *pEntry;
u16_t nquestions, nanswers; u16_t nquestions, nanswers;
#if (DNS_USES_STATIC_BUF == 0) #if (DNS_USES_STATIC_BUF == 0)
@ -823,11 +823,11 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
pHostname = (char *) dns_parse_name((unsigned char *)pHostname); pHostname = (char *) dns_parse_name((unsigned char *)pHostname);
/* Check for IP address type and Internet class. Others are discarded. */ /* Check for IP address type and Internet class. Others are discarded. */
SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER); ans = (struct dns_answer *)pHostname;
if((ans.type == htons(DNS_RRTYPE_A)) && (ans.cls == htons(DNS_RRCLASS_IN)) && if((ans->type == htons(DNS_RRTYPE_A)) && (ans->cls == htons(DNS_RRCLASS_IN)) &&
(ans.len == htons(sizeof(ip_addr_t))) ) { (ans->len == htons(sizeof(ip_addr_t))) ) {
/* read the answer resource record's TTL, and maximize it if needed */ /* read the answer resource record's TTL, and maximize it if needed */
pEntry->ttl = ntohl(ans.ttl); pEntry->ttl = ntohl(ans->ttl);
if (pEntry->ttl > DNS_MAX_TTL) { if (pEntry->ttl > DNS_MAX_TTL) {
pEntry->ttl = DNS_MAX_TTL; pEntry->ttl = DNS_MAX_TTL;
} }
@ -843,7 +843,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
/* deallocate memory and return */ /* deallocate memory and return */
goto memerr2; goto memerr2;
} else { } else {
pHostname = pHostname + SIZEOF_DNS_ANSWER + htons(ans.len); pHostname = pHostname + SIZEOF_DNS_ANSWER + htons(ans->len);
} }
--nanswers; --nanswers;
} }