_geoip_seek_country_v6

The Google Font Fix geoip seek country v6 function.

Description

_geoip_seek_country_v6( $gi, $ipnum ); 

Parameters (2)

0. $gi
The gi.
1. $ipnum
The ipnum.

Usage

  1. if ( !function_exists( '_geoip_seek_country_v6' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-font-fix/geo/geoip.inc.php'; 
  3.  
  4. // The gi. 
  5. $gi = null; 
  6.  
  7. // The ipnum. 
  8. $ipnum = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _geoip_seek_country_v6($gi, $ipnum); 
  12.  

Defined (1)

The function is defined in the following location(s).

/geo/geoip.inc.php  
  1. function _geoip_seek_country_v6($gi, $ipnum) 
  2. # arrays from unpack start with offset 1 
  3. # yet another php mystery. array_merge work around 
  4. # this broken behaviour 
  5. $v6vec = array_merge(unpack("C16", $ipnum)); 
  6.  
  7. $offset = 0; 
  8. for ($depth = 127; $depth >= 0; --$depth) { 
  9. if ($gi->flags & GEOIP_MEMORY_CACHE) { 
  10. $buf = _safe_substr
  11. $gi->memory_buffer,  
  12. 2 * $gi->record_length * $offset,  
  13. 2 * $gi->record_length 
  14. ); 
  15. } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { 
  16. $buf = _sharedMemRead($gi,  
  17. 2 * $gi->record_length * $offset,  
  18. 2 * $gi->record_length 
  19. ); 
  20. } else { 
  21. fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 
  22. or trigger_error("GeoIP API: fseek failed", E_USER_ERROR); 
  23. $buf = fread($gi->filehandle, 2 * $gi->record_length); 
  24. $x = array(0, 0); 
  25. for ($i = 0; $i < 2; ++$i) { 
  26. for ($j = 0; $j < $gi->record_length; ++$j) { 
  27. $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8); 
  28.  
  29. $bnum = 127 - $depth; 
  30. $idx = $bnum >> 3; 
  31. $b_mask = 1 << ($bnum & 7 ^ 7); 
  32. if (($v6vec[$idx] & $b_mask) > 0) { 
  33. if ($x[1] >= $gi->databaseSegments) { 
  34. return $x[1]; 
  35. $offset = $x[1]; 
  36. } else { 
  37. if ($x[0] >= $gi->databaseSegments) { 
  38. return $x[0]; 
  39. $offset = $x[0]; 
  40. trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR); 
  41. return false;