From 8ddc964cb51430a99285d002fe15a3dcb6a7bdb8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2020 19:59:53 +0200 Subject: global-functions: $IPCalc: return data in array --- global-functions | 25 +++++++++++++++++++------ 1 file 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 -- cgit v1.2.3-70-g09d2