mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-05 02:23:27 +02:00
Even more RST fixes
This commit is contained in:
parent
7c3ed1da81
commit
5f45f83c1d
2 changed files with 34 additions and 10 deletions
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue