Change the way intToIpv4 works

This commit is contained in:
niten 2023-11-03 12:42:49 -07:00
parent 7ae766bd8a
commit e37fe381d5

View File

@ -39,8 +39,10 @@ in rec {
in foldr (a: b: a + b) 0 (imap0 (i: el: (leftShift el (i * 8))) els); in foldr (a: b: a + b) 0 (imap0 (i: el: (leftShift el (i * 8))) els);
intToIpv4 = int: intToIpv4 = int:
concatStringsSep "." let
(map (i: toString (bitAnd (rightShift int (i * 8)) 255)) [ 3 2 1 0 ]); toComponent = i: toString (bitAnd (rightShift int (i * 8)) 255);
components = map toComponent [ 3 2 1 0 ];
in concatStringsSep "." components;
maskFromV32Network = network: maskFromV32Network = network:
let let
@ -65,12 +67,13 @@ in rec {
ip-int = ipv4ToInt ip; ip-int = ipv4ToInt ip;
net-min = networkMinIp network; net-min = networkMinIp network;
net-max = networkMaxIp network; net-max = networkMaxIp network;
in (ip-int >= (ipv4ToInt (trace "MIN-IP: ${networkMinIp}" networkMinIp))) in (ip-int >= (ipv4ToInt networkMinIp))
&& (ip-int <= (ipv4ToInt (trace "MIN-IP: ${networkMinIp}" networkMaxIp))); && (ip-int <= (ipv4ToInt networkMaxIp));
getNetworkMask = network: toInt (elemAt (splitString "/" network) 1); getNetworkMask = network: toInt (elemAt (splitString "/" network) 1);
getNetworkBase = network: getNetworkBase = network:
assert (builtins.match ".+/[0-9]+" network) != null;
let let
ip = elemAt (splitString "/" network) 0; ip = elemAt (splitString "/" network) 0;
insignificantBits = 32 - (getNetworkMask network); insignificantBits = 32 - (getNetworkMask network);