This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
DNS big-endian fix
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: eCos Patches <ecos-patches at sources dot redhat dot com>
- Date: Thu, 29 Aug 2002 12:09:41 +0200
- Subject: DNS big-endian fix
Here is what i have committed.
Thanks Roland for the patch.
Andrew
Index: net/ns//dns/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/ns/dns/current/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- net/ns//dns/current/ChangeLog 31 May 2002 01:05:55 -0000 1.4
+++ net/ns//dns/current/ChangeLog 29 Aug 2002 10:06:49 -0000
@@ -1,3 +1,11 @@
+2002-08-29 Roland Caßebohm <roland.cassebohm@visionsystems.de>
+
+ * include/dns_priv.h: Make dns_header structure endian dependent.
+
+ * include/dns_impl.inl: Don't use htons() for bitfields <= 8 bit.
+ Change the way setting the type and class fields in build_query()
+ to work with big-endian.
+
2002-05-30 Jesper Skov <jskov@redhat.com>
* src/dns.c: fixed index->ptdindex oversight.
Index: net/ns//dns/current/include/dns_impl.inl
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/ns/dns/current/include/dns_impl.inl,v
retrieving revision 1.2
diff -u -r1.2 dns_impl.inl
--- net/ns//dns/current/include/dns_impl.inl 23 May 2002 23:08:06 -0000 1.2
+++ net/ns//dns/current/include/dns_impl.inl 29 Aug 2002 10:06:50 -0000
@@ -201,7 +201,7 @@
dns_hdr = (struct dns_header *) msg;
dns_hdr->id = htons(id++);
dns_hdr->rd = true;
- dns_hdr->opcode = htons(DNS_QUERY);
+ dns_hdr->opcode = DNS_QUERY;
dns_hdr->qdcount = htons(1);
/* Now the question we want to ask */
@@ -216,10 +216,10 @@
ptr += len;
/* Set the type and class fields */
- *ptr++ = htons(rr_type) & 0xff;
- *ptr++ = htons(rr_type) >> 8;
- *ptr++ = htons(DNS_CLASS_IN) & 0xff;
- *ptr++ = htons(DNS_CLASS_IN) >> 8;
+ *ptr++ = (rr_type >> 8) & 0xff;
+ *ptr++ = rr_type & 0xff;
+ *ptr++ = (DNS_CLASS_IN >> 8) & 0xff;
+ *ptr++ = DNS_CLASS_IN & 0xff;
len = ptr - msg;
@@ -279,7 +279,7 @@
}
if ((dns_hdr->qr != 1) ||
- (dns_hdr->opcode != htons(DNS_QUERY)) ||
+ (dns_hdr->opcode != DNS_QUERY) ||
(dns_hdr->rcode != DNS_REPLY_NOERR)) {
h_errno = NO_RECOVERY;
return NULL;
Index: net/ns//dns/current/include/dns_priv.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/ns/dns/current/include/dns_priv.h,v
retrieving revision 1.2
diff -u -r1.2 dns_priv.h
--- net/ns//dns/current/include/dns_priv.h 23 May 2002 23:08:06 -0000 1.2
+++ net/ns//dns/current/include/dns_priv.h 29 Aug 2002 10:06:50 -0000
@@ -51,6 +51,7 @@
//=============================================================================
struct dns_header {
+#if (CYG_BYTEORDER == CYG_LSBFIRST)
unsigned id :16; /* query identification number */
/* fields in third byte */
unsigned rd :1; /* recursion desired */
@@ -69,6 +70,26 @@
unsigned ancount :16; /* number of answer entries */
unsigned nscount :16; /* number of authority entries */
unsigned arcount :16; /* number of resource entries */
+#else
+ unsigned id :16; /* query identification number */
+ /* fields in third byte */
+ unsigned qr :1; /* response flag */
+ unsigned opcode :4; /* purpose of message */
+ unsigned aa :1; /* authoritive answer */
+ unsigned tc :1; /* truncated message */
+ unsigned rd :1; /* recursion desired */
+ /* fields in fourth byte */
+ unsigned ra :1; /* recursion available */
+ unsigned unused :1; /* unused bits */
+ unsigned ad: 1; /* authentic data from named */
+ unsigned cd: 1; /* checking disabled by resolver */
+ unsigned rcode :4; /* response code */
+ /* remaining bytes */
+ unsigned qdcount :16; /* number of question entries */
+ unsigned ancount :16; /* number of answer entries */
+ unsigned nscount :16; /* number of authority entries */
+ unsigned arcount :16; /* number of resource entries */
+#endif
};
struct resource_record {