function _sf_notifications_cidr_match in Salesforce Suite 7.2
Same name and namespace in other branches
- 6.2 sf_notifications/sf_notifications.module \_sf_notifications_cidr_match()
Given a CIDR mask and an IP address, return TRUE or FALSE if the IP address matches or doesn't match the CIDR mask. Adapted from http://stackoverflow.com/questions/594112
1 call to _sf_notifications_cidr_match()
- sf_notifications_allowed_ips in sf_notifications/
sf_notifications.module - Access callback for SALESFORCE_PATH_NOTIFICATIONS_ENDPOINT
File
- sf_notifications/
sf_notifications.module, line 92
Code
function _sf_notifications_cidr_match($ip, $range) {
list($subnet, $bits) = explode('/', $range);
$ip = ip2long($ip);
$subnet = ip2long($subnet);
// Sanity check: ip2long() returns FALSE for an invalid IP address.
if (empty($subnet) || empty($bits) || empty($ip)) {
return FALSE;
}
$mask = -1 << 32 - $bits;
$subnet &= $mask;
// in case the supplied subnet wasn't correctly aligned
return ($ip & $mask) == $subnet;
}