aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2002-04-12 22:51:08 +0000
committerBill Nottingham <notting@redhat.com>2002-04-12 22:51:08 +0000
commit5a185803ee50cfbfd26ee8effff3552b01645db6 (patch)
tree90625f5f85f4e71f9a00ef49ad92749c08103f90
parent4e4eb9b9633136a6dfc2937149245b538bdafd0b (diff)
downloadinitscripts-5a185803ee50cfbfd26ee8effff3552b01645db6.tar
initscripts-5a185803ee50cfbfd26ee8effff3552b01645db6.tar.gz
initscripts-5a185803ee50cfbfd26ee8effff3552b01645db6.tar.bz2
initscripts-5a185803ee50cfbfd26ee8effff3552b01645db6.tar.xz
initscripts-5a185803ee50cfbfd26ee8effff3552b01645db6.zip
some minor ipcalc cleanups (#58410)
-rw-r--r--src/ipcalc.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/ipcalc.c b/src/ipcalc.c
index ad279587..d981be83 100644
--- a/src/ipcalc.c
+++ b/src/ipcalc.c
@@ -239,13 +239,6 @@ int main(int argc, const char **argv) {
} else
prefixStr = NULL;
- if (!inet_aton(ipStr, &ip)) {
- if (!beSilent)
- fprintf(stderr, "ipcalc: bad ip address: %s\n",
- ipStr);
- return 1;
- }
-
if (prefixStr != NULL) {
prefix = atoi(prefixStr);
if (prefix == 0) {
@@ -264,6 +257,12 @@ int main(int argc, const char **argv) {
poptPrintHelp(optCon, stderr, 0);
}
return 1;
+ } else if (netmaskStr && prefix != 0) {
+ if (!beSilent) {
+ fprintf(stderr, "ipcalc: both netmask and prefix specified\n");
+ poptPrintHelp(optCon, stderr, 0);
+ }
+ return 1;
} else if (netmaskStr) {
if (!inet_aton(netmaskStr, &netmask)) {
if (!beSilent)
@@ -283,6 +282,26 @@ int main(int argc, const char **argv) {
return 1;
}
+ /* Handle CIDR entries such as 172/8 */
+ if (prefix) {
+ char *tmp = ipStr;
+ int i;
+
+ for(i=3; i> 0; i--) {
+ tmp = strchr(tmp,'.');
+ if (!tmp)
+ break;
+ else
+ tmp++;
+ }
+ tmp = NULL;
+ for (; i>0; i--) {
+ tmp = malloc(strlen(ipStr + 3));
+ sprintf(tmp,"%s.0",ipStr);
+ ipStr = tmp;
+ }
+ }
+
if (!inet_aton(ipStr, (struct in_addr *) &ip)) {
if (!beSilent)
fprintf(stderr, "ipcalc: bad ip address: %s\n", ipStr);