protected function RequestMatcher::checkIp4

Validates an IPv4 address.

Parameters

string $requestIp:

string $ip:

Return value

boolean True valid, false if not.

1 call to RequestMatcher::checkIp4()
RequestMatcher::checkIp in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/RequestMatcher.php
Validates an IP address.

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/RequestMatcher.php, line 172

Class

RequestMatcher
RequestMatcher compares a pre-defined set of checks against a Request instance.

Namespace

Symfony\Component\HttpFoundation

Code

protected function checkIp4($requestIp, $ip) {
  if (false !== strpos($ip, '/')) {
    list($address, $netmask) = explode('/', $ip, 2);
    if ($netmask < 1 || $netmask > 32) {
      return false;
    }
  }
  else {
    $address = $ip;
    $netmask = 32;
  }
  return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
}