PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Net/DNS/RR/HINFO.php

https://github.com/ldath/Sblam
PHP | 110 lines | 60 code | 8 blank | 42 comment | 6 complexity | 24699fe824bec5c66ed0a777dd242d51 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  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. * Maintainers:
  8. * Marco Kaiser <bate@php.net>
  9. * Florian Anderiasch <fa@php.net>
  10. *
  11. * PHP versions 4 and 5
  12. *
  13. * LICENSE: This source file is subject to version 3.01 of the PHP license
  14. * that is available through the world-wide-web at the following URI:
  15. * http://www.php.net/license/3_01.txt. If you did not receive a copy of
  16. * the PHP License and are unable to obtain it through the web, please
  17. * send a note to license@php.net so we can mail you a copy immediately.
  18. */
  19. /* Net_DNS_RR_HINFO definition {{{ */
  20. /**
  21. * A representation of a resource record of type <b>HINFO</b>
  22. *
  23. * @package Net_DNS
  24. */
  25. class Net_DNS_RR_HINFO extends Net_DNS_RR
  26. {
  27. /* class variable definitions {{{ */
  28. var $name;
  29. var $type;
  30. var $class;
  31. var $ttl;
  32. var $rdlength;
  33. var $rdata;
  34. var $cpu;
  35. var $os;
  36. /* }}} */
  37. /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
  38. function Net_DNS_RR_HINFO(&$rro, $data, $offset = '')
  39. {
  40. $this->name = $rro->name;
  41. $this->type = $rro->type;
  42. $this->class = $rro->class;
  43. $this->ttl = $rro->ttl;
  44. $this->rdlength = $rro->rdlength;
  45. $this->rdata = $rro->rdata;
  46. if ($offset) {
  47. if ($this->rdlength > 0) {
  48. list($cpu, $offset) = Net_DNS_Packet::label_extract($data, $offset);
  49. list($os, $offset) = Net_DNS_Packet::label_extract($data, $offset);
  50. $this->cpu = $cpu;
  51. $this->os = $os;
  52. }
  53. } elseif (is_array($data)) {
  54. $this->cpu = $data['cpu'];
  55. $this->os = $data['os'];
  56. } else {
  57. $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */
  58. $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */
  59. preg_match('/("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]*$/', $data, $regs);
  60. foreach($regs as $idx => $value) {
  61. $value = str_replace(chr(2) . chr(2), '\\"', $value);
  62. $value = str_replace(chr(1) . chr(1), '\\\\', $value);
  63. $regs[$idx] = stripslashes($value);
  64. }
  65. $this->cpu = $regs[1];
  66. $this->os = $regs[2];
  67. }
  68. }
  69. /* }}} */
  70. /* Net_DNS_RR_HINFO::rdatastr() {{{ */
  71. function rdatastr()
  72. {
  73. if ($this->text) {
  74. return '"' . addslashes($this->cpu) . '" "' . addslashes($this->os) . '"';
  75. } else return '; no data';
  76. }
  77. /* }}} */
  78. /* Net_DNS_RR_HINFO::rr_rdata($packet, $offset) {{{ */
  79. function rr_rdata($packet, $offset)
  80. {
  81. if ($this->text) {
  82. $rdata = pack('C', strlen($this->cpu)) . $this->cpu;
  83. $rdata .= pack('C', strlen($this->os)) . $this->os;
  84. return $rdata;
  85. }
  86. return null;
  87. }
  88. /* }}} */
  89. }
  90. /* }}} */
  91. /* VIM settings {{{
  92. * Local variables:
  93. * tab-width: 4
  94. * c-basic-offset: 4
  95. * soft-stop-width: 4
  96. * c indent on
  97. * End:
  98. * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  99. * vim<600: sw=4 ts=4
  100. * }}} */
  101. ?>