aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-10-10 19:59:53 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-10-10 19:59:53 +0200
commit8ddc964cb51430a99285d002fe15a3dcb6a7bdb8 (patch)
tree28c51bfa30be0fd5fddfd2726d24cf7b4af8b925 /global-functions
parent8e6403b1bedd837485d86641aed2013abc4cc7f0 (diff)
global-functions: $IPCalc: return data in array
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions25
1 files changed, 19 insertions, 6 deletions
diff --git a/global-functions b/global-functions
index 366804a..2716355 100644
--- a/global-functions
+++ b/global-functions
@@ -379,13 +379,26 @@
:local Bits [ :tonum [ :pick $Input ([ :find $Input "/" ] + 1) [ :len $Input ] ] ];
:local Mask ((255.255.255.255 << (32 - $Bits)) & 255.255.255.255);
+ :local Return {
+ "address"=$Address;
+ "netmask"=$Mask;
+ "networkaddress"=($Address & $Mask);
+ "networkbits"=$Bits;
+ "network"=(($Address & $Mask) . "/" . $Bits);
+ "hostmin"=(($Address & $Mask) | 0.0.0.1);
+ "hostmax"=(($Address | ~$Mask) ^ 0.0.0.1);
+ "broadcast"=($Address | ~$Mask);
+ }
+
:put ( \
- "Address: " . $Address . "\n\r" . \
- "Netmask: " . $Mask . "\n\r" . \
- "Network: " . ($Address & $Mask) . "/" . $Bits . "\n\r" . \
- "HostMin: " . (($Address & $Mask) | 0.0.0.1) . "\n\r" . \
- "HostMax: " . (($Address | ~$Mask) ^ 0.0.0.1) . "\n\r" . \
- "Broadcast: " . ($Address | ~$Mask));
+ "Address: " . $Return->"address" . "\n\r" . \
+ "Netmask: " . $Return->"netmask" . "\n\r" . \
+ "Network: " . $Return->"network" . "\n\r" . \
+ "HostMin: " . $Return->"hostmin" . "\n\r" . \
+ "HostMax: " . $Return->"hostmax" . "\n\r" . \
+ "Broadcast: " . $Return->"broadcast");
+
+ :return $Return;
}
# log and print with same text, optionally exit