[BusyBox-cvs] busybox/networking ipcalc.c,1.3,1.4
Erik Andersen
andersen at busybox.net
Sat Jul 5 07:59:34 UTC 2003
Update of /var/cvs/busybox/networking
In directory winder:/tmp/cvs-serv15125/networking
Modified Files:
ipcalc.c
Log Message:
Patch from Lars Kellogg-Stedman:
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: ipcalc.c
===================================================================
RCS file: /var/cvs/busybox/networking/ipcalc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ipcalc.c 3 Jul 2003 10:28:07 -0000 1.3
+++ ipcalc.c 5 Jul 2003 07:59:30 -0000 1.4
@@ -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
More information about the busybox-cvs
mailing list