Question.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_Question object definition {{{ */
  23. /**
  24. * Builds or parses the QUESTION section of a DNS packet
  25. *
  26. * Builds or parses the QUESTION section of a DNS packet
  27. *
  28. * @package Net_DNS
  29. */
  30. class Net_DNS_Question
  31. {
  32. /* class variable definitions {{{ */
  33. var $qname = NULL;
  34. var $qtype = NULL;
  35. var $qclass = NULL;
  36. /* }}} */
  37. /* class constructor Net_DNS_Question($qname, $qtype, $qclass) {{{ */
  38. function Net_DNS_Question($qname, $qtype, $qclass)
  39. {
  40. if ( is_null(Net_DNS::typesbyname($qtype))
  41. && !is_null(Net_DNS::classesbyname($qtype))
  42. && is_null(Net_DNS::classesbyname($qclass))
  43. && !is_null(Net_DNS::typesbyname($qclass))) {
  44. $t = $qtype;
  45. $qtype = $qclass;
  46. $qclass = $t;
  47. }
  48. $this->qname = $qname;
  49. $this->qtype = $qtype;
  50. $this->qclass = $qclass;
  51. }
  52. /* }}} */
  53. /* Net_DNS_Question::display() {{{*/
  54. function display()
  55. {
  56. echo $this->string() . "\n";
  57. }
  58. /*}}}*/
  59. /* Net_DNS_Question::string() {{{*/
  60. function string()
  61. {
  62. return($this->qname . ".\t" . $this->qclass . "\t" . $this->qtype);
  63. }
  64. /*}}}*/
  65. /* Net_DNS_Question::data(&$packet, $offset) {{{*/
  66. function data($packet, $offset)
  67. {
  68. $data = $packet->dn_comp($this->qname, $offset);
  69. $data .= pack('n', Net_DNS::typesbyname(strtoupper($this->qtype)));
  70. $data .= pack('n', Net_DNS::classesbyname(strtoupper($this->qclass)));
  71. return($data);
  72. }
  73. /*}}}*/
  74. }
  75. /* }}} */
  76. /* VIM settings{{{
  77. * Local variables:
  78. * tab-width: 4
  79. * c-basic-offset: 4
  80. * soft-stop-width: 4
  81. * c indent on
  82. * End:
  83. * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  84. * vim<600: sw=4 ts=4
  85. * }}} */
  86. ?>