MVC/Firewall/Util - add CIDRToMask()

This commit is contained in:
Ad Schellevis 2023-05-10 19:15:57 +02:00
parent 271525f00b
commit d633cd961f

View File

@ -339,6 +339,16 @@ class Util
return md5(json_encode($rule));
}
/**
* convert ipv4 cidr to netmask e.g. 24 --> 255.255.255.0
* @param int $bits ipv4 bits
* @return string netmask
*/
public static function CIDRToMask($bits)
{
return long2ip(0xFFFFFFFF << (32 - $bits));
}
/**
* Find the smallest possible subnet mask for given IP range
* @param array ips (start, end)