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\DbCode
private function findAddressInTree($ipAddress) {
// XXX - could simplify. Done as a byte array to ease porting
$rawAddress = array_merge(unpack('C*', inet_pton($ipAddress)));
$bitCount = count($rawAddress) * 8;
// The first node of the tree is always node 0, at the beginning of the
// value
$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) {
// Record is empty
return 0;
}
elseif ($node > $this->metadata->nodeCount) {
// Record is a data pointer
return $node;
}
throw new InvalidDatabaseException("Something bad happened");
}