diff -Naur tftpnaive-1.3.3/tftpnaive/include/tftpnaive.h tftpnaive-1.3.3-change/tftpnaive/include/tftpnaive.h
--- tftpnaive-1.3.3/tftpnaive/include/tftpnaive.h	2010-12-27 14:17:55.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/include/tftpnaive.h	2011-01-13 22:12:09.000000000 +0800
@@ -74,4 +74,13 @@
 #define ERR_CHIPID	2
 #define ERR_TIMEOUT	3

+
+/*-------------------*/
+/* Endian Definition */
+/*-------------------*/
+
+//#define TFTPNAIVE_USE_BIG_ENDIAN
+#define TFTPNAIVE_USE_LITTLE_ENDIAN
+
+
 #endif
diff -Naur tftpnaive-1.3.3/tftpnaive/src/arp.c tftpnaive-1.3.3-change/tftpnaive/src/arp.c
--- tftpnaive-1.3.3/tftpnaive/src/arp.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/arp.c	2011-01-13 22:17:22.000000000 +0800
@@ -21,6 +21,7 @@

 #include "tftpnaive.h"
 #include "net.h"
+#include "endian.h"
 #include "baselib.h"

 #define MAXARPENTRIES 16
@@ -36,7 +37,7 @@
 	int i, f = 0;

 	for (i = 0; i < MAXARPENTRIES; ++i) {
-		if (arpCache[i].ip == p->sender_ipaddr) {
+		if (arpCache[i].ip == ntohl(p->sender_ipaddr)) {
 			if (f) {
 				arpCache[i].ok = 0;
 			}
@@ -53,29 +54,29 @@
 static void addAddr (ARPpkt * p)
 {
 	memcpy (arpCache[arpCacheCnt].ia, p->sender_hwaddr, 6);
-	arpCache[arpCacheCnt].ip = p->sender_ipaddr;
+	arpCache[arpCacheCnt].ip = ntohl(p->sender_ipaddr);
 	arpCache[arpCacheCnt].ok = 1;
 	arpCacheCnt = (arpCacheCnt + 1) % MAXARPENTRIES;
 }

 int sendARPRequest (unsigned int sender_ip, unsigned int target_ip)
-{
+{
 	ARPpkt p;
 	int i;

 	for (i = 0; i < 6; ++i)
 		p.ehdr.dst_hwadr[i] = 0xff;
 	memcpy (p.ehdr.src_hwadr, netif.IEEEIA, 6);
-	p.ehdr.frametype = FRAME_ARP;
-	p.hardtype = ARP_ETH;
-	p.prottype = FRAME_IP;
+	p.ehdr.frametype = htons(FRAME_ARP);
+	p.hardtype = htons(ARP_ETH);
+	p.prottype = htons(FRAME_IP);
 	p.hardsize = 6;
 	p.protsize = 4;
-	p.op = ARP_REQUEST;
+	p.op = htons(ARP_REQUEST);
 	memcpy (p.sender_hwaddr, netif.IEEEIA, 6);
-	p.sender_ipaddr = sender_ip;
+	p.sender_ipaddr = htonl(sender_ip);
 	memset (p.target_hwaddr, 0, 6);
-	p.target_ipaddr = target_ip;
+	p.target_ipaddr = htonl(target_ip);
 	return netif.send (&p, sizeof (ARPpkt));
 }

@@ -123,32 +124,32 @@
 	register ARPpkt *p = (ARPpkt *) pkt;

 	if (len >= sizeof (ARPpkt)) {
-		if (p->hardtype == ARP_ETH && p->prottype == FRAME_IP && netif.ip) {
+		if (ntohs(p->hardtype) == ARP_ETH && ntohs(p->prottype) == FRAME_IP && netif.ip) {
 			if (p->hardsize == 6 && p->protsize == 4) {
-				if (p->op == ARP_REQUEST) {
+				if (ntohs(p->op) == ARP_REQUEST) {
 					if (!updateAddr (p)) {
 						addAddr (p);
 					}
-					if (netif.ip == p->target_ipaddr) {
-						p->op = ARP_REPLY;
+					if (netif.ip == ntohl(p->target_ipaddr)) {
+						p->op = htons(ARP_REPLY);
 						memcpy (p->target_hwaddr, p->sender_hwaddr, 10);
-						p->sender_ipaddr = netif.ip;
+						p->sender_ipaddr = htonl(netif.ip);
 						memcpy (p->sender_hwaddr, netif.IEEEIA, 6);
 						memcpy (pkt, pkt + 6, 6);
 						memcpy (pkt + 6, netif.IEEEIA, 6);
 						netif.send (pkt, sizeof (ARPpkt));
 					}
 				}
-				else if (p->op == ARP_REPLY) {
-					if (p->sender_ipaddr == netif.ip) {
+				else if (ntohs(p->op) == ARP_REPLY) {
+					if (ntohl(p->sender_ipaddr) == netif.ip) {
 						netif.ip = 0;
 						printf ("IP conflict : ");
 						printf
 							("ARP reply: %d.%d.%d.%d is-at %02X:%02X:%02X:%02X:%02X:%02X\n",
-							 (p->sender_ipaddr >> 24) & 0xff,
-							 (p->sender_ipaddr >> 16) & 0xff,
-							 (p->sender_ipaddr >> 8) & 0xff,
-							 (p->sender_ipaddr) & 0xff, p->sender_hwaddr[0],
+							 (ntohl(p->sender_ipaddr) >> 24) & 0xff,
+							 (ntohl(p->sender_ipaddr) >> 16) & 0xff,
+							 (ntohl(p->sender_ipaddr) >> 8) & 0xff,
+							 (ntohl(p->sender_ipaddr)) & 0xff, p->sender_hwaddr[0],
 							 p->sender_hwaddr[1], p->sender_hwaddr[2],
 							 p->sender_hwaddr[3], p->sender_hwaddr[4],
 							 p->sender_hwaddr[5]);
diff -Naur tftpnaive-1.3.3/tftpnaive/src/bootp.c tftpnaive-1.3.3-change/tftpnaive/src/bootp.c
--- tftpnaive-1.3.3/tftpnaive/src/bootp.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/bootp.c	2011-01-13 22:16:54.000000000 +0800
@@ -21,6 +21,7 @@

 #include "tftpnaive.h"
 #include "net.h"
+#include "endian.h"
 #include "baselib.h"

 static BootData bdata;
@@ -28,28 +29,28 @@

 void processBOOTP (BOOTPpkt * bp)
 {
-	if (bp->op_type == BOOTP_ETH_REPLY && bp->id == BOOT_RQ_ID
+	if (ntohs(bp->op_type) == BOOTP_ETH_REPLY && ntohl(bp->id) == BOOT_RQ_ID
 		&& tftp_req == 0 && !memcmp (netif.IEEEIA, bp->hw_addr, 6)) {
 		int l;

 		printf ("BOOTP: ");
 		printf ("IP %d.%d.%d.%d, ",
-				(bp->your_ip >> 24) & 0xff,
-				(bp->your_ip >> 16) & 0xff,
-				(bp->your_ip >> 8) & 0xff,
-				bp->your_ip & 0xff);
+				(ntohl(bp->your_ip) >> 24) & 0xff,
+				(ntohl(bp->your_ip) >> 16) & 0xff,
+				(ntohl(bp->your_ip) >> 8) & 0xff,
+				ntohl(bp->your_ip) & 0xff);
 		printf ("server %d.%d.%d.%d, ",
-				(bp->srv_ip >> 24) & 0xff,
-				(bp->srv_ip >> 16) & 0xff,
-				(bp->srv_ip >> 8) & 0xff,
-				bp->srv_ip & 0xff);
+				(ntohl(bp->srv_ip) >> 24) & 0xff,
+				(ntohl(bp->srv_ip) >> 16) & 0xff,
+				(ntohl(bp->srv_ip) >> 8) & 0xff,
+				ntohl(bp->srv_ip) & 0xff);
 		printf ("boot file '%s'\n", bp->boot_filename);
-		netif.ip = bp->your_ip;
+		netif.ip = ntohl(bp->your_ip);
 		l = strlen (bp->boot_filename);
 		if (l > 0 && l < 128) {
 			memset (&bdata, 0, sizeof bdata);
 			tftp_req = &bdata;
-			tftp_req->server = bp->srv_ip;
+			tftp_req->server = ntohl(bp->srv_ip);
 			strcpy (tftp_req->file, bp->boot_filename);
 		}
 	}
@@ -61,10 +62,10 @@

 	tftp_req = 0;
 	memset (&bootp_pkt, 0, sizeof bootp_pkt);
-	bootp_pkt.op_type = BOOTP_ETH_REQUEST;
-	bootp_pkt.adr_hop = 0x600;
-	bootp_pkt.id = BOOT_RQ_ID;
-	bootp_pkt.sec = BOOT_RQ_SEC;
+	bootp_pkt.op_type = htons(BOOTP_ETH_REQUEST);
+	bootp_pkt.adr_hop = htons(0x600);
+	bootp_pkt.id = htonl(BOOT_RQ_ID);
+	bootp_pkt.sec = htons(BOOT_RQ_SEC);
 	memcpy (&bootp_pkt.hw_addr, netif.IEEEIA, 6);

 	return sendUDP ((UDPpkt *) & bootp_pkt,
diff -Naur tftpnaive-1.3.3/tftpnaive/src/endian.h tftpnaive-1.3.3-change/tftpnaive/src/endian.h
--- tftpnaive-1.3.3/tftpnaive/src/endian.h	1970-01-01 08:00:00.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/endian.h	2010-12-28 15:29:06.000000000 +0800
@@ -0,0 +1,49 @@
+
+#include "tftpnaive.h"
+
+#define __swap16gen(x)							\
+    (cyg_uint16)(((cyg_uint16)(x) & 0xff) << 8 | ((cyg_uint16)(x) & 0xff00) >> 8)
+
+#define __swap32gen(x)							\
+    (cyg_uint32)(((cyg_uint32)(x) & 0xff) << 24 |				\
+    ((cyg_uint32)(x) & 0xff00) << 8 | ((cyg_uint32)(x) & 0xff0000) >> 8 |	\
+    ((cyg_uint32)(x) & 0xff000000) >> 24)
+
+#define swap16 __swap16gen
+#define swap32 __swap32gen
+
+#ifdef TFTPNAIVE_USE_LITTLE_ENDIAN
+
+#define htobe16 swap16
+#define htobe32 swap32
+#define betoh16 swap16
+#define betoh32 swap32
+
+#define htole16(x) (x)
+#define htole32(x) (x)
+#define letoh16(x) (x)
+#define letoh32(x) (x)
+
+#else	// #ifdef TFTPNAIVE_USE_LITTLE_ENDIAN
+
+#define htole16 swap16
+#define htole32 swap32
+#define letoh16 swap16
+#define letoh32 swap32
+
+#define htobe16(x) (x)
+#define htobe32(x) (x)
+#define betoh16(x) (x)
+#define betoh32(x) (x)
+
+#endif	// #ifdef TFTPNAIVE_USE_LITTLE_ENDIAN
+
+#define htons htobe16
+#define htonl htobe32
+#define ntohs betoh16
+#define ntohl betoh32
+
+#define	NTOHL(x) (x) = ntohl((cyg_uint32)(x))
+#define	NTOHS(x) (x) = ntohs((cyg_uint16)(x))
+#define	HTONL(x) (x) = htonl((cyg_uint32)(x))
+#define	HTONS(x) (x) = htons((cyg_uint16)(x))
diff -Naur tftpnaive-1.3.3/tftpnaive/src/icmp.c tftpnaive-1.3.3-change/tftpnaive/src/icmp.c
--- tftpnaive-1.3.3/tftpnaive/src/icmp.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/icmp.c	2011-01-13 22:17:00.000000000 +0800
@@ -21,6 +21,7 @@

 #include "tftpnaive.h"
 #include "net.h"
+#include "endian.h"
 #include "baselib.h"
 #include "timer.h"

@@ -30,19 +31,19 @@

 	if (len >= sizeof (ICMPpkt)) {
 		if (cks (&p->op, len - sizeof (IPpkt)) == 0) {
-			switch (p->op & 0xff00) {
+			switch (ntohs(p->op) & 0xff00) {
 			case ICMP_ECHO_REQUEST:
 				if (netif.ip) {	/* reply only if we have our IP address */
 					memcpy (p->iphdr.ehdr.dst_hwadr, p->iphdr.ehdr.src_hwadr,
 							6);
 					memcpy (p->iphdr.ehdr.src_hwadr, netif.IEEEIA, 6);
-					p->iphdr.dst_ip = p->iphdr.src_ip;
+					p->iphdr.dst_ip = ntohl(p->iphdr.src_ip);
 					p->iphdr.src_ip = netif.ip;
 					p->iphdr.cks = 0;
 					p->iphdr.cks =
 						cks (&p->iphdr.vlt,
 							 sizeof (IPpkt) - sizeof (EthHeader));
-					p->op = ICMP_ECHO_REPLY;
+					p->op = htons(ICMP_ECHO_REPLY);
 					p->cks = 0;
 					p->cks = cks (&p->op, len - sizeof (IPpkt));
 					netif.send (p, len);
@@ -51,8 +52,8 @@
 #if TFTPNAIVE_TIMEREQUEST
 			case ICMP_TIMESTAMP_REPLY: {
 					extern int timestamp;
-					if ((((ICMPTSpkt *) p)->tra) < 86400000)
-						timestamp = ((ICMPTSpkt *) p)->tra;
+					if (ntohl(((ICMPTSpkt *) p)->tra) < 86400000)
+						timestamp = ntohl(((ICMPTSpkt *) p)->tra);
 				}
 				break;
 #endif
@@ -84,8 +85,8 @@
 	ICMPTSpkt p;

 	memset (&p, 0, sizeof p);
-	p.icmphdr.op = ICMP_TIMESTAMP_REQUEST;
-	p.icmphdr.seq = 1;
+	p.icmphdr.op = htons(ICMP_TIMESTAMP_REQUEST);
+	p.icmphdr.seq = htons(1);
 	p.icmphdr.cks = cks (&p.icmphdr.op, sizeof (ICMPTSpkt) - sizeof (IPpkt));
 	return sendIP ((IPpkt *) & p, sizeof (ICMPTSpkt) - sizeof (IPpkt),
 				   PROTO_ICMP, dst_ip);
diff -Naur tftpnaive-1.3.3/tftpnaive/src/ip.c tftpnaive-1.3.3-change/tftpnaive/src/ip.c
--- tftpnaive-1.3.3/tftpnaive/src/ip.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/ip.c	2011-01-13 20:07:32.000000000 +0800
@@ -28,9 +28,9 @@
 	register IPpkt *p = (IPpkt *) pkt;

 	if (len >= sizeof (IPpkt)) {
-		if ((p->vlt & 0xff00) == IPV4) {
-			if ((p->frag & ~DONT_FRAGMENT_MASK) == 0) {
-				if (netif.ip == 0 || p->dst_ip == netif.ip) {
+		if ((ntohs(p->vlt) & 0xff00) == IPV4) {
+			if ((ntohs(p->frag) & ~DONT_FRAGMENT_MASK) == 0) {
+				if (netif.ip == 0 || ntohl(p->dst_ip) == netif.ip) {
 					if (cks (&p->vlt, sizeof (IPpkt) - sizeof (EthHeader)) == 0) {
 						if (p->prot == PROTO_UDP) {
 							processUDP (pkt, len);
@@ -51,28 +51,28 @@
 	register unsigned char *dst;
 	register int trycount;

-	p->vlt = IPV4;
-	p->length = len + sizeof (IPpkt) - sizeof (EthHeader);
+	p->vlt = htons(IPV4);
+	p->length = htons(len + sizeof (IPpkt) - sizeof (EthHeader));
 	p->id = 0;
 	p->frag = 0;
 	p->ttl = 3;
 	p->prot = prot;
-	p->src_ip = netif.ip;
-	p->dst_ip = dst_ip;
+	p->src_ip = htonl(netif.ip);
+	p->dst_ip = htonl(dst_ip);
 	p->cks = 0;
 	p->cks = cks (&p->vlt, sizeof (IPpkt) - sizeof (EthHeader));

-	if (dst_ip == -1) {
+	if (ntohl(dst_ip) == -1) {
 		memset (p->ehdr.dst_hwadr, 0xff, 6);
 	}
 	else {
 		trycount = 4;
 		goto search;
 		do  {
-			sendARPRequest (netif.ip, p->dst_ip);
+			sendARPRequest (netif.ip, dst_ip);
 			busyWait (100, processPacket, 0);
 		search:
-			dst = lookupARP (p->dst_ip);
+			dst = lookupARP (ntohl(p->dst_ip));
 			if (dst) {
 				memcpy (p->ehdr.dst_hwadr, dst, 6);
 				goto end;
@@ -82,7 +82,7 @@
 	}
 end:
 	memcpy (p->ehdr.src_hwadr, netif.IEEEIA, 6);
-	p->ehdr.frametype = FRAME_IP;
+	p->ehdr.frametype = htons(FRAME_IP);

 	return netif.send (p, len + sizeof (IPpkt));
 }
diff -Naur tftpnaive-1.3.3/tftpnaive/src/net.c tftpnaive-1.3.3-change/tftpnaive/src/net.c
--- tftpnaive-1.3.3/tftpnaive/src/net.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/net.c	2011-01-13 22:16:48.000000000 +0800
@@ -21,6 +21,7 @@

 #include "tftpnaive.h"
 #include "net.h"
+#include "endian.h"
 #include "baselib.h"
 #include "timer.h"

@@ -38,10 +39,10 @@
 	if (idxo != idxiPBuf) {
 		idxo = (++idxo) % MAXPACKETBUF;
 		hdr = (EthHeader *) packetBuf[idxo];
-		if (hdr->frametype == FRAME_IP) {
+		if (ntohs(hdr->frametype) == FRAME_IP) {
 			processIP (packetBuf[idxo], packetBufLen[idxo]);
 		}
-		else if (hdr->frametype == FRAME_ARP) {
+		else if (ntohs(hdr->frametype) == FRAME_ARP) {
 			processARP (packetBuf[idxo], packetBufLen[idxo]);
 		}
 		idxoPBuf = idxo;
diff -Naur tftpnaive-1.3.3/tftpnaive/src/net.h tftpnaive-1.3.3-change/tftpnaive/src/net.h
--- tftpnaive-1.3.3/tftpnaive/src/net.h	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/net.h	2011-01-13 20:17:51.000000000 +0800
@@ -55,7 +55,7 @@
 	unsigned char dst_hwadr[6];
 	unsigned char src_hwadr[6];
 	unsigned short frametype;
-} EthHeader;
+} __attribute__ ((aligned(1), packed)) EthHeader;

 typedef struct {
 	EthHeader ehdr;
@@ -68,7 +68,7 @@
 	unsigned int sender_ipaddr;
 	unsigned char target_hwaddr[6];
 	unsigned int target_ipaddr;
-} ARPpkt;
+} __attribute__ ((aligned(1), packed)) ARPpkt;

 typedef struct {
 	EthHeader ehdr;
@@ -81,7 +81,7 @@
 	unsigned short cks;
 	unsigned int src_ip;
 	unsigned int dst_ip;
-} IPpkt;
+} __attribute__ ((aligned(1), packed)) IPpkt;

 typedef struct {
 	IPpkt iphdr;
@@ -89,14 +89,14 @@
 	unsigned short cks;
 	unsigned short id;
 	unsigned short seq;
-} ICMPpkt;
+} __attribute__ ((aligned(1), packed)) ICMPpkt;

 typedef struct {
 	ICMPpkt icmphdr;
 	unsigned int org;
 	unsigned int rec;
 	unsigned int tra;
-} ICMPTSpkt;
+} __attribute__ ((aligned(1), packed)) ICMPTSpkt;

 typedef struct {
 	IPpkt iphdr;
@@ -104,7 +104,7 @@
 	unsigned short dst_port;
 	unsigned short length;
 	unsigned short cks;
-} UDPpkt;
+} __attribute__ ((aligned(1), packed)) UDPpkt;

 typedef struct {
 	UDPpkt udphdr;
@@ -121,20 +121,20 @@
 	unsigned char srv_name[64];
 	unsigned char boot_filename[128];
 	unsigned char options[64];
-} BOOTPpkt;
+} __attribute__ ((aligned(1), packed)) BOOTPpkt;

 typedef struct {
 	UDPpkt udphdr;
 	unsigned short opcode;
 	char data[138];
-} TFTPRpkt;
+} __attribute__ ((aligned(1), packed)) TFTPRpkt;

 typedef struct {
 	UDPpkt udphdr;
 	unsigned short opcode;
 	unsigned short num;
 	unsigned char data[512];
-} TFTPDpkt;
+} __attribute__ ((aligned(1), packed)) TFTPDpkt;

 extern void processPacket (void);
 extern void processARP (unsigned char *, unsigned short);
diff -Naur tftpnaive-1.3.3/tftpnaive/src/tftp.c tftpnaive-1.3.3-change/tftpnaive/src/tftp.c
--- tftpnaive-1.3.3/tftpnaive/src/tftp.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/tftp.c	2011-01-13 22:17:18.000000000 +0800
@@ -21,6 +21,7 @@

 #include "tftpnaive.h"
 #include "net.h"
+#include "endian.h"
 #include "baselib.h"
 #include "timer.h"
 #ifdef TFTPNAIVE_CRCCHECK
@@ -31,7 +32,7 @@
 	UDPpkt udphdr;
 	unsigned short opcode;
 	unsigned short num;
-} TFTPDReplypkt;
+} __attribute__ ((aligned(1), packed)) TFTPDReplypkt;

 #ifdef TFTPNAIVE_USEPKTCPY

@@ -71,25 +72,25 @@
 		return;

 	if (tftp_req->port == 0)
-		tftp_req->port = tp->udphdr.src_port;
+		tftp_req->port = ntohs(tp->udphdr.src_port);

-	if (tp->udphdr.iphdr.src_ip == tftp_req->server
-		&& tp->udphdr.src_port == tftp_req->port) {
-		if (tp->opcode == 3) {
-			if (tp->num == tftp_req->bloc || tp->num == tftp_req->bloc - 1) {
-				tftpd_reply_pkt.opcode = 4;
-				tftpd_reply_pkt.num = tp->num;
+	if (ntohl(tp->udphdr.iphdr.src_ip) == tftp_req->server
+		&& ntohs(tp->udphdr.src_port) == tftp_req->port) {
+		if (ntohs(tp->opcode) == 3) {
+			if (ntohs(tp->num) == tftp_req->bloc || ntohs(tp->num) == tftp_req->bloc - 1) {
+				tftpd_reply_pkt.opcode = htons(4);
+				tftpd_reply_pkt.num = htons(ntohs(tp->num));
 				for (nbtry = 4; nbtry; --nbtry) {
 					if (sendUDP
 						((UDPpkt *) & tftpd_reply_pkt, 4, tftp_req->server,
-						 TFTP_LOCAL_PORT, tp->udphdr.src_port) == 0)
+						 TFTP_LOCAL_PORT, ntohs(tp->udphdr.src_port)) == 0)
 						break;
 					usleep (1000);
 				}
 				if (nbtry == 0)
 					printf ("TFTP: error sending ACK\n");
-				if (tp->num == tftp_req->bloc) {
-					register unsigned short len = tp->udphdr.length - 12;
+				if (ntohs(tp->num) == tftp_req->bloc) {
+					register unsigned short len = ntohs(tp->udphdr.length) - 12;

 					if (len) {
 						data_copy ((void *) (tftp_req->addr + tftp_req->bcnt),
@@ -107,7 +108,7 @@
 						putchar ('\b');
 					}
 					++tftp_req->bloc;
-					if (tp->udphdr.length < 524) {
+					if (ntohs(tp->udphdr.length) < 524) {
 						tftp_req->sts = 1;
 						printf ("TFTP: downloaded %d bytes\n",
 								tftp_req->bcnt);
@@ -122,9 +123,9 @@
 				}
 			}
 		}
-		else if (tp->opcode == 5) {
-			printf ("TFTP error %d: %s\n", tp->num, tp->data);
-			tftp_req->sts = -tp->num;
+		else if (ntohs(tp->opcode) == 5) {
+			printf ("TFTP error %d: %s\n", ntohs(tp->num), tp->data);
+			tftp_req->sts = -ntohs(tp->num);
 		}
 	}
 }
@@ -136,7 +137,7 @@

 	if (tftp_req) {
 		memset (&tftpr_pkt, 0, sizeof tftpr_pkt);
-		tftpr_pkt.opcode = 1;
+		tftpr_pkt.opcode = htons(1);
 		strcpy (tftpr_pkt.data, tftp_req->file);
 		len = strlen (tftp_req->file) + 1;
 		strcpy (tftpr_pkt.data + len, "octet");
diff -Naur tftpnaive-1.3.3/tftpnaive/src/udp.c tftpnaive-1.3.3-change/tftpnaive/src/udp.c
--- tftpnaive-1.3.3/tftpnaive/src/udp.c	2004-03-21 21:32:59.000000000 +0800
+++ tftpnaive-1.3.3-change/tftpnaive/src/udp.c	2011-01-13 22:16:41.000000000 +0800
@@ -21,6 +21,7 @@

 #include "tftpnaive.h"
 #include "net.h"
+#include "endian.h"
 #include "baselib.h"

 typedef struct {
@@ -28,7 +29,7 @@
 	int da;
 	short pt;
 	short ln;
-} fakehdr;
+} __attribute__ ((aligned(1), packed)) fakehdr;

 void processUDP (unsigned char *pkt, unsigned short len)
 {
@@ -38,17 +39,16 @@

 	if (len >= sizeof (UDPpkt)) {
 		if ((sum = p->cks)) {
-			fh.sa = p->iphdr.src_ip;
-			fh.da = p->iphdr.dst_ip;
-			fh.pt = p->iphdr.prot;
-			fh.ln = p->length;
+			fh.sa = (p->iphdr.src_ip);
+			fh.da = (p->iphdr.dst_ip);
+			fh.pt = ntohs(p->iphdr.prot);
+			fh.ln = (p->length);
 			sum = cks_partial (&fh, sizeof fh, 0);
-			sum = ~cks_partial (&p->src_port, fh.ln, sum);
 		}
 		if (sum == 0) {
-			if (p->dst_port == TFTP_LOCAL_PORT && netif.ip)
+			if (ntohs(p->dst_port) == TFTP_LOCAL_PORT && netif.ip)
 				processTFTP ((TFTPDpkt *) p);
-			else if (p->src_port == BOOTP_SRV_PORT && p->dst_port == BOOTP_CLI_PORT
+			else if (ntohs(p->src_port) == BOOTP_SRV_PORT && ntohs(p->dst_port) == BOOTP_CLI_PORT
 				&& netif.ip == 0)
 				processBOOTP ((BOOTPpkt *) p);
 		}
@@ -65,13 +65,14 @@
 	register unsigned short sum;

 	len += sizeof (UDPpkt) - sizeof (IPpkt);
-	p->src_port = src_port;
-	p->dst_port = dst_port;
-	fh.ln = p->length = len;
+	p->src_port = htons(src_port);
+	p->dst_port = htons(dst_port);
+	fh.ln = htons(len);
+	p->length = htons(len);
 	p->cks = 0;
-	fh.sa = netif.ip;
-	fh.da = dst_ip;
-	fh.pt = PROTO_UDP;
+	fh.sa = htonl(netif.ip);
+	fh.da = htonl(dst_ip);
+	fh.pt = htons(PROTO_UDP);
 	sum = cks_partial (&fh, sizeof fh, 0);
 	sum = ~cks_partial (&p->src_port, len, sum);
 	p->cks = sum ? sum : -1;
