From 4e2822fc434126830c8fc362e704f38acda94287 Mon Sep 17 00:00:00 2001 From: Erik Troan Date: Sun, 22 Mar 1998 20:33:49 +0000 Subject: added --netmask argument --- src/ipcalc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipcalc.c b/src/ipcalc.c index 2535bb6b..fc8d3d5c 100644 --- a/src/ipcalc.c +++ b/src/ipcalc.c @@ -8,7 +8,7 @@ typedef unsigned int int32; int main(int argc, char ** argv) { - int showBroadcast = 0, showNetwork = 0, showHostname = 0; + int showBroadcast = 0, showNetwork = 0, showHostname = 0, showNetmask = 0; int beSilent = 0; int rc; poptContext optCon; @@ -19,6 +19,7 @@ int main(int argc, char ** argv) { struct poptOption optionsTable[] = { { "broadcast", '\0', 0, &showBroadcast, 0 }, { "hostname", '\0', 0, &showHostname, 0 }, + { "netmask", '\0', 0, &showNetmask, 0 }, { "network", '\0', 0, &showNetwork, 0 }, { "silent", '\0', 0, &beSilent, 0 }, { NULL, '\0', 0, 0, 0 }, @@ -69,6 +70,16 @@ int main(int argc, char ** argv) { return 1; } + if (showNetmask) { + if (((ntohl(ip) & 0xFF000000) >> 24) <= 127) + chptr = "255.0.0.0"; + else if (((ntohl(ip) & 0xFF000000) >> 24) <= 191) + chptr = "255.255.0.0"; + else + chptr = "255.255.255.0"; + + printf("NETMASK=%s\n", chptr); + } if (showBroadcast) { broadcast = (ip & netmask) | ~netmask; -- cgit v1.2.1