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.
This commit is contained in:
Eric Andersen 2003-07-05 07:59:30 +00:00
parent 65e20a33c2
commit 7207b88d06

View File

@ -22,15 +22,22 @@
#define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;} #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) static unsigned long get_netmask(unsigned long ipaddr)
{ {
if (ipaddr & 0xC0) { ipaddr = htonl(ipaddr);
return 0x00FFFFFF; /* Class C */
} if ((ipaddr & 0xC0000000) == 0xC0000000)
if (ipaddr & 0x10) { return CLASS_C_NETMASK;
return 0x0000FFFF; /* Class B */ else if ((ipaddr & 0x80000000) == 0x80000000)
} return CLASS_B_NETMASK;
return 0x000000FF; /* Class A */ else if ((ipaddr & 0x80000000) == 0)
return CLASS_A_NETMASK;
else
return 0;
} }
#define NETMASK 0x01 #define NETMASK 0x01