PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/blekkzor/pinetd2
PHP | 132 lines | 115 code | 13 blank | 4 comment | 9 complexity | ea32ab8608c5bac62d88367091c3c64f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // http://en.wikipedia.org/wiki/List_of_DNS_record_types
  3. // http://www.dns.net/dnsrd/rfc/
  4. // http://www.faqs.org/rfcs/rfc1035.html
  5. namespace Daemon\DNSd;
  6. class Type {
  7. private static $dns_type = array(
  8. 1 => 'A', // RFC 1035: Host address
  9. 2 => 'NS', // RFC 1035: Authoritative Name Server
  10. 5 => 'CNAME', // RFC 1035: Canonical Name for an alias
  11. 6 => 'SOA', // RFC 1035: Start Of Authority
  12. 12 => 'PTR', // RFC 1035: A domain name pointer
  13. 15 => 'MX', // RFC 1035: Mail eXchange
  14. 16 => 'TXT', // RFC 1035: Text strings
  15. 18 => 'AFSDB', // RFC 1183: AFS database record
  16. 24 => 'SIG', // RFC 2535: Sig(0). See RFC 2931. Deprecated by RFC 3755
  17. 25 => 'KEY', // RFC 2535: Key record, see RFC 2930.
  18. 28 => 'AAAA', // RFC 3596: IPv6 address record
  19. 29 => 'LOC', // RFC 1876: Geographical location
  20. 33 => 'SRV', // RFC 2782: Service locator
  21. 35 => 'NAPTR', // RFC 3403: Naming Authority Pointer
  22. 37 => 'CERT', // RFC 4398
  23. 39 => 'DNAME', // RFC 2672
  24. 41 => 'OPT', // RFC 2671
  25. 43 => 'DS', // RFC 3658: Delegation Signer
  26. 44 => 'SSHFP', // RFC 4255: SSH Public Key Fingerprint
  27. 45 => 'IPSECKEY', // RFC 4025
  28. 46 => 'RRSIG', // RFC 3755
  29. 47 => 'NSEC', // RFC 3755
  30. 48 => 'DNSKEY', // RFC 3755
  31. 49 => 'DHCID', // RFC 4701
  32. 50 => 'NSEC3', // RFC 5155
  33. 51 => 'NSEC3PARAM', // RFC 5155
  34. 55 => 'HIP', // RFC 5205: Host Identity Protocol
  35. 99 => 'SPF', // RFC 4408: SPF Record
  36. 249 => 'TKEY', // RFC 2930
  37. 250 => 'TSIG', // RFC 2845
  38. 251 => 'IXFR', // RFC 1995: Incremental Zone Transfer
  39. 252 => 'AXFR', // RFC 1035: Transfer of an entire zone
  40. 255 => 'ANY', // RFC 1035: Request for all records
  41. 32768 => 'TA', // DNSSEC Trust Authorities
  42. 32769 => 'DLV', // RFC 4431: DNSSEC Lookaside Validation Record
  43. );
  44. private static $dns_type_rev = NULL;
  45. private static $dns_type_rfc = array(
  46. 1 => 1035, // RFC 1035: Host address
  47. 2 => 1035, // RFC 1035: Authoritative Name Server
  48. 5 => 1035, // RFC 1035: Canonical Name for an alias
  49. 6 => 1035, // RFC 1035: Start Of Authority
  50. 12 => 1035, // RFC 1035: A domain name pointer
  51. 15 => 1035, // RFC 1035: Mail eXchange
  52. 16 => 1035, // RFC 1035: Text strings
  53. 18 => 1183, // RFC 1183: AFS database record
  54. 24 => 2535, // RFC 2535: Sig(0). See RFC 2931. Deprecated by RFC 3755
  55. 25 => 2535, // RFC 2535: Key record, see RFC 2930.
  56. 28 => 3596, // RFC 3596: IPv6 address record
  57. 29 => 1876, // RFC 1876: Geographical location
  58. 33 => 2782, // RFC 2782: Service locator
  59. 35 => 3403, // RFC 3403: Naming Authority Pointer
  60. 37 => 4398, // RFC 4398
  61. 39 => 2672, // RFC 2672
  62. 41 => 2671, // RFC 2671: OPT (EDNS0) extended bits, used for DNSSEC
  63. 43 => 3658, // RFC 3658: Delegation Signer
  64. 44 => 4255, // RFC 4255: SSH Public Key Fingerprint
  65. 45 => 4025, // RFC 4025
  66. 46 => 3755, // RFC 3755
  67. 47 => 3755, // RFC 3755
  68. 48 => 3755, // RFC 3755
  69. 49 => 4701, // RFC 4701
  70. 50 => 5155, // RFC 5155
  71. 51 => 5155, // RFC 5155
  72. 55 => 5205, // RFC 5205: Host Identity Protocol
  73. 99 => 4408, // RFC 4408: SPF Record
  74. 249 => 2930, // RFC 2930
  75. 250 => 2845, // RFC 2845
  76. 251 => 1995, // RFC 1995: Incremental Zone Transfer
  77. 252 => 1035, // RFC 1035: Transfer of an entire zone
  78. 255 => 1035, // RFC 1035: Request for any kind of record
  79. // 32768 => 'TA', // DNSSEC Trust Authorities
  80. 32769 => 4431, // RFC 4431: DNSSEC Lookaside Validation Record
  81. );
  82. private $dns_class = array(
  83. 1 => 'IN', // Teh Internet
  84. 2 => 'CS', // The CSNET class (obsolete, used only for examples in some obsolete RFCs)
  85. 3 => 'CH', // The CHAOS class
  86. 4 => 'HS', // Hesiod [Dyer 87]
  87. 255 => 'ANY', // Any class
  88. );
  89. public static function typeToString($type) {
  90. if (!isset(self::$dns_type[$type])) return null;
  91. return self::$dns_type[$type];
  92. }
  93. public static function stringToType($typestr) {
  94. if (is_null(self::$dns_type_rev)) self::$dns_type_rev = array_flip(self::$dns_type);
  95. if (!isset(self::$dns_type_rev[$typestr])) return NULL;
  96. return self::$dns_type_rev[$typestr];
  97. }
  98. public static function factory($pkt, $type) {
  99. if (!isset(self::$dns_type_rfc[$type])) return NULL; // ?!
  100. $class = 'Daemon\\DNSd\\Type\\RFC'.self::$dns_type_rfc[$type];
  101. $obj = new $class($pkt, $type);
  102. return $obj;
  103. }
  104. public static function decode($pkt, $context, $type, $data) {
  105. if (is_object($data)) return $data;
  106. if (!isset(self::$dns_type_rfc[$type])) return NULL; // ?!
  107. $class = 'Daemon\\DNSd\\Type\\RFC'.self::$dns_type_rfc[$type];
  108. $obj = new $class($pkt, $type);
  109. if (is_null($obj->decode($data, $context))) return NULL;
  110. return $obj;
  111. }
  112. public static function encode($pkt, $type, $data) {
  113. if (is_object($data)) return $data->encode();
  114. if (!isset(self::$dns_type_rfc[$type])) return NULL; // ?!
  115. $class = 'Daemon\\DNSd\\Type\\RFC'.self::$dns_type_rfc[$type];
  116. $obj = new $class($pkt, $type);
  117. return $obj->encode($data);
  118. }
  119. }