This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
DNS code doesn't work on big-endian machine.
- From: "Mervyn Wongso" <intertel_ecos at hotmail dot com>
- To: <ecos-discuss at sources dot redhat dot com>
- Date: Mon, 22 Jul 2002 13:35:09 -0700
- Subject: [ECOS] DNS code doesn't work on big-endian machine.
Hi,
I tried using the DNS package on a coldfire processor. I found out =
that the DNS structure in dns_priv.h is targeted for little-endian =
machine. I also notice that this function in dns_impl.h writes =
little-endian 16-bit number to the DNS packet which I thought supposed =
to be big-endian (network format).
=20
Thanks
Mervyn
/* Build a query message which can be sent to the server. If something
goes wrong return -1, otherwise the length of the query message */
static int=20
build_query(char * msg, const char * hostname, short rr_type)
{
struct dns_header *dns_hdr;
char *ptr;
int len;
/* Fill out the header */
dns_hdr =3D (struct dns_header *) msg;
dns_hdr->id =3D htons(id++);
dns_hdr->rd =3D true;
dns_hdr->opcode =3D htons(DNS_QUERY);
dns_hdr->qdcount =3D htons(1);
=20
/* Now the question we want to ask */
ptr =3D (char *)&dns_hdr[1];
len =3D build_qname(ptr, hostname);
if (len < 0) {
h_errno =3D NO_RECOVERY;
return -1;
}
ptr +=3D len;
=20
/*************** little endian format?? *****************/
/* Set the type and class fields */
*ptr++ =3D htons(rr_type) & 0xff;
*ptr++ =3D htons(rr_type) >> 8;
*ptr++ =3D htons(DNS_CLASS_IN) & 0xff;
*ptr++ =3D htons(DNS_CLASS_IN) >> 8;
len =3D ptr - msg;
return len;
}
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss