getNumberOfBits())); } $numberOfBits = $from->getNumberOfBits(); if ($to->getNumberOfBits() !== $numberOfBits) { return null; } $calculator = new RangesFromBounradyCalculator($numberOfBits); return $calculator->getRanges($from, $to); } /** * @param \IPLib\Address\AddressInterface $from * @param \IPLib\Address\AddressInterface $to * * @return \IPLib\Range\RangeInterface|null */ protected static function rangeFromBoundaryAddresses(AddressInterface $from = null, AddressInterface $to = null) { if ($from === null && $to === null) { $result = null; } elseif ($to === null) { $result = Range\Single::fromAddress($from); } elseif ($from === null) { $result = Range\Single::fromAddress($to); } else { $result = null; $addressType = $from->getAddressType(); if ($addressType === $to->getAddressType()) { $cmp = strcmp($from->getComparableString(), $to->getComparableString()); if ($cmp === 0) { $result = Range\Single::fromAddress($from); } else { if ($cmp > 0) { list($from, $to) = array($to, $from); } $fromBytes = $from->getBytes(); $toBytes = $to->getBytes(); $numBytes = count($fromBytes); $sameBits = 0; for ($byteIndex = 0; $byteIndex < $numBytes; $byteIndex++) { $fromByte = $fromBytes[$byteIndex]; $toByte = $toBytes[$byteIndex]; if ($fromByte === $toByte) { $sameBits += 8; } else { $differentBitsInByte = decbin($fromByte ^ $toByte); $sameBits += 8 - strlen($differentBitsInByte); break; } } $result = static::rangeFromString($from->toString(true) . '/' . (string) $sameBits); } } } return $result; } /** * @param string|\IPLib\Address\AddressInterface $from * @param string|\IPLib\Address\AddressInterface $to * @param bool $supportNonDecimalIPv4 * * @return \IPLib\Address\AddressInterface[]|null[]|false[] */ private static function parseBoundaries($from, $to, $supportNonDecimalIPv4 = false) { $result = array(); foreach (array('from', 'to') as $param) { $value = $$param; if (!($value instanceof AddressInterface)) { $value = (string) $value; if ($value === '') { $value = null; } else { $value = static::addressFromString($value, true, true, $supportNonDecimalIPv4); if ($value === null) { $value = false; } } } $result[] = $value; } if ($result[0] && $result[1] && strcmp($result[0]->getComparableString(), $result[1]->getComparableString()) > 0) { $result = array($result[1], $result[0]); } return $result; } }