private function Reader::findAddressInTree in Smart IP 6.2
Same name and namespace in other branches
- 7.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php \MaxMind\Db\Reader::findAddressInTree()
1 call to Reader::findAddressInTree()
- Reader::get in includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php
- Looks up the <code>address</code> in the MaxMind DB.
File
- includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php, line 118
Class
- Reader
- Instances of this class provide a reader for the MaxMind DB format. IP
addresses can be looked up using the <code>get</code> method.
Namespace
MaxMind\Db
Code
private function findAddressInTree($ipAddress) {
$rawAddress = array_merge(unpack('C*', inet_pton($ipAddress)));
$bitCount = count($rawAddress) * 8;
$node = $this
->startNode($bitCount);
for ($i = 0; $i < $bitCount; $i++) {
if ($node >= $this->metadata->nodeCount) {
break;
}
$tempBit = 0xff & $rawAddress[$i >> 3];
$bit = 1 & $tempBit >> 7 - $i % 8;
$node = $this
->readNode($node, $bit);
}
if ($node == $this->metadata->nodeCount) {
return 0;
}
elseif ($node > $this->metadata->nodeCount) {
return $node;
}
throw new InvalidDatabaseException("Something bad happened");
}