[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [BusyBox] udhcp patches/ endianess
From:       Rainer Weikusat <rainer.weikusat () sncag ! com>
Date:       2005-01-31 15:54:28
Message-ID: 87is5d387f.fsf_-_ () farside ! sncag ! com
[Download RAW message or body]

Compile-time support for different endianesses.

? busybox/networking/udhcp/endianess.h
Index: busybox//include/endianess.h
===================================================================
RCS file: busybox//include/endianess.h
diff -N busybox//include/endianess.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ busybox//include/endianess.h	30 Jan 2005 16:35:26 -0000	1.3
@@ -0,0 +1,38 @@
+/*
+  deal with endianess issues
+
+  	$Id: endianess.h,v 1.3 2005/01/30 16:35:26 rw Exp $
+*/
+#ifndef udhcp_endianess_h
+#define udhcp_endianess_h
+
+/*  includes */
+#include <inttypes.h>
+
+#include <config.h>
+
+/*  functions */
+#ifdef CONFIG_TARGET_LITTLE_ENDIAN
+static inline uint16_t pad_octet_left(uint8_t v, uint8_t pad)
+{
+    return pad | v << 8;
+}
+
+static inline uint16_t pad_octet_right(uint8_t v, uint8_t pad)
+{
+    return v | pad << 8;
+}
+#endif
+#ifdef CONFIG_TARGET_BIG_ENDIAN
+static inline uint16_t pad_octet_left(uint8_t v, uint8_t pad)
+{
+    return pad << 8 | v;
+}
+
+static inline uint16_t pad_octet_right(uint8_t v, uint8_t pad)
+{
+    return v << 8 | pad;
+}
+#endif
+
+#endif
Index: busybox//networking/udhcp/packet.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/packet.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- busybox//networking/udhcp/packet.c	30 Jan 2005 17:10:46 -0000	1.4
+++ busybox//networking/udhcp/packet.c	30 Jan 2005 17:11:33 -0000	1.5
@@ -14,6 +14,8 @@
 #endif
 #include <errno.h>
 
+#include <endianess.h>
+
 #include "packet.h"
 #include "dhcpd.h"
 #include "options.h"
@@ -118,7 +120,7 @@
 		p += 2;
 
 	case 1:
-		a_sum += *p;
+		a_sum += pad_octet_right(*p, 0);
 	}
 
 	while ((a_tmp = a_sum >> 16)) 
Index: busybox//networking/udhcp/packet.h
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/packet.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- busybox//networking/udhcp/packet.h	30 Nov 2004 16:02:32 -0000	1.1.1.1
+++ busybox//networking/udhcp/packet.h	30 Jan 2005 16:36:41 -0000	1.2
@@ -31,7 +31,7 @@
 
 void init_header(struct dhcpMessage *packet, char type);
 int get_packet(struct dhcpMessage *packet, int fd);
-uint16_t checksum(void *addr, int count);
+uint16_t checksum(uint8_t *addr, unsigned count);
 int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
 		   uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex);
 int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
Index: busybox//sysdeps/linux/Config.in
===================================================================
RCS file: /data/repo/busybox/sysdeps/linux/Config.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- busybox//sysdeps/linux/Config.in	30 Nov 2004 16:02:34 -0000	1.1.1.1
+++ busybox//sysdeps/linux/Config.in	30 Jan 2005 16:37:04 -0000	1.2
@@ -196,6 +196,25 @@
 	  if you want to add some simple compiler switches (like -march=i686),
 	  or check for warnings using -Werror, just those options here.
 
+choice
+	prompt "Target byte order"
+	default CONFIG_TARGET_LITTLE_ENDIAN
+	help
+	  Define byte order of the target system. Choices are
+	  "little endian", which means that the octet at the lowest
+	  address of a multi-octet quantity has the lowest numerical
+	  value, and "big endian" ('network byte order'), meaning the
+	  first octet of a multi-octet quantity is that with the
+	  highest numerical value.
+
+config CONFIG_TARGET_LITTLE_ENDIAN
+	bool "Little endian"
+
+config CONFIG_TARGET_BIG_ENDIAN
+	bool "Big endian"
+	
+endchoice	
+
 endmenu
 
 menu 'Installation Options'


_______________________________________________
busybox mailing list
busybox@mail.busybox.net
http://codepoet.org/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic