PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/blekkzor/pinetd2
PHP | 37 lines | 27 code | 6 blank | 4 comment | 1 complexity | 7e76564738b8239081f043724a7b0f48 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // http://www.ietf.org/rfc/rfc2782.txt
  3. // Type "SRV"
  4. // <int> <int> <int> <label>
  5. // SRV Priority Weight Port Target
  6. namespace Daemon\DNSd\Type;
  7. class RFC2782 extends Base {
  8. const TYPE_SRV = 33;
  9. public function decode($val, array $context) {
  10. switch($this->type) {
  11. case self::TYPE_SRV:
  12. $this->value = unpack('npriority/nrefresh/nretry', substr($val, 0, 6));
  13. $offset = 6;
  14. $this->value['host'] = $this->pkt->decodeLabel($val, $offset);
  15. break;
  16. default: // unknown type
  17. $this->value = $val;
  18. return false;
  19. }
  20. return true;
  21. }
  22. public function encode($val = NULL, $offset = NULL) {
  23. if (is_null($val)) $val = $this->value;
  24. switch($this->type) {
  25. case self::TYPE_SRV:
  26. return pack('nnn', $val['priority'], $val['refresh'], $val['retry']).$this->pkt->encodeLabel($val['host'], $offset+6);
  27. default: // unknown type
  28. return $val;
  29. }
  30. }
  31. }