You are here

function _cidr_match in CloudFlare 6

Same name and namespace in other branches
  1. 7 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 495

Code

function _cidr_match($ip, $range) {
  list($subnet, $bits) = split('/', $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;
}