SOA.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /*
  3. * License Information:
  4. *
  5. * Net_DNS: A resolver library for PHP
  6. * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /* Net_DNS_RR_SOA definition {{{ */
  23. /**
  24. * A representation of a resource record of type <b>SOA</b>
  25. *
  26. * @package Net_DNS
  27. */
  28. class Net_DNS_RR_SOA extends Net_DNS_RR
  29. {
  30. /* class variable definitions {{{ */
  31. var $name;
  32. var $type;
  33. var $class;
  34. var $ttl;
  35. var $rdlength;
  36. var $rdata;
  37. var $mname;
  38. var $rname;
  39. var $serial;
  40. var $refresh;
  41. var $retry;
  42. var $expire;
  43. var $minimum;
  44. /* }}} */
  45. /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
  46. function Net_DNS_RR_SOA(&$rro, $data, $offset = '')
  47. {
  48. $this->name = $rro->name;
  49. $this->type = $rro->type;
  50. $this->class = $rro->class;
  51. $this->ttl = $rro->ttl;
  52. $this->rdlength = $rro->rdlength;
  53. $this->rdata = $rro->rdata;
  54. if ($offset) {
  55. if ($this->rdlength > 0) {
  56. list($mname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
  57. list($rname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
  58. $a = unpack("@$offset/N5soavals", $data);
  59. $this->mname = $mname;
  60. $this->rname = $rname;
  61. $this->serial = $a['soavals1'];
  62. $this->refresh = $a['soavals2'];
  63. $this->retry = $a['soavals3'];
  64. $this->expire = $a['soavals4'];
  65. $this->minimum = $a['soavals5'];
  66. }
  67. } else {
  68. if (ereg("([^ \t]+)[ \t]+([^ \t]+)[ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]*$", $string, $regs))
  69. {
  70. $this->mname = ereg_replace('(.*)\.$', '\\1', $regs[1]);
  71. $this->rname = ereg_replace('(.*)\.$', '\\1', $regs[2]);
  72. $this->serial = $regs[3];
  73. $this->refresh = $regs[4];
  74. $this->retry = $regs[5];
  75. $this->expire = $regs[6];
  76. $this->minimum = $regs[7];
  77. }
  78. }
  79. }
  80. /* }}} */
  81. /* Net_DNS_RR_SOA::rdatastr($pretty = 0) {{{ */
  82. function rdatastr($pretty = 0)
  83. {
  84. if (strlen($this->mname)) {
  85. if ($pretty) {
  86. $rdatastr = $this->mname . '. ' . $this->rname . ". (\n";
  87. $rdatastr .= "\t\t\t\t\t" . $this->serial . "\t; Serial\n";
  88. $rdatastr .= "\t\t\t\t\t" . $this->refresh . "\t; Refresh\n";
  89. $rdatastr .= "\t\t\t\t\t" . $this->retry . "\t; Retry\n";
  90. $rdatastr .= "\t\t\t\t\t" . $this->expire . "\t; Expire\n";
  91. $rdatastr .= "\t\t\t\t\t" . $this->minimum . " )\t; Minimum TTL";
  92. } else {
  93. $rdatastr = $this->mname . '. ' . $this->rname . '. ' .
  94. $this->serial . ' ' . $this->refresh . ' ' . $this->retry . ' ' .
  95. $this->expire . ' ' . $this->minimum;
  96. }
  97. return($rdatastr);
  98. }
  99. return('; no data');
  100. }
  101. /* }}} */
  102. /* Net_DNS_RR_SOA::rr_rdata($packet, $offset) {{{ */
  103. function rr_rdata($packet, $offset)
  104. {
  105. if (strlen($this->mname)) {
  106. $rdata = $packet->dn_comp($this->mname, $offset);
  107. $rdata .= $packet->dn_comp($this->rname, $offset + strlen($rdata));
  108. $rdata .= pack('N5', $this->serial,
  109. $this->refresh,
  110. $this->retry,
  111. $this->expire,
  112. $this->minimum);
  113. return($rdata);
  114. }
  115. return(NULL);
  116. }
  117. /* }}} */
  118. }
  119. /* }}} */
  120. /* VIM settings {{{
  121. * Local variables:
  122. * tab-width: 4
  123. * c-basic-offset: 4
  124. * soft-stop-width: 4
  125. * c indent on
  126. * End:
  127. * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  128. * vim<600: sw=4 ts=4
  129. * }}} */
  130. ?>