subnet address: MDL-19509 make subnet matching work with 0.0.0.0/0

Merged from MOODLE_18_STABLE
This commit is contained in:
iarenaza
2009-06-18 22:23:25 +00:00
parent 7d8b34d478
commit 656ff52256
+5 -1
View File
@@ -7245,7 +7245,11 @@ function address_in_subnet($addr, $subnetstr) {
if ($mask === '' || $mask > 32) {
$mask = 32;
}
$mask = 0xffffffff << (32 - $mask);
// When $mask is zero, PHP's integer arithmetic gives us a mask
// of 255.255.255.255 instead of 0.0.0.0, so special case it
if ($mask != 0) {
$mask = 0xffffffff << (32 - $mask);
}
$found = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask));
} else if (strpos($subnet, '-') !== false) {/// type 3
$subnetparts = explode('.', $subnet);