summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-07-05 07:59:30 +0000
committerEric Andersen <andersen@codepoet.org>2003-07-05 07:59:30 +0000
commit7207b88d062ca3fe58370ef9976388c0023ff746 (patch)
treee9164acc8a39daebf9bd66d589faa3f1d1a2c071 /networking
parent65e20a33c20314da5dd33d6e9e2ec529d835bbfb (diff)
downloadbusybox-w32-7207b88d062ca3fe58370ef9976388c0023ff746.tar.gz
busybox-w32-7207b88d062ca3fe58370ef9976388c0023ff746.tar.bz2
busybox-w32-7207b88d062ca3fe58370ef9976388c0023ff746.zip
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.
Diffstat (limited to 'networking')
-rw-r--r--networking/ipcalc.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/networking/ipcalc.c b/networking/ipcalc.c
index af4eed4a4..94b747ef6 100644
--- a/networking/ipcalc.c
+++ b/networking/ipcalc.c
@@ -22,15 +22,22 @@
22 22
23#define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;} 23#define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;}
24 24
25#define CLASS_A_NETMASK ntohl(0xFF000000)
26#define CLASS_B_NETMASK ntohl(0xFFFF0000)
27#define CLASS_C_NETMASK ntohl(0xFFFFFF00)
28
25static unsigned long get_netmask(unsigned long ipaddr) 29static unsigned long get_netmask(unsigned long ipaddr)
26{ 30{
27 if (ipaddr & 0xC0) { 31 ipaddr = htonl(ipaddr);
28 return 0x00FFFFFF; /* Class C */ 32
29 } 33 if ((ipaddr & 0xC0000000) == 0xC0000000)
30 if (ipaddr & 0x10) { 34 return CLASS_C_NETMASK;
31 return 0x0000FFFF; /* Class B */ 35 else if ((ipaddr & 0x80000000) == 0x80000000)
32 } 36 return CLASS_B_NETMASK;
33 return 0x000000FF; /* Class A */ 37 else if ((ipaddr & 0x80000000) == 0)
38 return CLASS_A_NETMASK;
39 else
40 return 0;
34} 41}
35 42
36#define NETMASK 0x01 43#define NETMASK 0x01