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;
struct dns_hdr *hdr;
struct dns_query qry;
struct dns_query *qry;
struct pbuf *p;
char *query, *nptr;
const char *pHostname;
@ -620,9 +620,9 @@ dns_send(u8_t numdns, const char* name, u8_t id)
*query++='\0';
/* fill dns query */
qry.type = htons(DNS_RRTYPE_A);
qry.cls = htons(DNS_RRCLASS_IN);
SMEMCPY(query, &qry, SIZEOF_DNS_QUERY);
qry = (struct dns_query *)query;
qry->type = htons(DNS_RRTYPE_A);
qry->cls = htons(DNS_RRCLASS_IN);
/* resize pbuf to the exact dns query */
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;
char *pHostname;
struct dns_hdr *hdr;
struct dns_answer ans;
struct dns_answer *ans;
struct dns_table_entry *pEntry;
u16_t nquestions, nanswers;
#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);
/* Check for IP address type and Internet class. Others are discarded. */
SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
if((ans.type == htons(DNS_RRTYPE_A)) && (ans.cls == htons(DNS_RRCLASS_IN)) &&
(ans.len == htons(sizeof(ip_addr_t))) ) {
ans = (struct dns_answer *)pHostname;
if((ans->type == htons(DNS_RRTYPE_A)) && (ans->cls == htons(DNS_RRCLASS_IN)) &&
(ans->len == htons(sizeof(ip_addr_t))) ) {
/* 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) {
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 */
goto memerr2;
} else {
pHostname = pHostname + SIZEOF_DNS_ANSWER + htons(ans.len);
pHostname = pHostname + SIZEOF_DNS_ANSWER + htons(ans->len);
}
--nanswers;
}