[BusyBox] Small patches for ipcalc and nameif.

Lars Kellogg-Stedman lars at larsshack.org
Thu Jul 3 22:33:33 UTC 2003


Hello all,

There are two patches attached to this message.

The first fixes endian problems in networking/ipcalc.c -- it was
returning bogus values on a PPC system; this patch makes it work in both
Intel and PPC environments.  I'm not sure this is the cleanest solution,
but it does work.

The second patch makes networking/nameif.c compile correctly on systems
that do not define IF_NAMESIZE.  This appears to be a glibc version
issue.

-- Lars
-------------- next part --------------
This patch fixes endian problems with get_netmask().  I don't know if
this is the cleanest solution, but it makes 'ipcalc -n' work on both
an i386 system and a ppc system.

Index: networking/ipcalc.c
===================================================================
RCS file: /var/cvs/busybox/networking/ipcalc.c,v
retrieving revision 1.3
diff -b -B -u -r1.3 ipcalc.c
--- networking/ipcalc.c	3 Jul 2003 10:28:07 -0000	1.3
+++ networking/ipcalc.c	3 Jul 2003 22:14:38 -0000
@@ -22,15 +22,22 @@
 
 #define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;}
 
+#define CLASS_A_NETMASK	ntohl(0xFF000000)
+#define CLASS_B_NETMASK	ntohl(0xFFFF0000)
+#define CLASS_C_NETMASK	ntohl(0xFFFFFF00)
+
 static unsigned long get_netmask(unsigned long ipaddr)
 {
-	if (ipaddr & 0xC0) {
-		return 0x00FFFFFF;	/* Class C */
-	}
-	if (ipaddr & 0x10) {
-		return 0x0000FFFF;	/* Class B */
-	}
-	return 0x000000FF;	/* Class A */
+	ipaddr = htonl(ipaddr);
+
+	if ((ipaddr & 0xC0000000) == 0xC0000000)
+		return CLASS_C_NETMASK;
+	else if ((ipaddr & 0x80000000) == 0x80000000)
+		return CLASS_B_NETMASK;
+	else if ((ipaddr & 0x80000000) == 0)
+		return CLASS_A_NETMASK;
+	else
+		return 0;
 }
 
 #define NETMASK   0x01
-------------- next part --------------
Glibc 2.1.3 (used by the Hardhat Linux SDK distributed by Cyclades) 
does not define IF_NAMESIZE in net/if.h.

Index: networking/nameif.c
===================================================================
RCS file: /var/cvs/busybox/networking/nameif.c,v
retrieving revision 1.7
diff -b -B -u -r1.7 nameif.c
--- networking/nameif.c	19 Mar 2003 09:12:38 -0000	1.7
+++ networking/nameif.c	3 Jul 2003 22:36:28 -0000
@@ -35,6 +35,15 @@
 
 #include "busybox.h"
 
+/* Older versions of net/if.h do not appear to define IF_NAMESIZE. */
+#ifndef IF_NAMESIZE
+#  ifdef IFNAMSIZ
+#    define IF_NAMESIZE IFNAMSIZ
+#  else
+#    define IF_NAMESIZE 16
+#  endif
+#endif
+
 /* take from linux/sockios.h */
 #define SIOCSIFNAME	0x8923	/* set interface name */
 


More information about the busybox mailing list