You are here

private function IpAddress::inRange4 in IP address fields 8

Same name and namespace in other branches
  1. 2.0.x src/IpAddress.php \Drupal\field_ipaddress\IpAddress::inRange4()

Checks if the current IPv4 is within a given min and max IP.

See also

https://stackoverflow.com/questions/18336908/php-check-if-ip-address-is-...

1 call to IpAddress::inRange4()
IpAddress::inRange in src/IpAddress.php
Checks if the stored IP is within $min and $max IPs.

File

src/IpAddress.php, line 275

Class

IpAddress
IpTools class.

Namespace

Drupal\field_ipaddress

Code

private function inRange4($min, $max) {
  $min_long = ip2long($min);
  $max_long = ip2long($max);
  if ($this->type == self::IP_RANGE_NONE) {
    $start_long = $end_long = ip2long($this->start);
  }
  else {
    $start_long = ip2long($this->start);
    $end_long = ip2long($this->end);
  }
  return $start_long >= $min_long && $start_long <= $max_long && ($end_long >= $min_long && $end_long <= $max_long);
}