You are here

public function IpAddress::inRange in IP address fields 8

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

Checks if the stored IP is within $min and $max IPs.

File

src/IpAddress.php, line 70

Class

IpAddress
IpTools class.

Namespace

Drupal\field_ipaddress

Code

public function inRange($min, $max) {
  if (!$this
    ->isIpAddress($min) || !$this
    ->isIpAddress($max)) {
    throw new \Exception('Invalid value.');
  }

  // IPs in different families are by default not within range.
  if ($this
    ->getFamily($min) != $this->family || $this
    ->getFamily($max) != $this->family) {
    return FALSE;
  }
  if ($this->family == self::IP_FAMILY_4) {
    return $this
      ->inRange4($min, $max);
  }
  else {
    return $this
      ->inRange6($min, $max);
  }
}