function _common_get_org($gi, $seek_org) { $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; if ($gi->flags & GEOIP_SHARED_MEMORY) { $org_buf = @shmop_read($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); } else { fseek($gi->filehandle, $record_pointer, SEEK_SET); $org_buf = fread($gi->filehandle, MAX_ORG_RECORD_LENGTH); } $org_buf = _safe_substr($org_buf, 0, strpos($org_buf, "")); return $org_buf; }
public function _geoip_seek_country_v6($ipnum) { # arrays from unpack start with offset 1 # yet another php mystery. array_merge work around # this broken behaviour $v6vec = array_merge(unpack("C16", $ipnum)); $offset = 0; for ($depth = 127; $depth >= 0; --$depth) { if ($this->flags & self::GEOIP_MEMORY_CACHE) { $buf = _safe_substr($this->memory_buffer, 2 * $this->record_length * $offset, 2 * $this->record_length); } elseif ($this->flags & self::GEOIP_SHARED_MEMORY) { $buf = @shmop_read($this->shmid, 2 * $this->record_length * $offset, 2 * $this->record_length); } else { $try = fseek($this->filehandle, 2 * $this->record_length * $offset, SEEK_SET) == 0; if (!$try) { throw new \Exception("File search error"); } $buf = fread($this->filehandle, 2 * $this->record_length); } $x = array(0, 0); for ($i = 0; $i < 2; ++$i) { for ($j = 0; $j < $this->record_length; ++$j) { $x[$i] += ord($buf[$this->record_length * $i + $j]) << $j * 8; } } $bnum = 127 - $depth; $idx = $bnum >> 3; $b_mask = 1 << ($bnum & 7 ^ 7); if (($v6vec[$idx] & $b_mask) > 0) { if ($x[1] >= $this->databaseSegments) { return $x[1]; } $offset = $x[1]; } else { if ($x[0] >= $this->databaseSegments) { return $x[0]; } $offset = $x[0]; } } trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR); return false; }