You are here

function _cidr_match in CloudFlare 7

Same name and namespace in other branches
  1. 6 cloudflare.module \_cidr_match()
1 call to _cidr_match()
_cloudflare_threat_api in ./cloudflare.module
Perform an action using Cloudflare's Threat API.

File

./cloudflare.module, line 525

Code

function _cidr_match($ip, $range) {
  list($subnet, $bits) = explode('/', $range);
  $ip = ip2long($ip);
  $subnet = ip2long($subnet);
  $mask = -1 << 32 - $bits;
  $subnet &= $mask;

  # nb: in case the supplied subnet wasn't correctly aligned
  return ($ip & $mask) == $subnet;
}