You are here

private function Reader::readNode in Smart IP 6.2

Same name and namespace in other branches
  1. 7.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php \MaxMind\Db\Reader::readNode()
2 calls to Reader::readNode()
Reader::findAddressInTree in includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php
Reader::ipV4StartNode in includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php

File

includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php, line 181

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 readNode($nodeNumber, $index) {
  $baseOffset = $nodeNumber * $this->metadata->nodeByteSize;

  // XXX - probably could condense this.
  switch ($this->metadata->recordSize) {
    case 24:
      $bytes = Util::read($this->fileHandle, $baseOffset + $index * 3, 3);
      list(, $node) = unpack('N', "\0" . $bytes);
      return $node;
    case 28:
      $middleByte = Util::read($this->fileHandle, $baseOffset + 3, 1);
      list(, $middle) = unpack('C', $middleByte);
      if ($index == 0) {
        $middle = (0xf0 & $middle) >> 4;
      }
      else {
        $middle = 0xf & $middle;
      }
      $bytes = Util::read($this->fileHandle, $baseOffset + $index * 4, 3);
      list(, $node) = unpack('N', chr($middle) . $bytes);
      return $node;
    case 32:
      $bytes = Util::read($this->fileHandle, $baseOffset + $index * 4, 4);
      list(, $node) = unpack('N', $bytes);
      return $node;
    default:
      throw new InvalidDatabaseException('Unknown record size: ' . $this->metadata->recordSize);
  }
}