From 30a545510e846a84997b62900512c6338bd2adc6 Mon Sep 17 00:00:00 2001 From: Preston Brown Date: Mon, 30 Apr 2001 23:17:53 +0000 Subject: --prefix fixups --- src/ipcalc.1 | 4 ++++ src/ipcalc.c | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ipcalc.1 b/src/ipcalc.1 index d5a3e39f..82510e95 100644 --- a/src/ipcalc.1 +++ b/src/ipcalc.1 @@ -29,6 +29,10 @@ address is in a complete class A, B, or C network. Many networks do not use the default netmasks, in which case an inappropriate value will be returned. +.TP +\fB\-p\fR, \fB\-\-prefix\fR +Show the prefix for the given mask/IP address. + .TP \fB\-n\fR, \fB\-\-network\fR Display the network address for the given IP address and netmask. diff --git a/src/ipcalc.c b/src/ipcalc.c index 3fb2bcc6..29d18a67 100644 --- a/src/ipcalc.c +++ b/src/ipcalc.c @@ -183,7 +183,8 @@ const char *get_hostname(unsigned long int addr) For more information, please see the ipcalc(1) man page. */ int main(int argc, const char **argv) { - int showBroadcast = 0, showNetwork = 0, showHostname = 0, showNetmask = 0; + int showBroadcast = 0, showPrefix = 0, showNetwork = 0; + int showHostname = 0, showNetmask = 0; int beSilent = 0; int rc; poptContext optCon; @@ -199,7 +200,9 @@ int main(int argc, const char **argv) { { "netmask", 'm', 0, &showNetmask, 0, "Display default netmask for IP (class A, B, or C)" }, { "network", 'n', 0, &showNetwork, 0, - "Display calculated network address", }, + "Display network address", }, + { "prefix", 'p', 0, &showPrefix, 0, + "Display network prefix", }, { "silent", 's', 0, &beSilent, 0, "Don't ever display error messages " }, POPT_AUTOHELP @@ -296,11 +299,16 @@ int main(int argc, const char **argv) { netmask.s_addr = default_netmask(ip.s_addr); prefix = mask2prefix(netmask.s_addr); } - - printf("PREFIX=%d\n", prefix); + printf("NETMASK=%s\n", inet_ntoa(netmask)); } + if (showPrefix) { + if (!prefix) + prefix = mask2prefix(ip.s_addr); + printf("PREFIX=%d\n", prefix); + } + if (showBroadcast) { broadcast.s_addr = calc_broadcast(ip.s_addr, prefix); printf("BROADCAST=%s\n", inet_ntoa(broadcast)); -- cgit v1.2.1