PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/code/classes/Daemon/DNSd/Type/RFC3596.class.php

https://github.com/blekkzor/pinetd2
PHP | 33 lines | 27 code | 5 blank | 1 comment | 3 complexity | 31ee8b168796ac501e77bcf2aa108b6e MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // http://www.ietf.org/rfc/rfc3596.txt
  3. namespace Daemon\DNSd\Type;
  4. class RFC3596 extends Base {
  5. const TYPE_AAAA = 28;
  6. public function decode($val, array $context) {
  7. switch($this->type) {
  8. case self::TYPE_AAAA:
  9. $this->value = inet_ntop($val);
  10. break;
  11. default: // unknown type
  12. $this->value = $val;
  13. return false;
  14. }
  15. return true;
  16. }
  17. public function encode($val = NULL, $offset = NULL) {
  18. if (is_null($val)) $val = $this->value;
  19. switch($this->type) {
  20. case self::TYPE_AAAA:
  21. $enc = inet_pton($val);
  22. if (strlen($enc) != 16) $enc = str_repeat("\0", 16);
  23. return $enc;
  24. default: // unknown type
  25. return $val;
  26. }
  27. }
  28. }