Revert my last changes and remove structure packing from struct dns_query and struct dns_answer since they are only used with SMEMCPY

This commit is contained in:
goldsimon 2010-02-14 14:02:05 +00:00
parent 10abe8aba2
commit 8908055b63

View File

@ -141,40 +141,26 @@ PACK_STRUCT_END
#endif #endif
#define SIZEOF_DNS_HDR 12 #define SIZEOF_DNS_HDR 12
#ifdef PACK_STRUCT_USE_INCLUDES /** DNS query message structure.
# include "arch/bpstruct.h" No packing needed: only used locally on the stack. */
#endif
PACK_STRUCT_BEGIN
/** DNS query message structure */
struct dns_query { struct dns_query {
/* DNS query record starts with either a domain name or a pointer /* DNS query record starts with either a domain name or a pointer
to a name already present somewhere in the packet. */ to a name already present somewhere in the packet. */
PACK_STRUCT_FIELD(u16_t type); u16_t type;
PACK_STRUCT_FIELD(u16_t cls); u16_t cls;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#define SIZEOF_DNS_QUERY 4 #define SIZEOF_DNS_QUERY 4
#ifdef PACK_STRUCT_USE_INCLUDES /** DNS answer message structure.
# include "arch/bpstruct.h" No packing needed: only used locally on the stack. */
#endif
PACK_STRUCT_BEGIN
/** DNS answer message structure */
struct dns_answer { struct dns_answer {
/* DNS answer record starts with either a domain name or a pointer /* DNS answer record starts with either a domain name or a pointer
to a name already present somewhere in the packet. */ to a name already present somewhere in the packet. */
PACK_STRUCT_FIELD(u16_t type); u16_t type;
PACK_STRUCT_FIELD(u16_t cls); u16_t cls;
PACK_STRUCT_FIELD(u32_t ttl); u32_t ttl;
PACK_STRUCT_FIELD(u16_t len); u16_t len;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#define SIZEOF_DNS_ANSWER 10 #define SIZEOF_DNS_ANSWER 10
/** DNS table entry */ /** DNS table entry */
@ -579,7 +565,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 +606,9 @@ dns_send(u8_t numdns, const char* name, u8_t id)
*query++='\0'; *query++='\0';
/* fill dns query */ /* fill dns query */
qry = (struct dns_query *)query; qry.type = htons(DNS_RRTYPE_A);
qry->type = htons(DNS_RRTYPE_A); qry.cls = htons(DNS_RRCLASS_IN);
qry->cls = htons(DNS_RRCLASS_IN); SMEMCPY(query, &qry, SIZEOF_DNS_QUERY);
/* 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 +730,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 +809,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. */
ans = (struct dns_answer *)pHostname; SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
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 +829,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;
} }