diff options
author | Preston Brown <pbrown@redhat.com> | 2001-04-30 23:17:53 +0000 |
---|---|---|
committer | Preston Brown <pbrown@redhat.com> | 2001-04-30 23:17:53 +0000 |
commit | 30a545510e846a84997b62900512c6338bd2adc6 (patch) | |
tree | 634c4d5e55401756af7b8e7aaa1af41d990374d7 | |
parent | ef25029f73c9e4c05797fbd6ba7779ed5185c107 (diff) | |
download | initscripts-30a545510e846a84997b62900512c6338bd2adc6.tar initscripts-30a545510e846a84997b62900512c6338bd2adc6.tar.gz initscripts-30a545510e846a84997b62900512c6338bd2adc6.tar.bz2 initscripts-30a545510e846a84997b62900512c6338bd2adc6.tar.xz initscripts-30a545510e846a84997b62900512c6338bd2adc6.zip |
--prefix fixups
-rw-r--r-- | src/ipcalc.1 | 4 | ||||
-rw-r--r-- | 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 @@ -30,6 +30,10 @@ 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)); |