IPv6.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\extra\ip2region\xdb;
  3. const IPv6VersionNo = 6;
  4. class IPv6
  5. {
  6. public $id;
  7. public $name;
  8. public $bytes;
  9. public $segmentIndexSize;
  10. private static $C = null;
  11. public static function default() {
  12. if (self::$C == null) {
  13. // 38 = 16 + 16 + 2 + 4
  14. self::$C = new self(IPv6VersionNo, 'IPv6', 16, 38);
  15. }
  16. return self::$C;
  17. }
  18. public function __construct($id, $name, $bytes, $segmentIndexSize) {
  19. $this->id = $id;
  20. $this->name = $name;
  21. $this->bytes = $bytes;
  22. $this->segmentIndexSize = $segmentIndexSize;
  23. }
  24. public function ipSubCompare($ip, $buff, $offset) {
  25. // return Util::ipCompare($ip, substr($buff, $offset, strlen($ip)));
  26. return SearchIp::ipSubCompare($ip, $buff, $offset);
  27. }
  28. public function __toString() {
  29. return sprintf(
  30. "{id:%d, name:%s, bytes:%d, segmentIndexSize:%d}",
  31. $this->id, $this->name, $this->bytes, $this->segmentIndexSize
  32. );
  33. }
  34. }