Even more RST fixes

This commit is contained in:
Pinga 2025-04-29 01:25:19 +03:00
parent 7c3ed1da81
commit 5f45f83c1d
2 changed files with 34 additions and 10 deletions

View file

@ -1035,9 +1035,23 @@ function validateHostName(string $hostName): bool
}
function ipMatches($ip, $cidr) {
if (strpos($cidr, '/') === false) {
return false; // invalid CIDR
}
list($subnet, $mask) = explode('/', $cidr);
if (!is_numeric($mask) || $mask < 0 || $mask > 32) {
return false; // invalid mask
}
$ipLong = ip2long($ip);
$subnetLong = ip2long($subnet);
if ($ipLong === false || $subnetLong === false) {
return false; // invalid IP
}
$maskLong = -1 << (32 - (int)$mask);
return ($ipLong & $maskLong) === ($subnetLong & $maskLong);
}