--- /dev/null
+<?php\r
+/**\r
+* Class to provide IPv4 calculations\r
+*\r
+* Module written/ported by Eric Kilfoil <eric@ypass.net>\r
+*\r
+* This is the copyright notice from the PERL Net::DNS module:\r
+*\r
+* Copyright (c) 1997-2000 Michael Fuhr. All rights reserved. This\r
+* program is free software; you can redistribute it and/or modify it\r
+* under the same terms as Perl itself.\r
+*\r
+* The majority of this is _NOT_ my code. I simply ported it from the\r
+* PERL Net::DNS module.\r
+*\r
+* The author of the Net::DNS module is Michael Fuhr <mike@fuhr.org>\r
+* http://www.fuhr.org/~mfuhr/perldns/\r
+*\r
+* Michael Fuhr has nothing to with the porting of this code to PHP.\r
+* Any questions directly related to this class library should be directed\r
+* to the maintainer.\r
+*\r
+*\r
+* PHP versions 4 and 5\r
+*\r
+* LICENSE: This source file is subject to version 3.01 of the PHP license\r
+* that is available through the world-wide-web at the following URI:\r
+* http://www.php.net/license/3_01.txt. If you did not receive a copy of\r
+* the PHP License and are unable to obtain it through the web, please\r
+* send a note to license@php.net so we can mail you a copy immediately.\r
+*\r
+* @category Net\r
+* @package Net_IPv4\r
+* @author Eric Kilfoil <edk@ypass.net>\r
+* @author Marco Kaiser <bate@php.net>\r
+* @author Florian Anderiasch <fa@php.net>\r
+* @copyright 1997-2005 The PHP Group\r
+* @license http://www.php.net/license/3_01.txt PHP License 3.01\r
+* @version CVS: $Id: DNS.php,v 1.14 2006/10/25 17:52:44 bate Exp $\r
+* @link http://pear.php.net/package/Net_DNS\r
+*/\r
+\r
+/* Include information {{{ */\r
+\r
+ require_once("Net/DNS/Header.php");\r
+ require_once("Net/DNS/Question.php");\r
+ require_once("Net/DNS/Packet.php");\r
+ require_once("Net/DNS/Resolver.php");\r
+ require_once("Net/DNS/RR.php");\r
+\r
+/* }}} */\r
+/* GLOBAL VARIABLE definitions {{{ */\r
+\r
+// Used by the Net_DNS_Resolver object to generate an ID\r
+\r
+$GLOBALS['_Net_DNS_packet_id'] = mt_rand(0, 65535);\r
+\r
+/* }}} */\r
+/* Net_DNS object definition (incomplete) {{{ */\r
+/**\r
+ * Initializes a resolver object\r
+ *\r
+ * Net_DNS allows you to query a nameserver for DNS lookups. It bypasses the\r
+ * system resolver library entirely, which allows you to query any nameserver,\r
+ * set your own values for retries, timeouts, recursion, etc.\r
+ *\r
+ * @author Eric Kilfoil <eric@ypass.net>\r
+ * @package Net_DNS\r
+ * @version 0.01alpha\r
+ */\r
+class Net_DNS\r
+{\r
+ /* class variable definitions {{{ */\r
+ /**\r
+ * A default resolver object created on instantiation\r
+ *\r
+ * @var Net_DNS_Resolver object\r
+ */\r
+ var $resolver;\r
+ var $VERSION = '1.00b2'; // This should probably be a define :(\r
+ var $PACKETSZ = 512;\r
+ var $HFIXEDSZ = 12;\r
+ var $QFIXEDSZ = 4;\r
+ var $RRFIXEDSZ = 10;\r
+ var $INT32SZ = 4;\r
+ var $INT16SZ = 2;\r
+ /* }}} */\r
+ /* class constructor - Net_DNS() {{{ */\r
+\r
+ /**\r
+ * Initializes a resolver object\r
+ *\r
+ * @see Net_DNS_Resolver\r
+ * @param array $defaults\r
+ * @return Net_DNS\r
+ */\r
+ function Net_DNS($defaults = array())\r
+ {\r
+ $this->resolver = new Net_DNS_Resolver($defaults);\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS::opcodesbyname() {{{ */\r
+ /**\r
+ * Translates opcode names to integers\r
+ *\r
+ * Translates the name of a DNS OPCODE into it's assigned number\r
+ * listed in RFC1035, RFC1996, or RFC2136. Valid OPCODES are:\r
+ * <ul>\r
+ * <li>QUERY\r
+ * <li>IQUERY\r
+ * <li>STATUS\r
+ * <li>NS_NOTIFY_OP\r
+ * <li>UPDATE\r
+ * <ul>\r
+ *\r
+ * @param string $opcode A DNS Packet OPCODE name\r
+ * @return integer The integer value of an OPCODE\r
+ * @see Net_DNS::opcodesbyval()\r
+ */\r
+ function opcodesbyname($opcode)\r
+ {\r
+ $op = array(\r
+ 'QUERY' => 0, // RFC 1035\r
+ 'IQUERY' => 1, // RFC 1035\r
+ 'STATUS' => 2, // RFC 1035\r
+ 'NS_NOTIFY_OP' => 4, // RFC 1996\r
+ 'UPDATE' => 5, // RFC 2136\r
+ );\r
+ if (! strlen($op[$opcode])) {\r
+ $op[$opcode] = null;\r
+ }\r
+ return $op[$opcode];\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS::opcodesbyval() {{{*/\r
+ /**\r
+ * Translates opcode integers into names\r
+ *\r
+ * Translates the integer value of an opcode into it's name\r
+ *\r
+ * @param integer $opcodeval A DNS packet opcode integer\r
+ * @return string The name of the OPCODE\r
+ * @see Net_DNS::opcodesbyname()\r
+ */\r
+ function opcodesbyval($opcodeval)\r
+ {\r
+ $opval = array(\r
+ 0 => 'QUERY',\r
+ 1 => 'IQUERY',\r
+ 2 => 'STATUS',\r
+ 4 => 'NS_NOTIFY_OP',\r
+ 5 => 'UPDATE',\r
+ );\r
+ if (! strlen($opval[$opcodeval])) {\r
+ $opval[$opcodeval] = null;\r
+ }\r
+ return $opval[$opcodeval];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS::rcodesbyname() {{{*/\r
+ /**\r
+ * Translates rcode names to integers\r
+ *\r
+ * Translates the name of a DNS RCODE (result code) into it's assigned number.\r
+ * <ul>\r
+ * <li>NOERROR\r
+ * <li>FORMERR\r
+ * <li>SERVFAIL\r
+ * <li>NXDOMAIN\r
+ * <li>NOTIMP\r
+ * <li>REFUSED\r
+ * <li>YXDOMAIN\r
+ * <li>YXRRSET\r
+ * <li>NXRRSET\r
+ * <li>NOTAUTH\r
+ * <li>NOTZONE\r
+ * <ul>\r
+ *\r
+ * @param string $rcode A DNS Packet RCODE name\r
+ * @return integer The integer value of an RCODE\r
+ * @see Net_DNS::rcodesbyval()\r
+ */\r
+ function rcodesbyname($rcode)\r
+ {\r
+ $rc = array(\r
+ 'NOERROR' => 0, // RFC 1035\r
+ 'FORMERR' => 1, // RFC 1035\r
+ 'SERVFAIL' => 2, // RFC 1035\r
+ 'NXDOMAIN' => 3, // RFC 1035\r
+ 'NOTIMP' => 4, // RFC 1035\r
+ 'REFUSED' => 5, // RFC 1035\r
+ 'YXDOMAIN' => 6, // RFC 2136\r
+ 'YXRRSET' => 7, // RFC 2136\r
+ 'NXRRSET' => 8, // RFC 2136\r
+ 'NOTAUTH' => 9, // RFC 2136\r
+ 'NOTZONE' => 10, // RFC 2136\r
+ );\r
+ if (! strlen($rc[$rcode])) {\r
+ $rc[$rcode] = null;\r
+ }\r
+ return $rc[$rcode];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS::rcodesbyval() {{{*/\r
+ /**\r
+ * Translates rcode integers into names\r
+ *\r
+ * Translates the integer value of an rcode into it's name\r
+ *\r
+ * @param integer $rcodeval A DNS packet rcode integer\r
+ * @return string The name of the RCODE\r
+ * @see Net_DNS::rcodesbyname()\r
+ */\r
+ function rcodesbyval($rcodeval)\r
+ {\r
+ $rc = array(\r
+ 0 => 'NOERROR',\r
+ 1 => 'FORMERR',\r
+ 2 => 'SERVFAIL',\r
+ 3 => 'NXDOMAIN',\r
+ 4 => 'NOTIMP',\r
+ 5 => 'REFUSED',\r
+ 6 => 'YXDOMAIN',\r
+ 7 => 'YXRRSET',\r
+ 8 => 'NXRRSET',\r
+ 9 => 'NOTAUTH',\r
+ 10 => 'NOTZONE',\r
+ );\r
+ if (! strlen($rc[$rcodeval])) {\r
+ $rc[$rcodeval] = null;\r
+ }\r
+ return $rc[$rcodeval];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS::typesbyname() {{{*/\r
+ /**\r
+ * Translates RR type names into integers\r
+ *\r
+ * Translates a Resource Record from it's name to it's integer value.\r
+ * Valid resource record types are:\r
+ *\r
+ * <ul>\r
+ * <li>A\r
+ * <li>NS\r
+ * <li>MD\r
+ * <li>MF\r
+ * <li>CNAME\r
+ * <li>SOA\r
+ * <li>MB\r
+ * <li>MG\r
+ * <li>MR\r
+ * <li>NULL\r
+ * <li>WKS\r
+ * <li>PTR\r
+ * <li>HINFO\r
+ * <li>MINFO\r
+ * <li>MX\r
+ * <li>TXT\r
+ * <li>RP\r
+ * <li>AFSDB\r
+ * <li>X25\r
+ * <li>ISDN\r
+ * <li>RT\r
+ * <li>NSAP\r
+ * <li>NSAP_PTR\r
+ * <li>SIG\r
+ * <li>KEY\r
+ * <li>PX\r
+ * <li>GPOS\r
+ * <li>AAAA\r
+ * <li>LOC\r
+ * <li>NXT\r
+ * <li>EID\r
+ * <li>NIMLOC\r
+ * <li>SRV\r
+ * <li>ATMA\r
+ * <li>NAPTR\r
+ * <li>TSIG\r
+ * <li>UINFO\r
+ * <li>UID\r
+ * <li>GID\r
+ * <li>UNSPEC\r
+ * <li>IXFR\r
+ * <li>AXFR\r
+ * <li>MAILB\r
+ * <li>MAILA\r
+ * <li>ANY\r
+ * <ul>\r
+ *\r
+ * @param string $rrtype A DNS packet RR type name\r
+ * @return integer The integer value of an RR type\r
+ * @see Net_DNS::typesbyval()\r
+ */\r
+ function typesbyname($rrtype)\r
+ {\r
+ $rc = array(\r
+ 'A' => 1,\r
+ 'NS' => 2,\r
+ 'MD' => 3,\r
+ 'MF' => 4,\r
+ 'CNAME' => 5,\r
+ 'SOA' => 6,\r
+ 'MB' => 7,\r
+ 'MG' => 8,\r
+ 'MR' => 9,\r
+ 'NULL' => 10,\r
+ 'WKS' => 11,\r
+ 'PTR' => 12,\r
+ 'HINFO' => 13,\r
+ 'MINFO' => 14,\r
+ 'MX' => 15,\r
+ 'TXT' => 16,\r
+ 'RP' => 17,\r
+ 'AFSDB' => 18,\r
+ 'X25' => 19,\r
+ 'ISDN' => 20,\r
+ 'RT' => 21,\r
+ 'NSAP' => 22,\r
+ 'NSAP_PTR' => 23,\r
+ 'SIG' => 24,\r
+ 'KEY' => 25,\r
+ 'PX' => 26,\r
+ 'GPOS' => 27,\r
+ 'AAAA' => 28,\r
+ 'LOC' => 29,\r
+ 'NXT' => 30,\r
+ 'EID' => 31,\r
+ 'NIMLOC' => 32,\r
+ 'SRV' => 33,\r
+ 'ATMA' => 34,\r
+ 'NAPTR' => 35,\r
+ 'UINFO' => 100,\r
+ 'UID' => 101,\r
+ 'GID' => 102,\r
+ 'UNSPEC' => 103,\r
+ 'TSIG' => 250,\r
+ 'IXFR' => 251,\r
+ 'AXFR' => 252,\r
+ 'MAILB' => 253,\r
+ 'MAILA' => 254,\r
+ 'ANY' => 255,\r
+ );\r
+ if (empty($rc[$rrtype])) {\r
+ $rc[$rrtype] = null;\r
+ }\r
+ return $rc[$rrtype];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS::typesbyval() {{{*/\r
+ /**\r
+ * Translates RR type integers into names\r
+ *\r
+ * Translates the integer value of an RR type into it's name\r
+ *\r
+ * @param integer $rrtypeval A DNS packet RR type integer\r
+ * @return string The name of the RR type\r
+ * @see Net_DNS::typesbyname()\r
+ */\r
+ function typesbyval($rrtypeval)\r
+ {\r
+ $rc = array(\r
+ 1 => 'A',\r
+ 2 => 'NS',\r
+ 3 => 'MD',\r
+ 4 => 'MF',\r
+ 5 => 'CNAME',\r
+ 6 => 'SOA',\r
+ 7 => 'MB',\r
+ 8 => 'MG',\r
+ 9 => 'MR',\r
+ 10 => 'NULL',\r
+ 11 => 'WKS',\r
+ 12 => 'PTR',\r
+ 13 => 'HINFO',\r
+ 14 => 'MINFO',\r
+ 15 => 'MX',\r
+ 16 => 'TXT',\r
+ 17 => 'RP',\r
+ 18 => 'AFSDB',\r
+ 19 => 'X25',\r
+ 20 => 'ISDN',\r
+ 21 => 'RT',\r
+ 22 => 'NSAP',\r
+ 23 => 'NSAP_PTR',\r
+ 24 => 'SIG',\r
+ 25 => 'KEY',\r
+ 26 => 'PX',\r
+ 27 => 'GPOS',\r
+ 28 => 'AAAA',\r
+ 29 => 'LOC',\r
+ 30 => 'NXT',\r
+ 31 => 'EID',\r
+ 32 => 'NIMLOC',\r
+ 33 => 'SRV',\r
+ 34 => 'ATMA',\r
+ 35 => 'NAPTR',\r
+ 100 => 'UINFO',\r
+ 101 => 'UID',\r
+ 102 => 'GID',\r
+ 103 => 'UNSPEC',\r
+ 250 => 'TSIG',\r
+ 251 => 'IXFR',\r
+ 252 => 'AXFR',\r
+ 253 => 'MAILB',\r
+ 254 => 'MAILA',\r
+ 255 => 'ANY',\r
+ );\r
+ $rrtypeval = preg_replace(array('/\s*/',' /^0*/'), '', $rrtypeval);\r
+ if (empty($rc[$rrtypeval])) {\r
+ $rc[$rrtypeval] = null;\r
+ }\r
+ return $rc[$rrtypeval];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS::classesbyname() {{{*/\r
+ /**\r
+ * translates a DNS class from it's name to it's integer value. Valid\r
+ * class names are:\r
+ * <ul>\r
+ * <li>IN\r
+ * <li>CH\r
+ * <li>HS\r
+ * <li>NONE\r
+ * <li>ANY\r
+ * </ul>\r
+ *\r
+ * @param string $class A DNS packet class type\r
+ * @return integer The integer value of an class type\r
+ * @see Net_DNS::classesbyval()\r
+ */\r
+ function classesbyname($class)\r
+ {\r
+ $rc = array(\r
+ 'IN' => 1, // RFC 1035\r
+ 'CH' => 3, // RFC 1035\r
+ 'HS' => 4, // RFC 1035\r
+ 'NONE' => 254, // RFC 2136\r
+ 'ANY' => 255 // RFC 1035\r
+ );\r
+ if (!isset($rc[$class])) {\r
+ $rc[$class] = null;\r
+ }\r
+ return $rc[$class];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS::classesbyval() {{{*/\r
+ /**\r
+ * Translates RR class integers into names\r
+ *\r
+ * Translates the integer value of an RR class into it's name\r
+ *\r
+ * @param integer $classval A DNS packet RR class integer\r
+ * @return string The name of the RR class\r
+ * @see Net_DNS::classesbyname()\r
+ */\r
+ function classesbyval($classval)\r
+ {\r
+ $rc = array(\r
+ 1 => 'IN',\r
+ 3 => 'CH',\r
+ 4 => 'HS',\r
+ 254 => 'NONE',\r
+ 255 => 'ANY'\r
+ );\r
+ $classval = preg_replace(array('/\s*/',' /^0*/'), '', $classval);\r
+ if (empty($rc[$classval])) {\r
+ $rc[$classval] = null;\r
+ }\r
+ return $rc[$classval];\r
+ }\r
+\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::mx() {{{*/\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::yxrrset() {{{*/\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::nxrrset() {{{*/\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::yxdomain() {{{*/\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::nxdomain() {{{*/\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::rr_add() {{{*/\r
+ /*}}}*/\r
+ /* not completed - Net_DNS::rr_del() {{{*/\r
+ /*}}}*/\r
+}\r
+/* }}} */\r
+/* VIM Settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>\r
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_Header object definition {{{ */\r
+/**\r
+ * Object representation of the HEADER section of a DNS packet\r
+ *\r
+ * The Net_DNS::Header class contains the values of a DNS packet. It parses\r
+ * the header of a DNS packet or can generate the binary data\r
+ * representation of the packet. The format of the header is described in\r
+ * RFC1035.\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_Header\r
+{\r
+ /* class variable definitions {{{ */\r
+ /**\r
+ * The packet's request id\r
+ *\r
+ * The request id of the packet represented as a 16 bit integer.\r
+ */\r
+ var $id;\r
+ /**\r
+ * The QR bit in a DNS packet header\r
+ *\r
+ * The QR bit as described in RFC1035. QR is set to 0 for queries, and\r
+ * 1 for repsones.\r
+ */\r
+ var $qr;\r
+ /**\r
+ * The OPCODE name of this packet.\r
+ *\r
+ * The string value (name) of the opcode for the DNS packet.\r
+ */\r
+ var $opcode;\r
+ /**\r
+ * The AA (authoritative answer) bit in a DNS packet header\r
+ *\r
+ * The AA bit as described in RFC1035. AA is set to 1 if the answer\r
+ * is authoritative. It has no meaning if QR is set to 0.\r
+ */\r
+ var $aa;\r
+ /**\r
+ * The TC (truncated) bit in a DNS packet header\r
+ *\r
+ * This flag is set to 1 if the response was truncated. This flag has\r
+ * no meaning in a query packet.\r
+ */\r
+ var $tc;\r
+ /**\r
+ * The RD (recursion desired) bit in a DNS packet header\r
+ *\r
+ * This bit should be set to 1 in a query if recursion is desired by\r
+ * the DNS server.\r
+ */\r
+ var $rd;\r
+ /**\r
+ * The RA (recursion available) bit in a DNS packet header\r
+ *\r
+ * This bit is set to 1 by the DNS server if the server is willing to\r
+ * perform recursion.\r
+ */\r
+ var $ra;\r
+ /**\r
+ * The RCODE name for this packet.\r
+ *\r
+ * The string value (name) of the rcode for the DNS packet.\r
+ */\r
+ var $rcode;\r
+ /**\r
+ * Number of questions contained within the packet\r
+ *\r
+ * 16bit integer representing the number of questions in the question\r
+ * section of the DNS packet.\r
+ *\r
+ * @var integer $qdcount\r
+ * @see Net_DNS_Question class\r
+ */\r
+ var $qdcount;\r
+ /**\r
+ * Number of answer RRs contained within the packet\r
+ *\r
+ * 16bit integer representing the number of answer resource records\r
+ * contained in the answer section of the DNS packet.\r
+ *\r
+ * @var integer $ancount\r
+ * @see Net_DNS_RR class\r
+ */\r
+ var $ancount;\r
+ /**\r
+ * Number of authority RRs within the packet\r
+ *\r
+ * 16bit integer representing the number of authority (NS) resource\r
+ * records contained in the authority section of the DNS packet.\r
+ *\r
+ * @var integer $nscount\r
+ * @see Net_DNS_RR class\r
+ */\r
+ var $nscount;\r
+ /**\r
+ * Number of additional RRs within the packet\r
+ *\r
+ * 16bit integer representing the number of additional resource records\r
+ * contained in the additional section of the DNS packet.\r
+ *\r
+ * @var integer $arcount\r
+ * @see Net_DNS_RR class\r
+ */\r
+ var $arcount;\r
+\r
+ /* }}} */\r
+ /* class constructor - Net_DNS_Header($data = "") {{{ */\r
+ /**\r
+ * Initializes the default values for the Header object.\r
+ * \r
+ * Builds a header object from either default values, or from a DNS\r
+ * packet passed into the constructor as $data\r
+ *\r
+ * @param string $data A DNS packet of which the header will be parsed.\r
+ * @return object Net_DNS_Header\r
+ * @access public\r
+ */\r
+ function Net_DNS_Header($data = '')\r
+ {\r
+ if ($data != '') {\r
+ /*\r
+ * The header MUST be at least 12 bytes.\r
+ * Passing the full datagram to this constructor\r
+ * will examine only the header section of the DNS packet\r
+ */\r
+ if (strlen($data) < 12)\r
+ return false;\r
+\r
+ $a = unpack('nid/C2flags/n4counts', $data);\r
+ $this->id = $a['id'];\r
+ $this->qr = ($a['flags1'] >> 7) & 0x1;\r
+ $this->opcode = ($a['flags1'] >> 3) & 0xf;\r
+ $this->aa = ($a['flags1'] >> 2) & 0x1;\r
+ $this->tc = ($a['flags1'] >> 1) & 0x1;\r
+ $this->rd = $a['flags1'] & 0x1;\r
+ $this->ra = ($a['flags2'] >> 7) & 0x1;\r
+ $this->rcode = $a['flags2'] & 0xf;\r
+ $this->qdcount = $a['counts1'];\r
+ $this->ancount = $a['counts2'];\r
+ $this->nscount = $a['counts3'];\r
+ $this->arcount = $a['counts4'];\r
+ }\r
+ else {\r
+ $this->id = Net_DNS_Resolver::nextid();\r
+ $this->qr = 0;\r
+ $this->opcode = 0;\r
+ $this->aa = 0;\r
+ $this->tc = 0;\r
+ $this->rd = 1;\r
+ $this->ra = 0;\r
+ $this->rcode = 0;\r
+ $this->qdcount = 1;\r
+ $this->ancount = 0;\r
+ $this->nscount = 0;\r
+ $this->arcount = 0;\r
+ }\r
+\r
+ if (Net_DNS::opcodesbyval($this->opcode)) {\r
+ $this->opcode = Net_DNS::opcodesbyval($this->opcode);\r
+ }\r
+ if (Net_DNS::rcodesbyval($this->rcode)) {\r
+ $this->rcode = Net_DNS::rcodesbyval($this->rcode);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Header::display() {{{ */\r
+ /**\r
+ * Displays the properties of the header.\r
+ *\r
+ * Displays the properties of the header.\r
+ *\r
+ * @access public\r
+ */\r
+ function display()\r
+ {\r
+ echo $this->string();\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Header::string() {{{ */\r
+ /**\r
+ * Returns a formatted string containing the properties of the header.\r
+ *\r
+ * @return string a formatted string containing the properties of the header.\r
+ * @access public\r
+ */\r
+ function string()\r
+ {\r
+ $retval = ';; id = ' . $this->id . "\n";\r
+ if ($this->opcode == 'UPDATE') {\r
+ $retval .= ';; qr = ' . $this->qr . ' ' .\r
+ 'opcode = ' . $this->opcode . ' ' .\r
+ 'rcode = ' . $this->rcode . "\n";\r
+ $retval .= ';; zocount = ' . $this->qdcount . ' ' . \r
+ 'prcount = ' . $this->ancount . ' ' .\r
+ 'upcount = ' . $this->nscount . ' ' .\r
+ 'adcount = ' . $this->arcount . "\n";\r
+ } else {\r
+ $retval .= ';; qr = ' . $this->qr . ' ' .\r
+ 'opcode = ' . $this->opcode . ' ' .\r
+ 'aa = ' . $this->aa . ' ' .\r
+ 'tc = ' . $this->tc . ' ' .\r
+ 'rd = ' . $this->rd . "\n";\r
+\r
+ $retval .= ';; ra = ' . $this->ra . ' ' .\r
+ 'rcode = ' . $this->rcode . "\n";\r
+\r
+ $retval .= ';; qdcount = ' . $this->qdcount . ' ' .\r
+ 'ancount = ' . $this->ancount . ' ' .\r
+ 'nscount = ' . $this->nscount . ' ' .\r
+ 'arcount = ' . $this->arcount . "\n";\r
+ }\r
+ return $retval;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Header::data() {{{ */\r
+ /**\r
+ * Returns the binary data containing the properties of the header\r
+ *\r
+ * Packs the properties of the Header object into a binary string\r
+ * suitable for using as the Header section of a DNS packet.\r
+ *\r
+ * @return string binary representation of the header object\r
+ * @access public\r
+ */\r
+ function data()\r
+ {\r
+ $opcode = Net_DNS::opcodesbyname($this->opcode);\r
+ $rcode = Net_DNS::rcodesbyname($this->rcode);\r
+\r
+ $byte2 = ($this->qr << 7)\r
+ | ($opcode << 3)\r
+ | ($this->aa << 2)\r
+ | ($this->tc << 1)\r
+ | ($this->rd);\r
+\r
+ $byte3 = ($this->ra << 7) | $rcode;\r
+\r
+ return pack('nC2n4', $this->id,\r
+ $byte2,\r
+ $byte3,\r
+ $this->qdcount,\r
+ $this->ancount,\r
+ $this->nscount,\r
+ $this->arcount);\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * expandtab on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_Packet object definition {{{ */\r
+/**\r
+ * A object represation of a DNS packet (RFC1035)\r
+ *\r
+ * This object is used to manage a DNS packet. It contains methods for\r
+ * DNS packet compression as defined in RFC1035, as well as parsing a DNS\r
+ * packet response from a DNS server, or building a DNS packet from the\r
+ * instance variables contained in the class.\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_Packet\r
+{\r
+ /* class variable definitions {{{ */\r
+ /**\r
+ * debugging flag\r
+ *\r
+ * If set to true (non-zero), debugging code will be displayed as the\r
+ * packet is parsed.\r
+ *\r
+ * @var boolean $debug\r
+ * @access public\r
+ */\r
+ var $debug;\r
+ /**\r
+ * A packet Header object.\r
+ *\r
+ * An object of type Net_DNS_Header which contains the header\r
+ * information of the packet.\r
+ *\r
+ * @var object Net_DNS_Header $header\r
+ * @access public\r
+ */\r
+ var $header;\r
+ /**\r
+ * A hash of compressed labels\r
+ *\r
+ * A list of all labels which have been compressed in the DNS packet\r
+ * and the location offset of the label within the packet.\r
+ *\r
+ * @var array $compnames\r
+ */\r
+ var $compnames;\r
+ /**\r
+ * The origin of the packet, if the packet is a server response.\r
+ *\r
+ * This contains a string containing the IP address of the name server\r
+ * from which the answer was given.\r
+ *\r
+ * @var string $answerfrom\r
+ * @access public\r
+ */\r
+ var $answerfrom;\r
+ /**\r
+ * The size of the answer packet, if the packet is a server response.\r
+ *\r
+ * This contains a integer containing the size of the DNS packet the\r
+ * server responded with if this packet was received by a DNS server\r
+ * using the query() method.\r
+ *\r
+ * @var string $answersize\r
+ * @access public\r
+ */\r
+ var $answersize;\r
+ /**\r
+ * An array of Net_DNS_Question objects\r
+ *\r
+ * Contains all of the questions within the packet. Each question is\r
+ * stored as an object of type Net_DNS_Question.\r
+ *\r
+ * @var array $question\r
+ * @access public\r
+ */\r
+ var $question;\r
+ /**\r
+ * An array of Net_DNS_RR ANSWER objects\r
+ *\r
+ * Contains all of the answer RRs within the packet. Each answer is\r
+ * stored as an object of type Net_DNS_RR.\r
+ *\r
+ * @var array $answer\r
+ * @access public\r
+ */\r
+ var $answer;\r
+ /**\r
+ * An array of Net_DNS_RR AUTHORITY objects\r
+ *\r
+ * Contains all of the authority RRs within the packet. Each authority is\r
+ * stored as an object of type Net_DNS_RR.\r
+ *\r
+ * @var array $authority\r
+ * @access public\r
+ */\r
+ var $authority;\r
+ /**\r
+ * An array of Net_DNS_RR ADDITIONAL objects\r
+ *\r
+ * Contains all of the additional RRs within the packet. Each additional is\r
+ * stored as an object of type Net_DNS_RR.\r
+ *\r
+ * @var array $additional\r
+ * @access public\r
+ */\r
+ var $additional;\r
+\r
+ /* }}} */\r
+ /* class constructor - Net_DNS_Packet($debug = false) {{{ */\r
+ /*\r
+ * unfortunately (or fortunately), we can't follow the same\r
+ * silly method for determining if name is a hostname or a packet\r
+ * stream in PHP, since there is no ref() function. So we're going\r
+ * to define a new method called parse to deal with this\r
+ * circumstance and another method called buildQuestion to build a question.\r
+ * I like it better that way anyway.\r
+ */\r
+ /**\r
+ * Initalizes a Net_DNS_Packet object\r
+ *\r
+ * @param boolean $debug Turns debugging on or off\r
+ */\r
+ function Net_DNS_Packet($debug = false)\r
+ {\r
+ $this->debug = $debug;\r
+ $this->compnames = array();\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Packet::buildQuestion($name, $type = "A", $class = "IN") {{{ */\r
+ /**\r
+ * Adds a DNS question to the DNS packet\r
+ *\r
+ * @param string $name The name of the record to query\r
+ * @param string $type The type of record to query\r
+ * @param string $class The class of record to query\r
+ * @see Net_DNS::typesbyname(), Net_DNS::classesbyname()\r
+ */\r
+ function buildQuestion($name, $type = 'A', $class = 'IN')\r
+ {\r
+ $this->header = new Net_DNS_Header();\r
+ $this->header->qdcount = 1;\r
+ $this->question[0] = new Net_DNS_Question($name, $type, $class);\r
+ $this->answer = null;\r
+ $this->authority = null;\r
+ $this->additional = null;\r
+ /* Do not print question packet\r
+ if ($this->debug) {\r
+ $this->display();\r
+ }\r
+ */\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Packet::parse($data) {{{ */\r
+ /**\r
+ * Parses a DNS packet returned by a DNS server\r
+ *\r
+ * Parses a complete DNS packet and builds an object hierarchy\r
+ * containing all of the parts of the packet:\r
+ * <ul>\r
+ * <li>HEADER\r
+ * <li>QUESTION\r
+ * <li>ANSWER || PREREQUISITE\r
+ * <li>ADDITIONAL || UPDATE\r
+ * <li>AUTHORITY\r
+ * </ul>\r
+ *\r
+ * @param string $data A binary string containing a DNS packet\r
+ * @return boolean true on success, null on parser error\r
+ */\r
+ function parse($data)\r
+ {\r
+ if ($this->debug) {\r
+ echo ';; HEADER SECTION' . "\n";\r
+ }\r
+\r
+ $this->header = new Net_DNS_Header($data);\r
+\r
+ if ($this->debug) {\r
+ $this->header->display();\r
+ }\r
+\r
+ /*\r
+ * Print and parse the QUESTION section of the packet\r
+ */\r
+ if ($this->debug) {\r
+ echo "\n";\r
+ $section = ($this->header->opcode == 'UPDATE') ? 'ZONE' : 'QUESTION';\r
+ echo ";; $section SECTION (" . $this->header->qdcount . ' record' .\r
+ ($this->header->qdcount == 1 ? '' : 's') . ")\n";\r
+ }\r
+\r
+ $offset = 12;\r
+\r
+ $this->question = array();\r
+ for ($ctr = 0; $ctr < $this->header->qdcount; $ctr++) {\r
+ list($qobj, $offset) = $this->parse_question($data, $offset);\r
+ if (is_null($qobj)) {\r
+ return null;\r
+ }\r
+\r
+ $this->question[count($this->question)] = $qobj;\r
+ if ($this->debug) {\r
+ echo ";;\n;";\r
+ $qobj->display();\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Print and parse the PREREQUISITE or ANSWER section of the packet\r
+ */\r
+ if ($this->debug) {\r
+ echo "\n";\r
+ $section = ($this->header->opcode == 'UPDATE') ? 'PREREQUISITE' :'ANSWER';\r
+ echo ";; $section SECTION (" .\r
+ $this->header->ancount . ' record' .\r
+ (($this->header->ancount == 1) ? '' : 's') .\r
+ ")\n";\r
+ }\r
+\r
+ $this->answer = array();\r
+ for ($ctr = 0; $ctr < $this->header->ancount; $ctr++) {\r
+ list($rrobj, $offset) = $this->parse_rr($data, $offset);\r
+\r
+ if (is_null($rrobj)) {\r
+ return null;\r
+ }\r
+ array_push($this->answer, $rrobj);\r
+ if ($this->debug) {\r
+ $rrobj->display();\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Print and parse the UPDATE or AUTHORITY section of the packet\r
+ */\r
+ if ($this->debug) {\r
+ echo "\n";\r
+ $section = ($this->header->opcode == 'UPDATE') ? 'UPDATE' : 'AUTHORITY';\r
+ echo ";; $section SECTION (" .\r
+ $this->header->nscount . ' record' .\r
+ (($this->header->nscount == 1) ? '' : 's') .\r
+ ")\n";\r
+ }\r
+\r
+ $this->authority = array();\r
+ for ($ctr = 0; $ctr < $this->header->nscount; $ctr++) {\r
+ list($rrobj, $offset) = $this->parse_rr($data, $offset);\r
+\r
+ if (is_null($rrobj)) {\r
+ return null;\r
+ }\r
+ array_push($this->authority, $rrobj);\r
+ if ($this->debug) {\r
+ $rrobj->display();\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Print and parse the ADDITIONAL section of the packet\r
+ */\r
+ if ($this->debug) {\r
+ echo "\n";\r
+ echo ';; ADDITIONAL SECTION (' .\r
+ $this->header->arcount . ' record' .\r
+ (($this->header->arcount == 1) ? '' : 's') .\r
+ ")\n";\r
+ }\r
+\r
+ $this->additional = array();\r
+ for ($ctr = 0; $ctr < $this->header->arcount; $ctr++) {\r
+ list($rrobj, $offset) = $this->parse_rr($data, $offset);\r
+\r
+ if (is_null($rrobj)) {\r
+ return null;\r
+ }\r
+ array_push($this->additional, $rrobj);\r
+ if ($this->debug) {\r
+ $rrobj->display();\r
+ }\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Packet::data() {{{*/\r
+ /**\r
+ * Build a packet from a Packet object hierarchy\r
+ *\r
+ * Builds a valid DNS packet suitable for sending to a DNS server or\r
+ * resolver client containing all of the data in the packet hierarchy.\r
+ *\r
+ * @return string A binary string containing a DNS Packet\r
+ */\r
+ function data()\r
+ {\r
+ $data = $this->header->data();\r
+\r
+ for ($ctr = 0; $ctr < $this->header->qdcount; $ctr++) {\r
+ $data .= $this->question[$ctr]->data($this, strlen($data));\r
+ }\r
+\r
+ for ($ctr = 0; $ctr < $this->header->ancount; $ctr++) {\r
+ $data .= $this->answer[$ctr]->data($this, strlen($data));\r
+ }\r
+\r
+ for ($ctr = 0; $ctr < $this->header->nscount; $ctr++) {\r
+ $data .= $this->authority[$ctr]->data($this, strlen($data));\r
+ }\r
+\r
+ for ($ctr = 0; $ctr < $this->header->arcount; $ctr++) {\r
+ $data .= $this->additional[$ctr]->data($this, strlen($data));\r
+ }\r
+\r
+ return $data;\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Packet::dn_comp($name, $offset) {{{*/\r
+ /**\r
+ * DNS packet compression method\r
+ *\r
+ * Returns a domain name compressed for a particular packet object, to\r
+ * be stored beginning at the given offset within the packet data. The\r
+ * name will be added to a running list of compressed domain names for\r
+ * future use.\r
+ *\r
+ * @param string $name The name of the label to compress\r
+ * @param integer $offset The location offset in the packet to where\r
+ * the label will be stored.\r
+ * @return string $compname A binary string containing the compressed\r
+ * label.\r
+ * @see Net_DNS_Packet::dn_expand()\r
+ */\r
+ function dn_comp($name, $offset)\r
+ {\r
+ $names = explode('.', $name);\r
+ $compname = '';\r
+ while (count($names)) {\r
+ $dname = join('.', $names);\r
+ if (isset($this->compnames[$dname])) {\r
+ $compname .= pack('n', 0xc000 | $this->compnames[$dname]);\r
+ break;\r
+ }\r
+\r
+ $this->compnames[$dname] = $offset;\r
+ $first = array_shift($names);\r
+ $length = strlen($first);\r
+ $compname .= pack('Ca*', $length, $first);\r
+ $offset += $length + 1;\r
+ }\r
+ if (! count($names)) {\r
+ $compname .= pack('C', 0);\r
+ }\r
+ return $compname;\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Packet::dn_expand($packet, $offset) {{{ */\r
+ /**\r
+ * DNS packet decompression method\r
+ *\r
+ * Expands the domain name stored at a particular location in a DNS\r
+ * packet. The first argument is a variable containing the packet\r
+ * data. The second argument is the offset within the packet where\r
+ * the (possibly) compressed domain name is stored.\r
+ *\r
+ * @param string $packet The packet data\r
+ * @param integer $offset The location offset in the packet of the\r
+ * label to decompress.\r
+ * @return array Returns a list of type array($name, $offset) where\r
+ * $name is the name of the label which was decompressed\r
+ * and $offset is the offset of the next field in the\r
+ * packet. Returns array(null, null) on error\r
+ */\r
+ function dn_expand($packet, $offset)\r
+ {\r
+ $packetlen = strlen($packet);\r
+ $int16sz = 2;\r
+ $name = '';\r
+ while (1) {\r
+ if ($packetlen < ($offset + 1)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $a = unpack("@$offset/Cchar", $packet);\r
+ $len = $a['char'];\r
+\r
+ if ($len == 0) {\r
+ $offset++;\r
+ break;\r
+ } else if (($len & 0xc0) == 0xc0) {\r
+ if ($packetlen < ($offset + $int16sz)) {\r
+ return array(null, null);\r
+ }\r
+ $ptr = unpack("@$offset/ni", $packet);\r
+ $ptr = $ptr['i'];\r
+ $ptr = $ptr & 0x3fff;\r
+ $name2 = Net_DNS_Packet::dn_expand($packet, $ptr);\r
+\r
+ if (is_null($name2[0])) {\r
+ return array(null, null);\r
+ }\r
+ $name .= $name2[0];\r
+ $offset += $int16sz;\r
+ break;\r
+ } else {\r
+ $offset++;\r
+\r
+ if ($packetlen < ($offset + $len)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $elem = substr($packet, $offset, $len);\r
+ $name .= $elem . '.';\r
+ $offset += $len;\r
+ }\r
+ }\r
+ $name = ereg_replace('\.$', '', $name);\r
+ return array($name, $offset);\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Packet::label_extract($packet, $offset) {{{ */\r
+ /**\r
+ * DNS packet decompression method\r
+ *\r
+ * Extracts the label stored at a particular location in a DNS\r
+ * packet. The first argument is a variable containing the packet\r
+ * data. The second argument is the offset within the packet where\r
+ * the (possibly) compressed domain name is stored.\r
+ *\r
+ * @param string $packet The packet data\r
+ * @param integer $offset The location offset in the packet of the\r
+ * label to extract.\r
+ * @return array Returns a list of type array($name, $offset) where\r
+ * $name is the name of the label which was decompressed\r
+ * and $offset is the offset of the next field in the\r
+ * packet. Returns array(null, null) on error\r
+ */\r
+ function label_extract($packet, $offset)\r
+ {\r
+ $packetlen = strlen($packet);\r
+ $name = '';\r
+ if ($packetlen < ($offset + 1)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $a = unpack("@$offset/Cchar", $packet);\r
+ $len = $a['char'];\r
+ $offset++;\r
+\r
+ if ($len + $offset > $packetlen) {\r
+ $name = substr($packet, $offset);\r
+ $offset = $packetlen;\r
+ } else {\r
+ $name = substr($packet, $offset, $len);\r
+ $offset += $len;\r
+ }\r
+ return array($name, $offset);\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Packet::parse_question($data, $offset) {{{ */\r
+ /**\r
+ * Parses the question section of a packet\r
+ *\r
+ * Examines a DNS packet at the specified offset and parses the data\r
+ * of the QUESTION section.\r
+ *\r
+ * @param string $data The packet data returned from the server\r
+ * @param integer $offset The location offset of the start of the\r
+ * question section.\r
+ * @return array An array of type array($q, $offset) where $q\r
+ * is a Net_DNS_Question object and $offset is the\r
+ * location of the next section of the packet which\r
+ * needs to be parsed.\r
+ */\r
+ function parse_question($data, $offset)\r
+ {\r
+ list($qname, $offset) = $this->dn_expand($data, $offset);\r
+ if (is_null($qname)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ if (strlen($data) < ($offset + 2 * 2)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $q = unpack("@$offset/n2int", $data);\r
+ $qtype = $q['int1'];\r
+ $qclass = $q['int2'];\r
+ $offset += 2 * 2;\r
+\r
+ $qtype = Net_DNS::typesbyval($qtype);\r
+ $qclass = Net_DNS::classesbyval($qclass);\r
+\r
+ $q = new Net_DNS_Question($qname, $qtype, $qclass);\r
+ return array($q, $offset);\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Packet::parse_rr($data, $offset) {{{ */\r
+ /**\r
+ * Parses a resource record section of a packet\r
+ *\r
+ * Examines a DNS packet at the specified offset and parses the data\r
+ * of a section which contains RRs (ANSWER, AUTHORITY, ADDITIONAL).\r
+ *\r
+ * @param string $data The packet data returned from the server\r
+ * @param integer $offset The location offset of the start of the resource\r
+ * record section.\r
+ * @return array An array of type array($rr, $offset) where $rr\r
+ * is a Net_DNS_RR object and $offset is the\r
+ * location of the next section of the packet which\r
+ * needs to be parsed.\r
+ */\r
+ function parse_rr($data, $offset)\r
+ {\r
+ list($name, $offset) = $this->dn_expand($data, $offset);\r
+ if ($name === null) {\r
+ return array(null, null);\r
+ }\r
+\r
+ if (strlen($data) < ($offset + 10)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $a = unpack("@$offset/n2tc/Nttl/nrdlength", $data);\r
+ $type = $a['tc1'];\r
+ $class = $a['tc2'];\r
+ $ttl = $a['ttl'];\r
+ $rdlength = $a['rdlength'];\r
+\r
+ $type = Net_DNS::typesbyval($type);\r
+ $class = Net_DNS::classesbyval($class);\r
+\r
+ $offset += 10;\r
+ if (strlen($data) < ($offset + $rdlength)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $rrobj = &Net_DNS_RR::factory(array($name,\r
+ $type,\r
+ $class,\r
+ $ttl,\r
+ $rdlength,\r
+ $data,\r
+ $offset));\r
+\r
+ if (is_null($rrobj)) {\r
+ return array(null, null);\r
+ }\r
+\r
+ $offset += $rdlength;\r
+\r
+ return array($rrobj, $offset);\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Packet::display() {{{ */\r
+ /**\r
+ * Prints out the packet in a human readable formatted string\r
+ */\r
+ function display()\r
+ {\r
+ echo $this->string();\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Packet::string() {{{ */\r
+ /**\r
+ * Builds a human readable formatted string representing a packet\r
+ */\r
+ function string()\r
+ {\r
+ $retval = '';\r
+ if ($this->answerfrom) {\r
+ $retval .= ';; Answer received from ' . $this->answerfrom . '(' .\r
+ $this->answersize . " bytes)\n;;\n";\r
+ }\r
+\r
+ $retval .= ";; HEADER SECTION\n";\r
+ $retval .= $this->header->string();\r
+ $retval .= "\n";\r
+\r
+ $section = ($this->header->opcode == 'UPDATE') ? 'ZONE' : 'QUESTION';\r
+ $retval .= ";; $section SECTION (" . $this->header->qdcount .\r
+ ' record' . ($this->header->qdcount == 1 ? '' : 's') .\r
+ ")\n";\r
+\r
+ foreach ($this->question as $qr) {\r
+ $retval .= ';; ' . $qr->string() . "\n";\r
+ }\r
+\r
+ $section = ($this->header->opcode == 'UPDATE') ? 'PREREQUISITE' : 'ANSWER';\r
+ $retval .= "\n;; $section SECTION (" . $this->header->ancount .\r
+ ' record' . ($this->header->ancount == 1 ? '' : 's') .\r
+ ")\n";\r
+\r
+ if (is_array($this->answer)) {\r
+ foreach ($this->answer as $ans) {\r
+ $retval .= ';; ' . $ans->string() . "\n";\r
+ }\r
+ }\r
+\r
+ $section = ($this->header->opcode == 'UPDATE') ? 'UPDATE' : 'AUTHORITY';\r
+ $retval .= "\n;; $section SECTION (" . $this->header->nscount .\r
+ ' record' . ($this->header->nscount == 1 ? '' : 's') .\r
+ ")\n";\r
+\r
+ if (is_array($this->authority)) {\r
+ foreach ($this->authority as $auth) {\r
+ $retval .= ';; ' . $auth->string() . "\n";\r
+ }\r
+ }\r
+\r
+ $retval .= "\n;; ADDITIONAL SECTION (" . $this->header->arcount .\r
+ ' record' . ($this->header->arcount == 1 ? '' : 's') .\r
+ ")\n";\r
+\r
+ if (is_array($this->additional)) {\r
+ foreach ($this->additional as $addl) {\r
+ $retval .= ';; ' . $addl->string() . "\n";\r
+ }\r
+ }\r
+\r
+ $retval .= "\n\n";\r
+ return $retval;\r
+ }\r
+\r
+ /*}}}*/\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_Question object definition {{{ */\r
+/**\r
+ * Builds or parses the QUESTION section of a DNS packet\r
+ *\r
+ * Builds or parses the QUESTION section of a DNS packet\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_Question\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $qname = null;\r
+ var $qtype = null;\r
+ var $qclass = null;\r
+\r
+ /* }}} */\r
+ /* class constructor Net_DNS_Question($qname, $qtype, $qclass) {{{ */\r
+ function Net_DNS_Question($qname, $qtype, $qclass)\r
+ {\r
+ $qtype = !is_null($qtype) ? strtoupper($qtype) : 'ANY';\r
+ $qclass = !is_null($qclass) ? strtoupper($qclass) : 'ANY';\r
+\r
+ // Check if the caller has the type and class reversed.\r
+ // We are not that kind for unknown types.... :-)\r
+ if ( ( is_null(Net_DNS::typesbyname($qtype)) ||\r
+ is_null(Net_DNS::classesbyname($qtype)) )\r
+ && !is_null(Net_DNS::classesbyname($qclass))\r
+ && !is_null(Net_DNS::typesbyname($qclass)))\r
+ {\r
+ list($qtype, $qclass) = array($qclass, $qtype);\r
+ }\r
+ $qname = preg_replace(array('/^\.+/', '/\.+$/'), '', $qname);\r
+ $this->qname = $qname;\r
+ $this->qtype = $qtype;\r
+ $this->qclass = $qclass;\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_Question::display() {{{*/\r
+ function display()\r
+ {\r
+ echo $this->string() . "\n";\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Question::string() {{{*/\r
+ function string()\r
+ {\r
+ return $this->qname . ".\t" . $this->qclass . "\t" . $this->qtype;\r
+ }\r
+\r
+ /*}}}*/\r
+ /* Net_DNS_Question::data(&$packet, $offset) {{{*/\r
+ function data($packet, $offset)\r
+ {\r
+ $data = $packet->dn_comp($this->qname, $offset);\r
+ $data .= pack('n', Net_DNS::typesbyname(strtoupper($this->qtype)));\r
+ $data .= pack('n', Net_DNS::classesbyname(strtoupper($this->qclass)));\r
+ return $data;\r
+ }\r
+\r
+ /*}}}*/\r
+}\r
+/* }}} */\r
+/* VIM settings{{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Include files {{{ */\r
+require_once("Net/DNS/RR/A.php");\r
+require_once("Net/DNS/RR/AAAA.php");\r
+require_once("Net/DNS/RR/NS.php");\r
+require_once("Net/DNS/RR/CNAME.php");\r
+require_once("Net/DNS/RR/PTR.php");\r
+require_once("Net/DNS/RR/SOA.php");\r
+require_once("Net/DNS/RR/MX.php");\r
+require_once("Net/DNS/RR/TSIG.php");\r
+require_once("Net/DNS/RR/TXT.php");\r
+require_once("Net/DNS/RR/HINFO.php");\r
+require_once("Net/DNS/RR/SRV.php");\r
+require_once("Net/DNS/RR/NAPTR.php");\r
+/* }}} */\r
+/* Net_DNS_RR object definition {{{ */\r
+/**\r
+ * Resource Record object definition\r
+ *\r
+ * Builds or parses resource record sections of the DNS packet including\r
+ * the answer, authority, and additional sections of the packet.\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ /* }}} */\r
+\r
+ /*\r
+ * Use Net_DNS_RR::factory() instead\r
+ *\r
+ * @access private\r
+ */\r
+ /* class constructor - Net_DNS_RR($rrdata) {{{ */\r
+ function Net_DNS_RR($rrdata)\r
+ {\r
+ if ($rrdata != 'getRR') { //BC check/warning remove later\r
+ trigger_error("Please use Net_DNS_RR::factory() instead");\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Returns an RR object, use this instead of constructor\r
+ *\r
+ * @param mixed $rr_rdata Options as string, array or data\r
+ * @return object Net_DNS_RR or Net_DNS_RR_<type>\r
+ * @access public\r
+ * @see Net_DNS_RR::new_from_array Net_DNS_RR::new_from_data Net_DNS_RR::new_from_string\r
+ */\r
+ function &factory($rrdata, $update_type = '')\r
+ {\r
+ if (is_string($rrdata)) {\r
+ $rr = &Net_DNS_RR::new_from_string($rrdata, $update_type);\r
+ } elseif (count($rrdata) == 7) {\r
+ list($name, $rrtype, $rrclass, $ttl, $rdlength, $data, $offset) = $rrdata;\r
+ $rr = &Net_DNS_RR::new_from_data($name, $rrtype, $rrclass, $ttl, $rdlength, $data, $offset);\r
+ } else {\r
+ $rr = &Net_DNS_RR::new_from_array($rrdata);\r
+ }\r
+ return $rr;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::new_from_data($name, $ttl, $rrtype, $rrclass, $rdlength, $data, $offset) {{{ */\r
+ function &new_from_data($name, $rrtype, $rrclass, $ttl, $rdlength, $data, $offset)\r
+ {\r
+ $rr = &new Net_DNS_RR('getRR');\r
+ $rr->name = $name;\r
+ $rr->type = $rrtype;\r
+ $rr->class = $rrclass;\r
+ $rr->ttl = $ttl;\r
+ $rr->rdlength = $rdlength;\r
+ $rr->rdata = substr($data, $offset, $rdlength);\r
+ if (class_exists('Net_DNS_RR_' . $rrtype)) {\r
+ $scn = 'Net_DNS_RR_' . $rrtype;\r
+ $rr = new $scn($rr, $data, $offset);\r
+ }\r
+ return $rr;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::new_from_string($rrstring, $update_type = '') {{{ */\r
+ function &new_from_string($rrstring, $update_type = '')\r
+ {\r
+ $rr = &new Net_DNS_RR('getRR');\r
+ $ttl = 0;\r
+ $parts = preg_split('/[\s]+/', $rrstring);\r
+ while (count($parts) > 0) {\r
+ $s = array_shift($parts);\r
+ if (!isset($name)) {\r
+ $name = ereg_replace('\.+$', '', $s);\r
+ } else if (preg_match('/^\d+$/', $s)) {\r
+ $ttl = $s;\r
+ } else if (!isset($rrclass) && ! is_null(Net_DNS::classesbyname(strtoupper($s)))) {\r
+ $rrclass = strtoupper($s);\r
+ $rdata = join(' ', $parts);\r
+ } else if (! is_null(Net_DNS::typesbyname(strtoupper($s)))) {\r
+ $rrtype = strtoupper($s);\r
+ $rdata = join(' ', $parts);\r
+ break;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Do we need to do this?\r
+ */\r
+ $rdata = trim(chop($rdata));\r
+\r
+ if (! strlen($rrtype) && strlen($rrclass) && $rrclass == 'ANY') {\r
+ $rrtype = $rrclass;\r
+ $rrclass = 'IN';\r
+ } else if (! isset($rrclass)) {\r
+ $rrclass = 'IN';\r
+ }\r
+\r
+ if (! strlen($rrtype)) {\r
+ $rrtype = 'ANY';\r
+ }\r
+\r
+ if (strlen($update_type)) {\r
+ $update_type = strtolower($update_type);\r
+ if ($update_type == 'yxrrset') {\r
+ $ttl = 0;\r
+ if (! strlen($rdata)) {\r
+ $rrclass = 'ANY';\r
+ }\r
+ } else if ($update_type == 'nxrrset') {\r
+ $ttl = 0;\r
+ $rrclass = 'NONE';\r
+ $rdata = '';\r
+ } else if ($update_type == 'yxdomain') {\r
+ $ttl = 0;\r
+ $rrclass = 'ANY';\r
+ $rrtype = 'ANY';\r
+ $rdata = '';\r
+ } else if ($update_type == 'nxdomain') {\r
+ $ttl = 0;\r
+ $rrclass = 'NONE';\r
+ $rrtype = 'ANY';\r
+ $rdata = '';\r
+ } else if (preg_match('/^(rr_)?add$/', $update_type)) {\r
+ $update_type = 'add';\r
+ if (! $ttl) {\r
+ $ttl = 86400;\r
+ }\r
+ } else if (preg_match('/^(rr_)?del(ete)?$/', $update_type)) {\r
+ $update_type = 'del';\r
+ $ttl = 0;\r
+ $rrclass = $rdata ? 'NONE' : 'ANY';\r
+ }\r
+ }\r
+\r
+ if (strlen($rrtype)) {\r
+ $rr->name = $name;\r
+ $rr->type = $rrtype;\r
+ $rr->class = $rrclass;\r
+ $rr->ttl = $ttl;\r
+ $rr->rdlength = 0;\r
+ $rr->rdata = '';\r
+\r
+ if (class_exists('Net_DNS_RR_' . $rrtype)) {\r
+ $scn = 'Net_DNS_RR_' . $rrtype;\r
+ return new $scn($rr, $rdata);\r
+ } else {\r
+ return $rr;\r
+ }\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::new_from_array($rrarray) {{{ */\r
+ function &new_from_array($rrarray)\r
+ {\r
+ $rr = &new Net_DNS_RR('getRR');\r
+ foreach ($rrarray as $k => $v) {\r
+ $rr->{strtolower($k)} = $v;\r
+ }\r
+\r
+ if (! strlen($rr->name)) {\r
+ return null;\r
+ }\r
+ if (! strlen($rr->type)){\r
+ return null;\r
+ }\r
+ if (! $rr->ttl) {\r
+ $rr->ttl = 0;\r
+ }\r
+ if (! strlen($rr->class)) {\r
+ $rr->class = 'IN';\r
+ }\r
+ if (strlen($rr->rdata)) {\r
+ $rr->rdlength = strlen($rr->rdata);\r
+ }\r
+ if (class_exists('Net_DNS_RR_' . $rr->rrtype)) {\r
+ $scn = 'Net_DNS_RR_' . $rr->rrtype;\r
+ return new $scn($rr, $rr->rdata);\r
+ } else {\r
+ return $rr;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::display() {{{ */\r
+ function display()\r
+ {\r
+ echo $this->string() . "\n";\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::string() {{{ */\r
+ function string()\r
+ {\r
+ return $this->name . ".\t" . (strlen($this->name) < 16 ? "\t" : '') .\r
+ $this->ttl . "\t" .\r
+ $this->class. "\t" .\r
+ $this->type . "\t" .\r
+ $this->rdatastr();\r
+\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if ($this->rdlength) {\r
+ return '; rdlength = ' . $this->rdlength;\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::rdata() {{{ */\r
+ function rdata(&$packetORrdata, $offset = '')\r
+ {\r
+ if ($offset) {\r
+ return $this->rr_rdata($packetORrdata, $offset);\r
+ } else if (strlen($this->rdata)) {\r
+ return $this->rdata;\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata(&$packet, $offset)\r
+ {\r
+ return (strlen($this->rdata) ? $this->rdata : '');\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_RR::data() {{{ */\r
+ function data(&$packet, $offset)\r
+ {\r
+ $data = $packet->dn_comp($this->name, $offset);\r
+ $data .= pack('n', Net_DNS::typesbyname(strtoupper($this->type)));\r
+ $data .= pack('n', Net_DNS::classesbyname(strtoupper($this->class)));\r
+ $data .= pack('N', $this->ttl);\r
+\r
+ $offset += strlen($data) + 2; // The 2 extra bytes are for rdlength\r
+\r
+ $rdata = $this->rdata($packet, $offset);\r
+ $data .= pack('n', strlen($rdata));\r
+ $data .= $rdata;\r
+\r
+ return $data;\r
+ }\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+\r
+/* Net_DNS_RR_A object definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>A</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_A extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $address;\r
+ /* }}} */\r
+ /* class constructor - Net_DNS_RR_A(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_A(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ /*\r
+ * We don't have inet_ntoa in PHP?\r
+ */\r
+ $aparts = unpack('C4b', $this->rdata);\r
+ $addr = $aparts['b1'] . '.' .\r
+ $aparts['b2'] . '.' .\r
+ $aparts['b3'] . '.' .\r
+ $aparts['b4'];\r
+ $this->address = $addr;\r
+ }\r
+ } else {\r
+ if (strlen($data) && ereg("([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)[ \t]*$", $data, $regs)) {\r
+ if (($regs[1] >= 0 && $regs[1] <= 255) &&\r
+ ($regs[2] >= 0 && $regs[2] <= 255) &&\r
+ ($regs[3] >= 0 && $regs[3] <= 255) &&\r
+ ($regs[4] >= 0 && $regs[4] <= 255)) {\r
+ $this->address = $regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' .$regs[4];\r
+ }\r
+ }\r
+ } \r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_A::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if (strlen($this->address)) {\r
+ return $this->address;\r
+ }\r
+ return '; no data';\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_RR_A::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ $aparts = split('\.', $this->address);\r
+ if (count($aparts) == 4) {\r
+ return pack('c4', $aparts[0], $aparts[1], $aparts[2], $aparts[3]);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+\r
+/* Net_DNS_RR_AAAA object definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>AAAA</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_AAAA extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $address;\r
+\r
+ /* }}} */\r
+ /* class constructor - Net_DNS_RR_AAAA(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_AAAA(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ $this->address = Net_DNS_RR_AAAA::ipv6_decompress(substr($this->rdata, 0, $this->rdlength));\r
+ } else {\r
+ if (strlen($data)) {\r
+ if (count($adata = explode(':', $data, 8)) >= 3) {\r
+ foreach($adata as $addr)\r
+ if (!preg_match('/^[0-9A-F]{0,4}$/i', $addr)) return;\r
+ $this->address = trim($data);\r
+ }\r
+ }\r
+ } \r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_AAAA::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if (strlen($this->address)) {\r
+ return $this->address;\r
+ }\r
+ return '; no data';\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_RR_AAAA::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ return Net_DNS_RR_AAAA::ipv6_compress($this->address);\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_AAAA::ipv6_compress($addr) {{{ */\r
+ function ipv6_compress($addr)\r
+ {\r
+ $numparts = count(explode(':', $addr));\r
+ if ($numparts < 3 || $numparts > 8 ||\r
+ !preg_match('/^([0-9A-F]{0,4}:){0,7}(:[0-9A-F]{0,4}){0,7}$/i', $addr)) {\r
+ /* Non-sensical IPv6 address */\r
+ return pack('n8', 0, 0, 0, 0, 0, 0, 0, 0);\r
+ }\r
+ if (strpos($addr, '::') !== false) {\r
+ /* First we have to normalize the address, turn :: into :0:0:0:0: */\r
+ $filler = str_repeat(':0', 9 - $numparts) . ':';\r
+ if (substr($addr, 0, 2) == '::') {\r
+ $filler = "0$filler";\r
+ }\r
+ if (substr($addr, -2, 2) == '::') {\r
+ $filler .= '0';\r
+ }\r
+ $addr = str_replace('::', $filler, $addr);\r
+ }\r
+ $aparts = explode(':', $addr);\r
+ return pack('n8', hexdec($aparts[0]), hexdec($aparts[1]), hexdec($aparts[2]), hexdec($aparts[3]),\r
+ hexdec($aparts[4]), hexdec($aparts[5]), hexdec($aparts[6]), hexdec($aparts[7]));\r
+ }\r
+ /* }}} */\r
+\r
+ /* Net_DNS_RR_AAAA::ipv6_decompress($pack) {{{ */\r
+ function ipv6_decompress($pack)\r
+ {\r
+ if (strlen($pack) != 16) {\r
+ /* Must be 8 shorts long */\r
+ return '::';\r
+ }\r
+ $a = unpack('n8', $pack);\r
+ $addr = vsprintf("%x:%x:%x:%x:%x:%x:%x:%x", $a);\r
+ /* Shorthand the first :0:0: set into a :: */\r
+ /* TODO: Make this is a single replacement pattern */\r
+ if (substr($addr, -4) == ':0:0') {\r
+ return preg_replace('/((:0){2,})$/', '::', $addr);\r
+ } elseif (substr($addr, 0, 4) == '0:0:') {\r
+ return '0:0:'. substr($addr, 4);\r
+ } else {\r
+ return preg_replace('/(:(0:){2,})/', '::', $addr);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_CNAME definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>CNAME</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_CNAME extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $cname;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_CNAME(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ list($cname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ $this->cname = $cname;\r
+ }\r
+ } else {\r
+ $this->cname = ereg_replace("[ \t]+(.+)[\. \t]*$", '\\1', $data);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_CNAME::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if (strlen($this->cname)) {\r
+ return $this->cname . '.';\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_CNAME::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if (strlen($this->cname)) {\r
+ return $packet->dn_comp($this->cname, $offset);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_HINFO definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>HINFO</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_HINFO extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $cpu;\r
+ var $os;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_HINFO(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ list($cpu, $offset) = Net_DNS_Packet::label_extract($data, $offset);\r
+ list($os, $offset) = Net_DNS_Packet::label_extract($data, $offset);\r
+\r
+ $this->cpu = $cpu;\r
+ $this->os = $os;\r
+ }\r
+ } else {\r
+ $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */\r
+ $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */\r
+\r
+ ereg('("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]*$', $data, $regs);\r
+ foreach($regs as $idx => $value) {\r
+ $value = str_replace(chr(2) . chr(2), '\\"', $value);\r
+ $value = str_replace(chr(1) . chr(1), '\\\\', $value);\r
+ $regs[$idx] = stripslashes($value);\r
+ }\r
+\r
+ $this->cpu = $regs[1];\r
+ $this->os = $regs[2];\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_HINFO::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if ($this->text) {\r
+ return '"' . addslashes($this->cpu) . '" "' . addslashes($this->os) . '"';\r
+ } else return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_HINFO::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if ($this->text) {\r
+ $rdata = pack('C', strlen($this->cpu)) . $this->cpu;\r
+ $rdata .= pack('C', strlen($this->os)) . $this->os;\r
+ return $rdata;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_MX definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>MX</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_MX extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $preference;\r
+ var $exchange;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_MX(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ $a = unpack("@$offset/npreference", $data);\r
+ $offset += 2;\r
+ list($exchange, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ $this->preference = $a['preference'];\r
+ $this->exchange = $exchange;\r
+ }\r
+ } else {\r
+ ereg("([0-9]+)[ \t]+(.+)[ \t]*$", $data, $regs);\r
+ $this->preference = $regs[1];\r
+ $this->exchange = ereg_replace('(.*)\.$', '\\1', $regs[2]);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_MX::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if (preg_match('/^[0-9]+$/', $this->preference)) {\r
+ return $this->preference . ' ' . $this->exchange . '.';\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_MX::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if (preg_match('/^[0-9]+$/', $this->preference)) {\r
+ $rdata = pack('n', $this->preference);\r
+ $rdata .= $packet->dn_comp($this->exchange, $offset + strlen($rdata));\r
+ return $rdata;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>\r
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_NAPTR definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>NAPTR</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_NAPTR extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $order;\r
+ var $preference;\r
+ var $flags;\r
+ var $services;\r
+ var $regex;\r
+ var $replacement;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_NAPTR(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ $a = unpack("@$offset/norder/npreference", $data);\r
+ $offset += 4;\r
+ list($flags, $offset) = Net_DNS_Packet::label_extract($data, $offset);\r
+ list($services, $offset) = Net_DNS_Packet::label_extract($data, $offset);\r
+ list($regex, $offset) = Net_DNS_Packet::label_extract($data, $offset);\r
+ list($replacement, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+\r
+ $this->order = $a['order'];\r
+ $this->preference = $a['preference'];\r
+ $this->flags = $flags;\r
+ $this->services = $services;\r
+ $this->regex = $regex;\r
+ $this->replacement = $replacement;\r
+ }\r
+ } else {\r
+ $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */\r
+ $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */\r
+ ereg('([0-9]+)[ \t]+([0-9]+)[ \t]+("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]+("[^"]*"|[^ \t]*)[ \t]+(.*?)[ \t]*$', $data, $regs);\r
+ $this->preference = $regs[1];\r
+ $this->weight = $regs[2];\r
+ foreach($regs as $idx => $value) {\r
+ $value = str_replace(chr(2) . chr(2), '\\"', $value);\r
+ $value = str_replace(chr(1) . chr(1), '\\\\', $value);\r
+ $regs[$idx] = stripslashes($value);\r
+ }\r
+ $this->flags = $regs[3];\r
+ $this->services = $regs[4];\r
+ $this->regex = $regs[5];\r
+ $this->replacement = $regs[6];\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_NAPTR::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if ($this->rdata) {\r
+ return intval($this->order) . ' ' . intval($this->preference) . ' "' . addslashes($this->flags) . '" "' . \r
+ addslashes($this->services) . '" "' . addslashes($this->regex) . '" "' . addslashes($this->replacement) . '"';\r
+ } else return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_NAPTR::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if ($this->preference) {\r
+ $rdata = pack('nn', $this->order, $this->preference);\r
+ $rdata .= pack('C', strlen($this->flags)) . $this->flags;\r
+ $rdata .= pack('C', strlen($this->services)) . $this->services;\r
+ $rdata .= pack('C', strlen($this->regex)) . $this->regex;\r
+ $rdata .= $packet->dn_comp($this->replacement, $offset + strlen($rdata));\r
+ return $rdata;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_NS definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>NS</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_NS extends Net_DNS_RR\r
+{\r
+ /* class variable defintiions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $nsdname;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_NS(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ list($nsdname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ $this->nsdname = $nsdname;\r
+ }\r
+ } else {\r
+ $this->nsdname = ereg_replace("[ \t]+(.+)[ \t]*$", '\\1', $data);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_NS::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if (strlen($this->nsdname)) {\r
+ return $this->nsdname . '.';\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_NS::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if (strlen($this->nsdname)) {\r
+ return $packet->dn_comp($this->nsdname, $offset);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_PTR definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>PTR</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_PTR extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $ptrdname;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_PTR(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ list($ptrdname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ $this->ptrdname = $ptrdname;\r
+ }\r
+ } else {\r
+ $this->ptrdname = ereg_replace("[ \t]+(.+)[ \t]*$", '\\1', $data);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_PTR::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if (strlen($this->ptrdname)) {\r
+ return $this->ptrdname . '.';\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_PTR::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if (strlen($this->ptrdname)) {\r
+ return $packet->dn_comp($this->ptrdname, $offset);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_SOA definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>SOA</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_SOA extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $mname;\r
+ var $rname;\r
+ var $serial;\r
+ var $refresh;\r
+ var $retry;\r
+ var $expire;\r
+ var $minimum;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_SOA(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ list($mname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ list($rname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+\r
+ $a = unpack("@$offset/N5soavals", $data);\r
+ $this->mname = $mname;\r
+ $this->rname = $rname;\r
+ $this->serial = $a['soavals1'];\r
+ $this->refresh = $a['soavals2'];\r
+ $this->retry = $a['soavals3'];\r
+ $this->expire = $a['soavals4'];\r
+ $this->minimum = $a['soavals5'];\r
+ }\r
+ } else {\r
+ if (ereg("([^ \t]+)[ \t]+([^ \t]+)[ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]*$", $string, $regs))\r
+ {\r
+ $this->mname = ereg_replace('(.*)\.$', '\\1', $regs[1]);\r
+ $this->rname = ereg_replace('(.*)\.$', '\\1', $regs[2]);\r
+ $this->serial = $regs[3];\r
+ $this->refresh = $regs[4];\r
+ $this->retry = $regs[5];\r
+ $this->expire = $regs[6];\r
+ $this->minimum = $regs[7];\r
+ }\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_SOA::rdatastr($pretty = 0) {{{ */\r
+ function rdatastr($pretty = 0)\r
+ {\r
+ if (strlen($this->mname)) {\r
+ if ($pretty) {\r
+ $rdatastr = $this->mname . '. ' . $this->rname . ". (\n";\r
+ $rdatastr .= "\t\t\t\t\t" . $this->serial . "\t; Serial\n";\r
+ $rdatastr .= "\t\t\t\t\t" . $this->refresh . "\t; Refresh\n";\r
+ $rdatastr .= "\t\t\t\t\t" . $this->retry . "\t; Retry\n";\r
+ $rdatastr .= "\t\t\t\t\t" . $this->expire . "\t; Expire\n";\r
+ $rdatastr .= "\t\t\t\t\t" . $this->minimum . " )\t; Minimum TTL";\r
+ } else {\r
+ $rdatastr = $this->mname . '. ' . $this->rname . '. ' .\r
+ $this->serial . ' ' . $this->refresh . ' ' . $this->retry . ' ' .\r
+ $this->expire . ' ' . $this->minimum;\r
+ }\r
+ return $rdatastr;\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_SOA::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if (strlen($this->mname)) {\r
+ $rdata = $packet->dn_comp($this->mname, $offset);\r
+ $rdata .= $packet->dn_comp($this->rname, $offset + strlen($rdata));\r
+ $rdata .= pack('N5', $this->serial,\r
+ $this->refresh,\r
+ $this->retry,\r
+ $this->expire,\r
+ $this->minimum);\r
+ return $rdata;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_SRV definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>SRV</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_SRV extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $preference;\r
+ var $weight;\r
+ var $port;\r
+ var $target;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_SRV(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ $a = unpack("@$offset/npreference/nweight/nport", $data);\r
+ $offset += 6;\r
+ list($target, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ $this->preference = $a['preference'];\r
+ $this->weight = $a['weight'];\r
+ $this->port = $a['port'];\r
+ $this->target = $target;\r
+ }\r
+ } else {\r
+ ereg("([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)[ \t]*$", $data, $regs);\r
+ $this->preference = $regs[1];\r
+ $this->weight = $regs[2];\r
+ $this->port = $regs[3];\r
+ $this->target = ereg_replace('(.*)\.$', '\\1', $regs[4]);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_SRV::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if ($this->port) {\r
+ return intval($this->preference) . ' ' . intval($this->weight) . ' ' . intval($this->port) . ' ' . $this->target . '.';\r
+ }\r
+ return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_SRV::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if (isset($this->preference)) {\r
+ $rdata = pack('nnn', $this->preference, $this->weight, $this->port);\r
+ $rdata .= $packet->dn_comp($this->target, $offset + strlen($rdata));\r
+ return $rdata;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>\r
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+define('NET_DNS_DEFAULT_ALGORITHM', 'hmac-md5.sig-alg.reg.int');\r
+define('NET_DNS_DEFAULT_FUDGE', 300);\r
+\r
+/* Net_DNS_RR_TSIG definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>TSIG</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_TSIG extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $time_signed;\r
+ var $fudge;\r
+ var $mac_size;\r
+ var $mac;\r
+ var $original_id;\r
+ var $error;\r
+ var $other_len;\r
+ var $other_data;\r
+ var $key;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_TSIG(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ list($alg, $offset) = Net_DNS_Packet::dn_expand($data, $offset);\r
+ $this->algorithm = $alg;\r
+\r
+ $d = unpack("\@$offset/nth/Ntl/nfudge/nmac_size", $data);\r
+ $time_high = $d['th'];\r
+ $time_low = $d['tl'];\r
+ $this->time_signed = $time_low;\r
+ $this->fudge = $d['fudge'];\r
+ $this->mac_size = $d['mac_size'];\r
+ $offset += 10;\r
+\r
+ $this->mac = substr($data, $offset, $this->mac_size);\r
+ $offset += $this->mac_size;\r
+\r
+ $d = unpack("@$offset/noid/nerror/nolen", $data);\r
+ $this->original_id = $d['oid'];\r
+ $this->error = $d['error'];\r
+ $this->other_len = $d['olen'];\r
+ $offset += 6;\r
+\r
+ $odata = substr($data, $offset, $this->other_len);\r
+ $d = unpack('nodata_high/Nodata_low', $odata);\r
+ $this->other_data = $d['odata_low'];\r
+ }\r
+ } else {\r
+ if (strlen($data) && preg_match('/^(.*)$/', $data, $regs)) {\r
+ $this->key = $regs[1];\r
+ }\r
+\r
+ $this->algorithm = NET_DNS_DEFAULT_ALGORITHM;\r
+ $this->time_signed = time();\r
+\r
+ $this->fudge = NET_DNS_DEFAULT_FUDGE;\r
+ $this->mac_size = 0;\r
+ $this->mac = '';\r
+ $this->original_id = 0;\r
+ $this->error = 0;\r
+ $this->other_len = 0;\r
+ $this->other_data = '';\r
+\r
+ // RFC 2845 Section 2.3\r
+ $this->class = 'ANY';\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_TSIG::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ $error = $this->error;\r
+ if (! $error) {\r
+ $error = 'UNDEFINED';\r
+ }\r
+\r
+ if (strlen($this->algorithm)) {\r
+ $rdatastr = $this->algorithm . '. ' . $this->time_signed . ' ' .\r
+ $this->fudge . ' ';\r
+ if ($this->mac_size && strlen($this->mac)) {\r
+ $rdatastr .= ' ' . $this->mac_size . ' ' . base64_encode($this->mac);\r
+ } else {\r
+ $rdatastr .= ' 0 ';\r
+ }\r
+ $rdatastr .= ' ' . $this->original_id . ' ' . $error;\r
+ if ($this->other_len && strlen($this->other_data)) {\r
+ $rdatastr .= ' ' . $this->other_data;\r
+ } else {\r
+ $rdatastr .= ' 0 ';\r
+ }\r
+ } else {\r
+ $rdatastr = '; no data';\r
+ }\r
+\r
+ return $rdatastr;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_TSIG::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ $rdata = '';\r
+ $sigdata = '';\r
+\r
+ if (strlen($this->key)) {\r
+ $key = $this->key;\r
+ $key = ereg_replace(' ', '', $key);\r
+ $key = base64_decode($key);\r
+\r
+ $newpacket = $packet;\r
+ $newoffset = $offset;\r
+ array_pop($newpacket->additional);\r
+ $newpacket->header->arcount--;\r
+ $newpacket->compnames = array();\r
+\r
+ /*\r
+ * Add the request MAC if present (used to validate responses).\r
+ */\r
+ if (isset($this->request_mac)) {\r
+ $sigdata .= pack('H*', $this->request_mac);\r
+ }\r
+ $sigdata .= $newpacket->data();\r
+\r
+ /*\r
+ * Don't compress the record (key) name.\r
+ */\r
+ $tmppacket = new Net_DNS_Packet;\r
+ $sigdata .= $tmppacket->dn_comp(strtolower($this->name), 0);\r
+\r
+ $sigdata .= pack('n', Net_DNS::classesbyname(strtoupper($this->class)));\r
+ $sigdata .= pack('N', $this->ttl);\r
+\r
+ /*\r
+ * Don't compress the algorithm name.\r
+ */\r
+ $tmppacket->compnames = array();\r
+ $sigdata .= $tmppacket->dn_comp(strtolower($this->algorithm), 0);\r
+\r
+ $sigdata .= pack('nN', 0, $this->time_signed);\r
+ $sigdata .= pack('n', $this->fudge);\r
+ $sigdata .= pack('nn', $this->error, $this->other_len);\r
+\r
+ if (strlen($this->other_data)) {\r
+ $sigdata .= pack('nN', 0, $this->other_data);\r
+ }\r
+\r
+ $this->mac = mhash(MHASH_MD5, $sigdata, $key);\r
+ $this->mac_size = strlen($this->mac);\r
+\r
+ /*\r
+ * Don't compress the algorithm name.\r
+ */\r
+ unset($tmppacket);\r
+ $tmppacket = new Net_DNS_Packet;\r
+ $rdata .= $tmppacket->dn_comp(strtolower($this->algorithm), 0);\r
+\r
+ $rdata .= pack('nN', 0, $this->time_signed);\r
+ $rdata .= pack('nn', $this->fudge, $this->mac_size);\r
+ $rdata .= $this->mac;\r
+\r
+ $rdata .= pack('nnn',$packet->header->id,\r
+ $this->error,\r
+ $this->other_len);\r
+\r
+ if ($this->other_data) {\r
+ $rdata .= pack('nN', 0, $this->other_data);\r
+ }\r
+ }\r
+ return $rdata;\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_RR_TSIG::error() {{{ */\r
+ function error()\r
+ {\r
+ if ($this->error != 0) {\r
+ $rcode = Net_DNS::rcodesbyval($error);\r
+ }\r
+ return $rcode;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * expandtab on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/* Net_DNS_RR_TXT definition {{{ */\r
+/**\r
+ * A representation of a resource record of type <b>TXT</b>\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_RR_TXT extends Net_DNS_RR\r
+{\r
+ /* class variable definitions {{{ */\r
+ var $name;\r
+ var $type;\r
+ var $class;\r
+ var $ttl;\r
+ var $rdlength;\r
+ var $rdata;\r
+ var $text;\r
+\r
+ /* }}} */\r
+ /* class constructor - RR(&$rro, $data, $offset = '') {{{ */\r
+ function Net_DNS_RR_TXT(&$rro, $data, $offset = '')\r
+ {\r
+ $this->name = $rro->name;\r
+ $this->type = $rro->type;\r
+ $this->class = $rro->class;\r
+ $this->ttl = $rro->ttl;\r
+ $this->rdlength = $rro->rdlength;\r
+ $this->rdata = $rro->rdata;\r
+\r
+ if ($offset) {\r
+ if ($this->rdlength > 0) {\r
+ $maxoffset = $this->rdlength + $offset;\r
+ while ($maxoffset > $offset) {\r
+ list($text, $offset) = Net_DNS_Packet::label_extract($data, $offset);\r
+ $this->text[] = $text;\r
+ }\r
+ }\r
+ } else {\r
+ $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */\r
+ $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */\r
+\r
+ ereg('("[^"]*"|[^ \t]*)[ \t]*$', $data, $regs);\r
+ $regs[1] = str_replace(chr(2) . chr(2), '\\"', $regs[1]);\r
+ $regs[1] = str_replace(chr(1) . chr(1), '\\\\', $regs[1]);\r
+ $regs[1] = stripslashes($regs[1]);\r
+\r
+ $this->text = $regs[1];\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_TXT::rdatastr() {{{ */\r
+ function rdatastr()\r
+ {\r
+ if ($this->text) {\r
+ if (is_array($this->text)) {\r
+ $tmp = array();\r
+ foreach ($this->text as $t) {\r
+ $tmp[] = '"'.addslashes($t).'"';\r
+ }\r
+ return implode(' ',$tmp);\r
+ } else {\r
+ return '"' . addslashes($this->text) . '"';\r
+ }\r
+ } else return '; no data';\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_RR_TXT::rr_rdata($packet, $offset) {{{ */\r
+ function rr_rdata($packet, $offset)\r
+ {\r
+ if ($this->text) {\r
+ $rdata = pack('C', strlen($this->text)) . $this->text;\r
+ return $rdata;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>\r
--- /dev/null
+<?php\r
+/*\r
+ * License Information:\r
+ *\r
+ * Net_DNS: A resolver library for PHP\r
+ * Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+\r
+/* Net_DNS_Resolver object definition {{{ */\r
+/**\r
+ * A DNS Resolver library\r
+ *\r
+ * Resolver library. Builds a DNS query packet, sends the packet to the\r
+ * server and parses the reponse.\r
+ *\r
+ * @package Net_DNS\r
+ */\r
+class Net_DNS_Resolver\r
+{\r
+ /* class variable definitions {{{ */\r
+ /**\r
+ * An array of all nameservers to query\r
+ *\r
+ * @var array $nameservers\r
+ * @access public\r
+ */\r
+ var $nameservers;\r
+ /**\r
+ * The UDP port to use for the query (default = 53)\r
+ *\r
+ * @var integer $port\r
+ * @access public\r
+ */\r
+ var $port;\r
+ /**\r
+ * The domain in which the resolver client host resides.\r
+ *\r
+ * @var string $domain\r
+ * @access public\r
+ */\r
+ var $domain;\r
+ /**\r
+ * The searchlist to apply to unqualified hosts\r
+ *\r
+ * An array of strings containg domains to apply to unqualified hosts\r
+ * passed to the resolver.\r
+ *\r
+ * @var array $searchlist\r
+ * @access public\r
+ */\r
+ var $searchlist;\r
+ /**\r
+ * The number of seconds between retransmission of unaswered queries\r
+ *\r
+ * @var integer $retrans\r
+ * @access public\r
+ */\r
+ var $retrans;\r
+ /**\r
+ * The number of times unanswered requests should be retried\r
+ *\r
+ * @var integer $retry\r
+ * @access public\r
+ */\r
+ var $retry;\r
+ /**\r
+ * Whether or not to use TCP (Virtual Circuits) instead of UDP\r
+ *\r
+ * If set to 0, UDP will be used unless TCP is required. TCP is\r
+ * required for questions or responses greater than 512 bytes.\r
+ *\r
+ * @var boolean $usevc\r
+ * @access public\r
+ */\r
+ var $usevc;\r
+ /**\r
+ * Unknown\r
+ */\r
+ var $stayopen;\r
+ /**\r
+ * Ignore TC (truncated) bit\r
+ *\r
+ * If the server responds with the TC bit set on a response, and $igntc\r
+ * is set to 0, the resolver will automatically retransmit the request\r
+ * using virtual circuits (TCP).\r
+ *\r
+ * @access public\r
+ * @var boolean $igntc\r
+ */\r
+ var $igntc;\r
+ /**\r
+ * Recursion Desired\r
+ *\r
+ * Sets the value of the RD (recursion desired) bit in the header. If\r
+ * the RD bit is set to 0, the server will not perform recursion on the\r
+ * request.\r
+ *\r
+ * @var boolean $recurse\r
+ * @access public\r
+ */\r
+ var $recurse;\r
+ /**\r
+ * Unknown\r
+ */\r
+ var $defnames;\r
+ /**\r
+ * Unknown\r
+ */\r
+ var $dnsrch;\r
+ /**\r
+ * Contains the value of the last error returned by the resolver.\r
+ *\r
+ * @var string $errorstring\r
+ * @access public\r
+ */\r
+ var $errorstring;\r
+ /**\r
+ * The origin of the packet.\r
+ *\r
+ * This contains a string containing the IP address of the name server\r
+ * from which the answer was given.\r
+ *\r
+ * @var string $answerfrom\r
+ * @access public\r
+ */\r
+ var $answerfrom;\r
+ /**\r
+ * The size of the answer packet.\r
+ *\r
+ * This contains a integer containing the size of the DNS packet the\r
+ * server responded with.\r
+ *\r
+ * @var string $answersize\r
+ * @access public\r
+ */\r
+ var $answersize;\r
+ /**\r
+ * The number of seconds after which a TCP connection should timeout\r
+ *\r
+ * @var integer $tcp_timeout\r
+ * @access public\r
+ */\r
+ var $tcp_timeout;\r
+ /**\r
+ * The location of the system resolv.conf file.\r
+ *\r
+ * @var string $resolv_conf\r
+ */\r
+ var $resolv_conf = '/etc/resolv.conf';\r
+ /**\r
+ * The name of the user defined resolv.conf\r
+ *\r
+ * The resolver will attempt to look in both the current directory as\r
+ * well as the user's home directory for a user defined resolver\r
+ * configuration file\r
+ *\r
+ * @var string $dotfile\r
+ * @see Net_DNS_Resolver::$confpath\r
+ */\r
+ var $dotfile = '.resolv.conf';\r
+ /**\r
+ * A array of directories to search for the user's resolver config\r
+ *\r
+ * @var string $confpath\r
+ * @see Net_DNS_Resolver::$dotfile\r
+ */\r
+ var $confpath;\r
+ /**\r
+ * debugging flag\r
+ *\r
+ * If set to true (non-zero), debugging code will be displayed as the\r
+ * resolver makes the request.\r
+ *\r
+ * @var boolean $debug;\r
+ * @access public\r
+ */\r
+ var $debug;\r
+ /**\r
+ * use the (currently) experimental PHP socket library\r
+ *\r
+ * If set to true (non-zero), the Resolver will attempt to use the\r
+ * much more effecient PHP sockets extension (if available).\r
+ *\r
+ * @var boolean $useEnhancedSockets;\r
+ * @access public\r
+ */\r
+ var $useEnhancedSockets = true;\r
+ /**\r
+ * An array of sockets connected to a name servers\r
+ *\r
+ * @var array $sockets\r
+ * @access private\r
+ */\r
+ var $sockets;\r
+ /**\r
+ * axfr tcp socket\r
+ *\r
+ * Used to store a PHP socket resource for a connection to a server\r
+ *\r
+ * @var resource $_axfr_sock;\r
+ * @access private\r
+ */\r
+ var $_axfr_sock;\r
+ /**\r
+ * axfr resource record list\r
+ *\r
+ * Used to store a resource record list from a zone transfer\r
+ *\r
+ * @var resource $_axfr_rr;\r
+ * @access private\r
+ */\r
+ var $_axfr_rr;\r
+ /**\r
+ * axfr soa count\r
+ *\r
+ * Used to store the number of soa records received from a zone transfer\r
+ *\r
+ * @var resource $_axfr_soa_count;\r
+ * @access private\r
+ */\r
+ var $_axfr_soa_count;\r
+\r
+\r
+ /* }}} */\r
+ /* class constructor - Net_DNS_Resolver() {{{ */\r
+ /**\r
+ * Initializes the Resolver Object\r
+ *\r
+ * @return Net_DNS_Resolver\r
+ */\r
+ function Net_DNS_Resolver($defaults = array())\r
+ {\r
+ $mydefaults = array(\r
+ 'nameservers' => array(),\r
+ 'port' => '53',\r
+ 'domain' => '',\r
+ 'searchlist' => array(),\r
+ 'retrans' => 5,\r
+ 'retry' => 4,\r
+ 'usevc' => 0,\r
+ 'stayopen' => 0,\r
+ 'igntc' => 0,\r
+ 'recurse' => 1,\r
+ 'defnames' => 1,\r
+ 'dnsrch' => 1,\r
+ 'debug' => 0,\r
+ 'errorstring' => 'unknown error or no error',\r
+ 'answerfrom' => '',\r
+ 'answersize' => 0,\r
+ 'tcp_timeout' => 120\r
+ );\r
+ foreach ($mydefaults as $k => $v) {\r
+ $this->{$k} = isset($defaults[$k]) ? $defaults[$k] : $v;\r
+ }\r
+ $this->confpath[0] = getenv('HOME');\r
+ $this->confpath[1] = '.';\r
+ $this->res_init();\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::res_init() {{{ */\r
+ /**\r
+ * Initalizes the resolver library\r
+ *\r
+ * res_init() searches for resolver library configuration files and\r
+ * initializes the various properties of the resolver object.\r
+ *\r
+ * @see Net_DNS_Resolver::$resolv_conf, Net_DNS_Resolver::$dotfile,\r
+ * Net_DNS_Resolver::$confpath, Net_DNS_Resolver::$searchlist,\r
+ * Net_DNS_Resolver::$domain, Net_DNS_Resolver::$nameservers\r
+ * @access public\r
+ */\r
+ function res_init()\r
+ {\r
+ $err = error_reporting(0);\r
+ if (file_exists($this->resolv_conf) && is_readable($this->resolv_conf)) {\r
+ $this->read_config($this->resolv_conf);\r
+ }\r
+\r
+ foreach ($this->confpath as $dir) {\r
+ $file = $dir.DIRECTORY_SEPARATOR.$this->dotfile;\r
+ if (file_exists($file) && is_readable($file)) {\r
+ $this->read_config($file);\r
+ }\r
+ }\r
+\r
+ $this->read_env();\r
+\r
+ if (!strlen($this->domain) && sizeof($this->searchlist)) {\r
+ $this->domain = $this->searchlist[0];\r
+ } else if (! sizeof($this->searchlist) && strlen($this->domain)) {\r
+ $this->searchlist = array($this->domain);\r
+ }\r
+ error_reporting($err);\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::read_config {{{ */\r
+ /**\r
+ * Reads and parses a resolver configuration file\r
+ *\r
+ * @param string $file The name of the file to open and parse\r
+ */\r
+ function read_config($file)\r
+ {\r
+ if (is_readable($file)) {\r
+ if (! ($f = fopen($file, 'r'))) {\r
+ $this->error = "can't open $file";\r
+ }\r
+ }\r
+\r
+ if (!is_resource($f)) {\r
+ $this->error = "can't open $file";\r
+ } else {\r
+ while (! feof($f)) {\r
+ $line = chop(fgets($f, 10240));\r
+ $line = ereg_replace('(.*)[;#].*', '\\1', $line);\r
+ if (ereg("^[ \t]*$", $line, $regs)) {\r
+ continue;\r
+ }\r
+ ereg("^[ \t]*([^ \t]+)[ \t]+([^ \t]+)", $line, $regs);\r
+ $option = $regs[1];\r
+ $value = $regs[2];\r
+\r
+ switch ($option) {\r
+ case 'domain':\r
+ $this->domain = $regs[2];\r
+ break;\r
+ case 'search':\r
+ $this->searchlist[count($this->searchlist)] = $regs[2];\r
+ break;\r
+ case 'nameserver':\r
+ foreach (split(' ', $regs[2]) as $ns) {\r
+ $this->nameservers[count($this->nameservers)] = $ns;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ fclose($f);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::read_env() {{{ */\r
+ /**\r
+ * Examines the environment for resolver config information\r
+ */\r
+ function read_env()\r
+ {\r
+ if (getenv('RES_NAMESERVERS')) {\r
+ $this->nameservers = split(' ', getenv('RES_NAMESERVERS'));\r
+ }\r
+\r
+ if (getenv('RES_SEARCHLIST')) {\r
+ $this->searchlist = split(' ', getenv('RES_SEARCHLIST'));\r
+ }\r
+\r
+ if (getenv('LOCALDOMAIN')) {\r
+ $this->domain = getenv('LOCALDOMAIN');\r
+ }\r
+\r
+ if (getenv('RES_OPTIONS')) {\r
+ $env = split(' ', getenv('RES_OPTIONS'));\r
+ foreach ($env as $opt) {\r
+ list($name, $val) = split(':', $opt);\r
+ if ($val == '') {\r
+ $val = 1;\r
+ }\r
+ $this->{$name} = $val;\r
+ }\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::string() {{{ */\r
+ /**\r
+ * Builds a string containing the current state of the resolver\r
+ *\r
+ * Builds formatted string containing the state of the resolver library suited\r
+ * for display.\r
+ *\r
+ * @access public\r
+ */\r
+ function string()\r
+ {\r
+ $state = ";; Net_DNS_Resolver state:\n";\r
+ $state .= ';; domain = ' . $this->domain . "\n";\r
+ $state .= ';; searchlist = ' . implode(' ', $this->searchlist) . "\n";\r
+ $state .= ';; nameservers = ' . implode(' ', $this->nameservers) . "\n";\r
+ $state .= ';; port = ' . $this->port . "\n";\r
+ $state .= ';; tcp_timeout = ';\r
+ $state .= ($this->tcp_timeout ? $this->tcp_timeout : 'indefinite') . "\n";\r
+ $state .= ';; retrans = ' . $this->retrans . ' ';\r
+ $state .= 'retry = ' . $this->retry . "\n";\r
+ $state .= ';; usevc = ' . $this->usevc . ' ';\r
+ $state .= 'stayopen = ' . $this->stayopen . ' ';\r
+ $state .= 'igntc = ' . $this->igntc . "\n";\r
+ $state .= ';; defnames = ' . $this->defnames . ' ';\r
+ $state .= 'dnsrch = ' . $this->dnsrch . "\n";\r
+ $state .= ';; recurse = ' . $this->recurse . ' ';\r
+ $state .= 'debug = ' . $this->debug . "\n";\r
+ return $state;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::nextid() {{{ */\r
+ /**\r
+ * Returns the next request Id to be used for the DNS packet header\r
+ */\r
+ function nextid()\r
+ {\r
+ if ($GLOBALS['_Net_DNS_packet_id']++ > 65535) {\r
+ $GLOBALS['_Net_DNS_packet_id']= 1;\r
+ }\r
+ return $GLOBALS['_Net_DNS_packet_id'];\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::nameservers() {{{ */\r
+ /**\r
+ * Gets or sets the nameservers to be queried.\r
+ *\r
+ * Returns the current nameservers if an array of new nameservers is not\r
+ * given as the argument OR sets the nameservers to the given nameservers.\r
+ *\r
+ * Nameservers not specified by ip address must be able to be resolved by\r
+ * the default settings of a new Net_DNS_Resolver.\r
+ *\r
+ * @access public\r
+ */\r
+ function nameservers($nsa = array())\r
+ {\r
+ $defres = new Net_DNS_Resolver();\r
+\r
+ if (is_array($nsa)) {\r
+ $a = array();\r
+ foreach ($nsa as $ns) {\r
+ if (preg_match('/^(\d+(:?\.\d+){0,3})$/', $ns)) {\r
+ $a[] = ($ns == 0) ? '0.0.0.0' : $ns;\r
+ } else {\r
+ $names = array();\r
+ if (!preg_match('/\./', $ns)) {\r
+ if (!empty($defres->searchlist)) {\r
+ foreach ($defres->searchlist as $suffix) {\r
+ $names[] = $ns .'.' . $suffix;\r
+ }\r
+ } elseif (!empty($defres->domain)) {\r
+ $names[] = $ns .'.'. $defres->domain;\r
+ }\r
+ } else {\r
+ $names[] = $ns;\r
+ }\r
+ $packet = $defres->search($ns);\r
+ if (is_object($packet)) {\r
+ $addresses = $this->cname_addr($names, $packet);\r
+ foreach ($addresses as $b) {\r
+ $a[] = $b;\r
+ }\r
+ $a = array_unique($a);\r
+ }\r
+ }\r
+ }\r
+ if (count($a)) {\r
+ $this->nameservers = $a;\r
+ }\r
+ }\r
+ return $this->nameservers;\r
+ }\r
+\r
+ /* }}} */\r
+ /* not tested -- Net_DNS_Resolver::cname_addr() {{{ */\r
+ function cname_addr($names, $packet)\r
+ {\r
+ $addr = array();\r
+ //my $oct2 = '(?:2[0-4]\d|25[0-5]|[0-1]?\d\d|\d)';\r
+ foreach ($packet->answer as $rr) {\r
+ if (in_array($rr->name, $names)) {\r
+ if ($rr->type == 'CNAME') {\r
+ $names[] = $rr->cname;\r
+ } elseif ($rr->type == 'A') {\r
+ // Run a basic taint check.\r
+ //next RR unless $rr->address =~ m/^($oct2\.$oct2\.$oct2\.$oct2)$/o;\r
+\r
+ $addr[] = $rr->address;\r
+ }\r
+ }\r
+ }\r
+ return $addr;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::search() {{{ */\r
+ /**\r
+ * Searches nameservers for an answer\r
+ *\r
+ * Goes through the search list and attempts to resolve name based on\r
+ * the information in the search list.\r
+ *\r
+ * @param string $name The name (LHS) of a resource record to query.\r
+ * @param string $type The type of record to query.\r
+ * @param string $class The class of record to query.\r
+ * @return mixed an object of type Net_DNS_Packet on success,\r
+ * or false on failure.\r
+ * @see Net_DNS::typesbyname(), Net_DNS::classesbyname()\r
+ * @access public\r
+ */\r
+ function search($name, $type = 'A', $class = 'IN')\r
+ {\r
+ /*\r
+ * If the name looks like an IP address then do an appropriate\r
+ * PTR query.\r
+ */\r
+ if (preg_match('/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/', $name, $regs)) {\r
+ $name = $regs[4].'.'.$regs[3].'.'.$regs[2].'.'.$regs[1].'.in-addr.arpa.';\r
+ $type = 'PTR';\r
+ }\r
+\r
+ /*\r
+ * If the name contains at least one dot then try it as is first.\r
+ */\r
+ if (strstr($name, '.')) {\r
+ if ($this->debug) {\r
+ echo ";; search($name, $type, $class)\n";\r
+ }\r
+ $ans = $this->query($name, $type, $class);\r
+ if (is_object($ans) && ($ans->header->ancount > 0)) {\r
+ return $ans;\r
+ }\r
+ }\r
+\r
+ /*\r
+ * If the name does not end in a dot then apply the search list.\r
+ */\r
+ $domain = '';\r
+ if ((! preg_match('/\.$/', $name)) && $this->dnsrch) {\r
+ foreach ($this->searchlist as $domain) {\r
+ $newname = "$name.$domain";\r
+ if ($this->debug) {\r
+ echo ";; search($newname, $type, $class)\n";\r
+ }\r
+ $ans = $this->query($newname, $type, $class);\r
+ if (is_object($ans) && ($ans->header->ancount > 0)) {\r
+ return $ans;\r
+ }\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Finally, if the name has no dots then try it as is.\r
+ */\r
+ if (strpos($name, '.') === false) {\r
+ if ($this->debug) {\r
+ echo ";; search($name, $type, $class)\n";\r
+ }\r
+ $ans = $this->query($name.'.', $type, $class);\r
+ if (is_object($ans) && ($ans->header->ancount > 0)) {\r
+ return $ans;\r
+ }\r
+ }\r
+\r
+ /*\r
+ * No answer was found.\r
+ */\r
+ return false;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::rawQuery() {{{ */\r
+ /**\r
+ * Queries nameservers for an answer\r
+ *\r
+ * Queries the nameservers listed in the resolver configuration for an\r
+ * answer to a question packet.\r
+ *\r
+ * @param string $name The name (LHS) of a resource record to query.\r
+ * @param string $type The type of record to query.\r
+ * @param string $class The class of record to query.\r
+ * @return mixed an object of type Net_DNS_Packet, regardless of whether the packet\r
+ * has an answer or not\r
+ * @see Net_DNS::typesbyname(), Net_DNS::classesbyname()\r
+ * @access public\r
+ */\r
+ function rawQuery($name, $type = 'A', $class = 'IN')\r
+ {\r
+ /*\r
+ * If the name does not contain any dots then append the default domain.\r
+ */\r
+ if ((strchr($name, '.') < 0) && $this->defnames) {\r
+ $name .= '.' . $this->domain;\r
+ }\r
+\r
+ /*\r
+ * If the name looks like an IP address then do an appropriate\r
+ * PTR query.\r
+ */\r
+ if (preg_match('/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/', $name, $regs)) {\r
+ $name = $regs[4].'.'.$regs[3].'.'.$regs[2].'.'.$regs[1].'.in-addr.arpa.';\r
+ $type = 'PTR';\r
+ }\r
+\r
+ if ($this->debug) {\r
+ echo ";; query($name, $type, $class)\n";\r
+ }\r
+ $packet = new Net_DNS_Packet($this->debug);\r
+ $packet->buildQuestion($name, $type, $class);\r
+ $packet->header->rd = $this->recurse;\r
+ $ans = $this->send($packet);\r
+ return $ans;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::query() {{{ */\r
+ /**\r
+ * Queries nameservers for an answer\r
+ *\r
+ * Queries the nameservers listed in the resolver configuration for an\r
+ * answer to a question packet.\r
+ *\r
+ * @param string $name The name (LHS) of a resource record to query.\r
+ * @param string $type The type of record to query.\r
+ * @param string $class The class of record to query.\r
+ * @return mixed an object of type Net_DNS_Packet on success,\r
+ * or false on failure.\r
+ * @see Net_DNS::typesbyname(), Net_DNS::classesbyname()\r
+ * @access public\r
+ */\r
+ function query($name, $type = 'A', $class = 'IN')\r
+ {\r
+ $ans = $this->rawQuery($name, $type, $class);\r
+ if (is_object($ans) && $ans->header->ancount > 0) {\r
+ return $ans;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::send($packetORname, $qtype = '', $qclass = '') {{{ */\r
+ /**\r
+ * Sends a packet to a nameserver\r
+ *\r
+ * Determines the appropriate communication method (UDP or TCP) and\r
+ * sends a DNS packet to a nameserver. Use of the this function\r
+ * directly is discouraged. $packetORname should always be a properly\r
+ * formatted binary DNS packet. However, it is possible to send a\r
+ * query here and bypass Net_DNS_Resolver::query()\r
+ *\r
+ * @param string $packetORname A binary DNS packet stream or a\r
+ * hostname to query\r
+ * @param string $qtype This should not be used\r
+ * @param string $qclass This should not be used\r
+ * @return object Net_DNS_Packet An answer packet object\r
+ */\r
+ function send($packetORname, $qtype = '', $qclass = '')\r
+ {\r
+ $packet = $this->make_query_packet($packetORname, $qtype, $qclass);\r
+ $packet_data = $packet->data();\r
+\r
+ if ($this->usevc != 0 || strlen($packet_data > 512)) {\r
+ $ans = $this->send_tcp($packet, $packet_data);\r
+ } else {\r
+ $ans = $this->send_udp($packet, $packet_data);\r
+\r
+ if ($ans && $ans->header->tc && $this->igntc != 0) {\r
+ if ($this->debug) {\r
+ echo ";;\n;; packet truncated: retrying using TCP\n";\r
+ }\r
+ $ans = $this->send_tcp($packet, $packet_data);\r
+ }\r
+ }\r
+ return $ans;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::printhex($packet_data) {{{ */\r
+ /**\r
+ * Prints packet data as hex code.\r
+ */\r
+ function printhex($data)\r
+ {\r
+ $data = ' ' . $data;\r
+ $start = 0;\r
+ while ($start < strlen($data)) {\r
+ printf(';; %03d: ', $start);\r
+ for ($ctr = $start; $ctr < $start+16; $ctr++) {\r
+ if ($ctr < strlen($data)) {\r
+ printf('%02x ', ord($data[$ctr]));\r
+ } else {\r
+ echo ' ';\r
+ }\r
+ }\r
+ echo ' ';\r
+ for ($ctr = $start; $ctr < $start+16; $ctr++) {\r
+ if (ord($data[$ctr]) < 32 || ord($data[$ctr]) > 127) {\r
+ echo '.';\r
+ } else {\r
+ echo $data[$ctr];\r
+ }\r
+ }\r
+ echo "\n";\r
+ $start += 16;\r
+ }\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::send_tcp($packet, $packet_data) {{{ */\r
+ /**\r
+ * Sends a packet via TCP to the list of name servers.\r
+ *\r
+ * @param string $packet A packet object to send to the NS list\r
+ * @param string $packet_data The data in the packet as returned by\r
+ * the Net_DNS_Packet::data() method\r
+ * @return object Net_DNS_Packet Returns an answer packet object\r
+ * @see Net_DNS_Resolver::send_udp(), Net_DNS_Resolver::send()\r
+ */\r
+ function send_tcp($packet, $packet_data)\r
+ {\r
+ if (! count($this->nameservers)) {\r
+ $this->errorstring = 'no nameservers';\r
+ if ($this->debug) {\r
+ echo ";; ERROR: send_tcp: no nameservers\n";\r
+ }\r
+ return null;\r
+ }\r
+ $timeout = $this->tcp_timeout;\r
+\r
+ foreach ($this->nameservers as $ns) {\r
+ $dstport = $this->port;\r
+ if ($this->debug) {\r
+ echo ";; send_tcp($ns:$dstport)\n";\r
+ }\r
+ $sock_key = "$ns:$dstport";\r
+ if (isset($this->sockets[$sock_key]) && is_resource($this->sockets[$sock_key])) {\r
+ $sock = &$this->sockets[$sock_key];\r
+ } else {\r
+ if (! ($sock = @fsockopen($ns, $dstport, $errno,\r
+ $errstr, $timeout))) {\r
+ $this->errorstring = 'connection failed';\r
+ if ($this->debug) {\r
+ echo ";; ERROR: send_tcp: connection failed: $errstr\n";\r
+ }\r
+ continue;\r
+ }\r
+ $this->sockets[$sock_key] = $sock;\r
+ unset($sock);\r
+ $sock = &$this->sockets[$sock_key];\r
+ }\r
+ $lenmsg = pack('n', strlen($packet_data));\r
+ if ($this->debug) {\r
+ echo ';; sending ' . strlen($packet_data) . " bytes\n";\r
+ }\r
+\r
+ if (($sent = fwrite($sock, $lenmsg)) == -1) {\r
+ $this->errorstring = 'length send failed';\r
+ if ($this->debug) {\r
+ echo ";; ERROR: send_tcp: length send failed\n";\r
+ }\r
+ continue;\r
+ }\r
+\r
+ if (($sent = fwrite($sock, $packet_data)) == -1) {\r
+ $this->errorstring = 'packet send failed';\r
+ if ($this->debug) {\r
+ echo ";; ERROR: send_tcp: packet data send failed\n";\r
+ }\r
+ }\r
+\r
+ socket_set_timeout($sock, $timeout);\r
+ $buf = fread($sock, 2);\r
+ $e = socket_get_status($sock);\r
+ /* If $buf is empty, we want to supress errors\r
+ long enough to reach the continue; down the line */\r
+ $len = @unpack('nint', $buf);\r
+ $len = @$len['int'];\r
+ if (!$len) {\r
+ continue;\r
+ }\r
+ $buf = fread($sock, $len);\r
+ $actual = strlen($buf);\r
+ $this->answerfrom = $ns;\r
+ $this->answersize = $len;\r
+ if ($this->debug) {\r
+ echo ";; received $actual bytes\n";\r
+ }\r
+ if ($actual != $len) {\r
+ $this->errorstring = "expected $len bytes, received $buf";\r
+ if ($this->debug) {\r
+ echo ';; send_tcp: ' . $this->errorstring;\r
+ }\r
+ continue;\r
+ }\r
+\r
+ $ans = new Net_DNS_Packet($this->debug);\r
+ if (is_null($ans->parse($buf))) {\r
+ continue;\r
+ }\r
+ $this->errorstring = $ans->header->rcode;\r
+ $ans->answerfrom = $this->answerfrom;\r
+ $ans->answersize = $this->answersize;\r
+ return $ans;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::send_udp_no_sock_lib($packet, $packet_data) {{{ */\r
+ /**\r
+ * Sends a packet via UDP to the list of name servers.\r
+ *\r
+ * This function sends a packet to a nameserver. It is called by\r
+ * send_udp if the sockets PHP extension is not compiled into PHP.\r
+ *\r
+ * @param string $packet A packet object to send to the NS list\r
+ * @param string $packet_data The data in the packet as returned by\r
+ * the Net_DNS_Packet::data() method\r
+ * @return object Net_DNS_Packet Returns an answer packet object\r
+ * @see Net_DNS_Resolver::send_tcp(), Net_DNS_Resolver::send(),\r
+ * Net_DNS_Resolver::send_udp(), Net_DNS_Resolver::send_udp_with_sock_lib()\r
+ */\r
+ function send_udp_no_sock_lib($packet, $packet_data)\r
+ {\r
+ $retrans = $this->retrans;\r
+ $timeout = $retrans;\r
+\r
+ /*\r
+ * PHP doesn't have excellent socket support as of this writing.\r
+ * This needs to be rewritten when PHP POSIX socket support is\r
+ * complete.\r
+ * Obviously, this code is MUCH different than the PERL implementation\r
+ */\r
+\r
+ $w = error_reporting(0);\r
+ $ctr = 0;\r
+ // Create a socket handle for each nameserver\r
+ foreach ($this->nameservers as $nameserver) {\r
+ if ($sock[$ctr++] = fsockopen("udp://$nameserver", $this->port)) {\r
+ $peerhost[$ctr-1] = $nameserver;\r
+ $peerport[$ctr-1] = $this->port;\r
+ socket_set_blocking($sock[$ctr-1], false);\r
+ } else {\r
+ $ctr--;\r
+ }\r
+ }\r
+ error_reporting($w);\r
+\r
+ if ($ctr == 0) {\r
+ $this->errorstring = 'no nameservers';\r
+ return null;\r
+ }\r
+\r
+ for ($i = 0; $i < $this->retry; $i++, $retrans *= 2,\r
+ $timeout = (int) ($retrans / $ctr)) {\r
+ if ($timeout < 1) {\r
+ $timeout = 1;\r
+ }\r
+\r
+ foreach ($sock as $k => $s) {\r
+ if ($this->debug) {\r
+ echo ';; send_udp(' . $peerhost[$k] . ':' . $peerport[$k] . '): sending ' . strlen($packet_data) . " bytes\n";\r
+ }\r
+\r
+ if (! fwrite($s, $packet_data)) {\r
+ if ($this->debug) {\r
+ echo ";; send error\n";\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Here's where it get's really nasty. We don't have a select()\r
+ * function here, so we have to poll for a response... UGH!\r
+ */\r
+\r
+ $timetoTO = time() + (double)microtime() + $timeout;\r
+\r
+ /*\r
+ * let's sleep for a few hundred microseconds to let the\r
+ * data come in from the network...\r
+ */\r
+ usleep(500);\r
+ $buf = '';\r
+ while (! strlen($buf) && $timetoTO > (time() +\r
+ (double)microtime())) {\r
+ socket_set_blocking($s, false);\r
+ if ($buf = fread($s, 512)) {\r
+ $this->answerfrom = $peerhost[$k];\r
+ $this->answersize = strlen($buf);\r
+ if ($this->debug) {\r
+ echo ';; answer from ' . $peerhost[$k] . ':' .\r
+ $peerport[$k] . ': ' . strlen($buf) . " bytes\n";\r
+ }\r
+ $ans = new Net_DNS_Packet($this->debug);\r
+ if ($ans->parse($buf)) {\r
+ if ($ans->header->qr != '1') {\r
+ continue;\r
+ }\r
+ if ($ans->header->id != $packet->header->id) {\r
+ continue;\r
+ }\r
+ $this->errorstring = $ans->header->rcode;\r
+ $ans->answerfrom = $this->answerfrom;\r
+ $ans->answersize = $this->answersize;\r
+ return $ans;\r
+ }\r
+ }\r
+ // Sleep another 1/100th of a second... this sucks...\r
+ usleep(1000);\r
+ }\r
+\r
+ }\r
+ \r
+ $this->errorstring = 'query timed out';\r
+ return null;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::send_udp_with_sock_lib($packet, $packet_data) {{{ */\r
+ /**\r
+ * Sends a packet via UDP to the list of name servers.\r
+ *\r
+ * This function sends a packet to a nameserver. It is called by\r
+ * send_udp if the sockets PHP extension is compiled into PHP.\r
+ *\r
+ * @param string $packet A packet object to send to the NS list\r
+ * @param string $packet_data The data in the packet as returned by\r
+ * the Net_DNS_Packet::data() method\r
+ * @return object Net_DNS_Packet Returns an answer packet object\r
+ * @see Net_DNS_Resolver::send_tcp(), Net_DNS_Resolver::send(),\r
+ * Net_DNS_Resolver::send_udp(), Net_DNS_Resolver::send_udp_no_sock_lib()\r
+ */\r
+ function send_udp_with_sock_lib($packet, $packet_data)\r
+ {\r
+ $retrans = $this->retrans;\r
+ $timeout = $retrans;\r
+\r
+ //$w = error_reporting(0);\r
+ $ctr = 0;\r
+ // Create a socket handle for each nameserver\r
+ foreach ($this->nameservers as $nameserver) {\r
+ if ((($sock[$ctr++] = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) &&\r
+ socket_connect($sock[$ctr-1], $nameserver, $this->port))\r
+ {\r
+ $peerhost[$ctr-1] = $nameserver;\r
+ $peerport[$ctr-1] = $this->port;\r
+ socket_set_nonblock($sock[$ctr-1]);\r
+ } else {\r
+ $ctr--;\r
+ }\r
+ }\r
+ //error_reporting($w);\r
+\r
+ if ($ctr == 0) {\r
+ $this->errorstring = 'no nameservers';\r
+ return null;\r
+ }\r
+ // Try each nameserver up to $this->retry times\r
+ for ($i = 0; $i < $this->retry; $i++) {\r
+ if ($i != 0) {\r
+ // Set the timeout for each retry based on the number of\r
+ // nameservers there is a connected socket for.\r
+ $retrans *= 2;\r
+ $timeout = (int) ($retrans / $ctr);\r
+ }\r
+ // Make sure the timeout is at least 1 second\r
+ if ($timeout < 1) {\r
+ $timeout = 1;\r
+ }\r
+\r
+ // Try each nameserver\r
+ foreach ($sock as $k => $s) {\r
+ if ($this->debug) {\r
+ echo "\n;; send_udp(" . $peerhost[$k] . ':' . $peerport[$k] . '): sending ' . strlen($packet_data) . " bytes\n";\r
+ }\r
+\r
+ if (! socket_write($s, $packet_data)) {\r
+ if ($this->debug) {\r
+ echo ";; send error\n";\r
+ }\r
+ }\r
+\r
+ $set = array($s);\r
+ if ($this->debug) {\r
+ echo ";; timeout set to $timeout seconds\n";\r
+ }\r
+ $changed = socket_select($set, $w = null, $e = null, $timeout);\r
+ if ($changed) {\r
+ // Test to see if the connection was refused. Linux servers will send\r
+ // an ICMP message which will cause the client's next system call to\r
+ // return ECONNREFUSED if the server is not listening on the ip:port queried\r
+ if (socket_get_option($s, SOL_SOCKET, SO_ERROR) == SOCKET_ECONNREFUSED) {\r
+ // Unix socket connection was refused\r
+ if ($this->debug) {\r
+ echo ';; connection to ' . $peerhost[$k] . ':' . $peerport[$k] . " was refused\n";\r
+ }\r
+ // Try the next server.\r
+ continue;\r
+ }\r
+\r
+ // Read the response\r
+ $buf = @socket_read($s, 512);\r
+ if ($buf === false) {\r
+ // No data could be read from socket\r
+ if ($this->debug) {\r
+ echo ';; no data could be read from ' . $peerhost[$k] . ':' . $peerport[$k] . "\n";\r
+ echo ';; socket_error: ' . socket_strerror(socket_last_error()) . "\n";\r
+ }\r
+ // Reset the non-specific socket error status\r
+ socket_clear_error();\r
+ // Try the next server.\r
+ continue;\r
+ }\r
+\r
+ $this->answerfrom = $peerhost[$k];\r
+ $this->answersize = strlen($buf);\r
+ if ($this->debug) {\r
+ echo ';; answer from ' . $peerhost[$k] . ':' .\r
+ $peerport[$k] . ': ' . strlen($buf) . " bytes\n";\r
+ }\r
+ $ans = new Net_DNS_Packet($this->debug);\r
+ if ($ans->parse($buf)) {\r
+ if ($ans->header->qr != '1') {\r
+ // Ignore packet if it is not a response\r
+ continue;\r
+ } elseif ($ans->header->id != $packet->header->id) {\r
+ // Ignore packet if the response id does not match the query id\r
+ continue;\r
+ } else {\r
+ // Return the DNS response packet\r
+ $this->errorstring = $ans->header->rcode;\r
+ $ans->answerfrom = $this->answerfrom;\r
+ $ans->answersize = $this->answersize;\r
+ return $ans;\r
+ }\r
+ }\r
+ } elseif ($this->debug) {\r
+ echo ";; query to ". $peerhost[$k] . ':' . $peerport[$k] . " timed out\n";\r
+ }\r
+ }\r
+ }\r
+ $this->errorstring = 'query timed out';\r
+ return null;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::send_udp($packet, $packet_data) {{{ */\r
+ /**\r
+ * Sends a packet via UDP to the list of name servers.\r
+ *\r
+ * This function sends a packet to a nameserver. send_udp calls\r
+ * either Net_DNS_Resolver::send_udp_no_sock_lib() or\r
+ * Net_DNS_Resolver::send_udp_with_sock_lib() depending on whether or\r
+ * not the sockets extension is compiled into PHP. Note that using the\r
+ * sockets extension is MUCH more efficient.\r
+ *\r
+ * @param object Net_DNS_Packet $packet A packet object to send to the NS list\r
+ * @param string $packet_data The data in the packet as returned by\r
+ * the Net_DNS_Packet::data() method\r
+ * @return object Net_DNS_Packet Returns an answer packet object\r
+ * @see Net_DNS_Resolver::send_tcp(), Net_DNS_Resolver::send(),\r
+ * Net_DNS_Resolver::send_udp(), Net_DNS_Resolver::send_udp_no_sock_lib()\r
+ */\r
+ function send_udp($packet, $packet_data)\r
+ {\r
+ if (extension_loaded('sockets') && $this->useEnhancedSockets) {\r
+ if ($this->debug) {\r
+ echo "\n;; using extended PHP sockets\n";\r
+ }\r
+ return $this->send_udp_with_sock_lib($packet, $packet_data);\r
+ } else {\r
+ if ($this->debug) {\r
+ echo "\n;; using simple sockets\n";\r
+ }\r
+ return $this->send_udp_no_sock_lib($packet, $packet_data);\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::make_query_packet($packetORname, $type = '', $class = '') {{{ */\r
+ /**\r
+ * Unknown\r
+ */\r
+ function make_query_packet($packetORname, $type = '', $class = '')\r
+ {\r
+ if (is_object($packetORname) && strcasecmp(get_class($packetORname), 'net_dns_packet') == 0) {\r
+ $packet = $packetORname;\r
+ } else {\r
+ $name = $packetORname;\r
+ if ($type == '') {\r
+ $type = 'A';\r
+ }\r
+ if ($class == '') {\r
+ $class = 'IN';\r
+ }\r
+\r
+ /*\r
+ * If the name looks like an IP address then do an appropriate\r
+ * PTR query.\r
+ */\r
+ if (preg_match('/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/', $name, $regs)) {\r
+ $name = $regs[4].'.'.$regs[3].'.'.$regs[2].'.'.$regs[1].'.in-addr.arpa.';\r
+ $type = 'PTR';\r
+ }\r
+\r
+ if ($this->debug) {\r
+ echo ";; query($name, $type, $class)\n";\r
+ }\r
+ $packet = new Net_DNS_Packet($this->debug);\r
+ $packet->buildQuestion($name, $type, $class);\r
+ }\r
+\r
+ $packet->header->rd = $this->recurse;\r
+ return $packet;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::axfr_old($dname, $class = 'IN') {{{ */\r
+ /**\r
+ * Performs an AXFR query (zone transfer) (OLD BUGGY STYLE)\r
+ *\r
+ * This is deprecated and should not be used!\r
+ *\r
+ * @param string $dname The domain (zone) to transfer\r
+ * @param string $class The class in which to look for the zone.\r
+ * @return object Net_DNS_Packet\r
+ * @access public\r
+ */\r
+ function axfr_old($dname, $class = 'IN')\r
+ {\r
+ return $this->axfr($dname, $class, true);\r
+ }\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::axfr($dname, $class = 'IN', $old = false) {{{ */\r
+ /**\r
+ * Performs an AXFR query (zone transfer)\r
+ *\r
+ * Requests a zone transfer from the nameservers. Note that zone\r
+ * transfers will ALWAYS use TCP regardless of the setting of the\r
+ * Net_DNS_Resolver::$usevc flag. If $old is set to true, Net_DNS requires\r
+ * a nameserver that supports the many-answers style transfer format. Large\r
+ * zone transfers will not function properly. Setting $old to true is _NOT_\r
+ * recommended and should only be used for backwards compatibility.\r
+ *\r
+ * @param string $dname The domain (zone) to transfer\r
+ * @param string $class The class in which to look for the zone.\r
+ * @param boolean $old Requires 'old' style many-answer format to function.\r
+ Used for backwards compatibility only.\r
+ * @return object Net_DNS_Packet\r
+ * @access public\r
+ */\r
+ function axfr($dname, $class = 'IN', $old = false)\r
+ {\r
+ if ($old) {\r
+ if ($this->debug) {\r
+ echo ";; axfr_start($dname, $class)\n";\r
+ }\r
+ if (! count($this->nameservers)) {\r
+ $this->errorstring = 'no nameservers';\r
+ if ($this->debug) {\r
+ echo ";; ERROR: no nameservers\n";\r
+ }\r
+ return null;\r
+ }\r
+ $packet = $this->make_query_packet($dname, 'AXFR', $class);\r
+ $packet_data = $packet->data();\r
+ $ans = $this->send_tcp($packet, $packet_data);\r
+ return $ans;\r
+ } else {\r
+ if ($this->axfr_start($dname, $class) === null) {\r
+ return null;\r
+ }\r
+ $ret = array();\r
+ while (($ans = $this->axfr_next()) !== null) {\r
+ if ($ans === null) {\r
+ return null;\r
+ }\r
+ array_push($ret, $ans);\r
+ }\r
+ return $ret;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::axfr_start($dname, $class = 'IN') {{{ */\r
+ /**\r
+ * Sends a packet via TCP to the list of name servers.\r
+ *\r
+ * @param string $packet A packet object to send to the NS list\r
+ * @param string $packet_data The data in the packet as returned by\r
+ * the Net_DNS_Packet::data() method\r
+ * @return object Net_DNS_Packet Returns an answer packet object\r
+ * @see Net_DNS_Resolver::send_tcp()\r
+ */\r
+ function axfr_start($dname, $class = 'IN')\r
+ {\r
+ if ($this->debug) {\r
+ echo ";; axfr_start($dname, $class)\n";\r
+ }\r
+\r
+ if (! count($this->nameservers)) {\r
+ $this->errorstring = "no nameservers";\r
+ if ($this->debug) {\r
+ echo ";; ERROR: axfr_start: no nameservers\n";\r
+ }\r
+ return null;\r
+ }\r
+ $packet = $this->make_query_packet($dname, "AXFR", $class);\r
+ $packet_data = $packet->data();\r
+\r
+ $timeout = $this->tcp_timeout;\r
+\r
+ foreach ($this->nameservers as $ns) {\r
+ $dstport = $this->port;\r
+ if ($this->debug) {\r
+ echo ";; axfr_start($ns:$dstport)\n";\r
+ }\r
+ $sock_key = "$ns:$dstport";\r
+ if (is_resource($this->sockets[$sock_key])) {\r
+ $sock = &$this->sockets[$sock_key];\r
+ } else {\r
+ if (! ($sock = fsockopen($ns, $dstport, $errno,\r
+ $errstr, $timeout))) {\r
+ $this->errorstring = "connection failed";\r
+ if ($this->debug) {\r
+ echo ";; ERROR: axfr_start: connection failed: $errstr\n";\r
+ }\r
+ continue;\r
+ }\r
+ $this->sockets[$sock_key] = $sock;\r
+ unset($sock);\r
+ $sock = &$this->sockets[$sock_key];\r
+ }\r
+ $lenmsg = pack("n", strlen($packet_data));\r
+ if ($this->debug) {\r
+ echo ";; sending " . strlen($packet_data) . " bytes\n";\r
+ }\r
+\r
+ if (($sent = fwrite($sock, $lenmsg)) == -1) {\r
+ $this->errorstring = "length send failed";\r
+ if ($this->debug) {\r
+ echo ";; ERROR: axfr_start: length send failed\n";\r
+ }\r
+ continue;\r
+ }\r
+\r
+ if (($sent = fwrite($sock, $packet_data)) == -1) {\r
+ $this->errorstring = "packet send failed";\r
+ if ($this->debug) {\r
+ echo ";; ERROR: axfr_start: packet data send failed\n";\r
+ }\r
+ }\r
+\r
+ socket_set_timeout($sock, $timeout);\r
+\r
+ $this->_axfr_sock = $sock;\r
+ $this->_axfr_rr = array();\r
+ $this->_axfr_soa_count = 0;\r
+ return $sock;\r
+ }\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::axfr_next() {{{ */\r
+ /**\r
+ * Requests the next RR from a existing transfer started with axfr_start\r
+ *\r
+ * @return object Net_DNS_RR Returns a Net_DNS_RR object of the next RR\r
+ * from a zone transfer.\r
+ * @see Net_DNS_Resolver::send_tcp()\r
+ */\r
+ function axfr_next()\r
+ {\r
+ if (! count($this->_axfr_rr)) {\r
+ if (! isset($this->_axfr_sock) || ! is_resource($this->_axfr_sock)) {\r
+ $this->errorstring = 'no zone transfer in progress';\r
+ return null;\r
+ }\r
+ $timeout = $this->tcp_timeout;\r
+ $buf = $this->read_tcp($this->_axfr_sock, 2, $this->debug);\r
+ if (! strlen($buf)) {\r
+ $this->errorstring = 'truncated zone transfer';\r
+ return null;\r
+ }\r
+ $len = unpack('n1len', $buf);\r
+ $len = $len['len'];\r
+ if (! $len) {\r
+ $this->errorstring = 'truncated zone transfer';\r
+ return null;\r
+ }\r
+ $buf = $this->read_tcp($this->_axfr_sock, $len, $this->debug);\r
+ if ($this->debug) {\r
+ echo ';; received ' . strlen($buf) . "bytes\n";\r
+ }\r
+ if (strlen($buf) != $len) {\r
+ $this->errorstring = 'expected ' . $len . ' bytes, received ' . strlen($buf);\r
+ if ($this->debug) {\r
+ echo ';; ' . $err . "\n";\r
+ }\r
+ return null;\r
+ }\r
+ $ans = new Net_DNS_Packet($this->debug);\r
+ if (! $ans->parse($buf)) {\r
+ if (! $this->errorstring) {\r
+ $this->errorstring = 'unknown error during packet parsing';\r
+ }\r
+ return null;\r
+ }\r
+ if ($ans->header->ancount < 1) {\r
+ $this->errorstring = 'truncated zone transfer';\r
+ return null;\r
+ }\r
+ if ($ans->header->rcode != 'NOERROR') {\r
+ $this->errorstring = 'errorcode ' . $ans->header->rcode . ' returned';\r
+ return null;\r
+ }\r
+ foreach ($ans->answer as $rr) {\r
+ if ($rr->type == 'SOA') {\r
+ if (++$this->_axfr_soa_count < 2) {\r
+ array_push($this->_axfr_rr, $rr);\r
+ }\r
+ } else {\r
+ array_push($this->_axfr_rr, $rr);\r
+ }\r
+ }\r
+ if ($this->_axfr_soa_count >= 2) {\r
+ unset($this->_axfr_sock);\r
+ }\r
+ }\r
+ $rr = array_shift($this->_axfr_rr);\r
+ return $rr;\r
+ }\r
+\r
+ /* }}} */\r
+ /* Net_DNS_Resolver::read_tcp() {{{ */\r
+ /**\r
+ * Unknown - not ported yet\r
+ */\r
+ function read_tcp($sock, $nbytes, $debug = 0)\r
+ {\r
+ $buf = '';\r
+ while (strlen($buf) < $nbytes) {\r
+ $nread = $nbytes - strlen($buf);\r
+ $read_buf = '';\r
+ if ($debug) {\r
+ echo ";; read_tcp: expecting $nread bytes\n";\r
+ }\r
+ $read_buf = fread($sock, $nread);\r
+ if (! strlen($read_buf)) {\r
+ if ($debug) {\r
+ echo ";; ERROR: read_tcp: fread failed\n";\r
+ }\r
+ break;\r
+ }\r
+ if ($debug) {\r
+ echo ';; read_tcp: received ' . strlen($read_buf) . " bytes\n";\r
+ }\r
+ if (!strlen($read_buf)) {\r
+ break;\r
+ }\r
+\r
+ $buf .= $read_buf;\r
+ }\r
+ return $buf;\r
+ }\r
+ /* }}} */\r
+}\r
+/* }}} */\r
+/* VIM settings {{{\r
+ * Local variables:\r
+ * tab-width: 4\r
+ * c-basic-offset: 4\r
+ * soft-stop-width: 4\r
+ * c indent on\r
+ * expandtab on\r
+ * End:\r
+ * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et\r
+ * vim<600: sw=4 ts=4\r
+ * }}} */\r
+?>\r
<?php
+
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-// +----------------------------------------------------------------------+
-// | PEAR::Net_DNSBL |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 2004 Sebastian Nohn <sebastian@nohn.net> |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available through the world-wide-web at the following url: |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Sebastian Nohn <sebastian@nohn.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id: DNSBL.php,v 1.4 2004/12/02 14:23:51 nohn Exp $
/**
* PEAR::Net_DNSBL
* This class acts as interface to generic Realtime Blocking Lists
* (RBL)
*
- * Net_RBL looks up an supplied host if it's listed in 1-n supplied
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.01 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_01.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * Net_DNSBL looks up an supplied host if it's listed in 1-n supplied
* Blacklists
*
- * @author Sebastian Nohn <sebastian@nohn.net>
- * @package Net_DNSBL
- * @license http://www.php.net/license/3_0.txt
- * @version 0.5.3
+ * @category Net
+ * @package DNSBL
+ * @author Sebastian Nohn <sebastian@nohn.net>
+ * @author Ammar Ibrahim <fixxme@fixme.com>
+ * @copyright 2004-2007 Sebastian Nohn <sebastian@nohn.net>
+ * @license http://www.php.net/license/3_01.txt PHP License 3.01
+ * @version CVS: $Id: DNSBL.php,v 1.4 2006/12/25 10:40:59 nohn Exp $
+ * @link http://pear.php.net/package/Net_DNSBL
+ * @see Net_DNS
+ * @since File available since Release 1.0.0
*/
-require_once dirname(__FILE__) . '/CheckIP.php';
+
+require_once 'Net/CheckIP.php';
+require_once 'Net/DNS.php';
class Net_DNSBL {
* @var array
* @access protected
*/
- var $blacklists = array('sbl-xbl.spamhaus.net',
+ var $blacklists = array('sbl-xbl.spamhaus.org',
'bl.spamcop.net');
+ /**
+ * Array of Results
+ *
+ * @var array
+ * @access protected
+ */
+ var $results = array();
+
/**
* Set the blacklist to a desired blacklist.
*
return $this->blacklists;
}
+ /**
+ * Returns Blacklist and Reply from the Blacklist, a host is listed in.
+ *
+ * @param string Host to check
+ * @access public
+ * @return array result. $result['dnsbl'] contains DNSBL,
+ * $result['record'] contains returned DNS record.
+ */
+ function getDetails($host)
+ {
+ if (isset($this->results[$host]['dnsbl'])) {
+ return $this->results[$host];
+ } else {
+ return false;
+ }
+ } // function
+
+ /**
+ * Returns Blacklist, host is listed in.
+ *
+ * @param string Host to check
+ * @access public
+ * @return bl, a host is listed in or false
+ */
+ function getListingBl($host)
+ {
+ if (isset($this->results[$host]['dnsbl'])) {
+ return $this->results[$host]['dnsbl'];
+ } else {
+ return false;
+ }
+ } // function
+
+ /**
+ * Returns result, when a host is listed.
+ *
+ * @param string Host to check
+ * @access public
+ * @return bl, a host is listed in or false
+ */
+ function getListingRecord($host)
+ {
+ if (isset($this->results[$host]['record'])) {
+ return $this->results[$host]['record'];
+ } else {
+ return false;
+ }
+ } // function
+
+ /**
+ * Returns TXT-Records, when a host is listed.
+ *
+ * @param string Host to check
+ * @access public
+ * @return array TXT-Records for this host
+ */
+ function getTxt($host)
+ {
+ if (isset($this->results[$host]['txt'])) {
+ return $this->results[$host]['txt'];
+ } else {
+ return false;
+ }
+ } // function
+
/**
* Checks if the supplied Host is listed in one or more of the
* RBLs.
*/
function isListed($host)
{
-
$isListed = false;
-
+ $resolver = new Net_DNS_Resolver;
+
foreach ($this->blacklists as $blacklist) {
- $result = gethostbyname($this->getHostForLookup($host, $blacklist));
- if ($result != $this->getHostForLookup($host, $blacklist)) {
+ $response = $resolver->query($this->getHostForLookup($host, $blacklist));
+ if ($response) {
$isListed = true;
-
+ $this->results[$host]['dnsbl'] = $blacklist;
+ $this->results[$host]['record'] = $response->answer[0]->address;
+ $response_txt = $resolver->query($this->getHostForLookup($host, $blacklist), 'TXT');
+ foreach ($response_txt->answer as $txt) {
+ $this->results[$host]['txt'][] = $txt->text[0];
+ }
//if the Host was listed we don't need to check other RBLs,
break;
{
// Currently only works for v4 addresses.
if (!Net_CheckIP::check_ip($host)) {
- $ip = gethostbyname($host);
+ $resolver = new Net_DNS_Resolver;
+ $response = $resolver->query($host);
+ $ip = $response->answer[0]->address;
} else {
$ip = $host;
}
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-// +----------------------------------------------------------------------+
-// | PEAR::Net_DNSBL_SURBL |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 2004 Sebastian Nohn <sebastian@nohn.net> |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available through the world-wide-web at the following url: |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Sebastian Nohn <sebastian@nohn.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id: SURBL.php,v 1.4 2004/12/02 14:23:51 nohn Exp $
+
+/**
+ * PEAR::Net_DNSBL
+ *
+ * This class acts as interface to generic Realtime Blocking Lists
+ * (RBL)
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.01 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_01.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * Net_DNSBL looks up an supplied host if it's listed in 1-n supplied
+ * Blacklists
+ *
+ * @category Net
+ * @package DNSBL
+ * @author Sebastian Nohn <sebastian@nohn.net>
+ * @author Ammar Ibrahim <fixxme@fixme.com>
+ * @copyright 2004-2007 Sebastian Nohn <sebastian@nohn.net>
+ * @license http://www.php.net/license/3_01.txt PHP License 3.01
+ * @version CVS: $Id: SURBL.php,v 1.4 2006/12/25 10:40:59 nohn Exp $
+ * @link http://pear.php.net/package/Net_DNSBL
+ * @see Net_DNS
+ * @since File available since Release 1.0.0
+ */
+
+require_once 'Cache/Lite.php';
+require_once 'HTTP/Request.php';
+require_once 'Net/CheckIP.php';
+require_once 'Net/DNSBL.php';
/**
* PEAR::Net_DNSBL_SURBL
*
* @author Sebastian Nohn <sebastian@nohn.net>
* @package Net_DNSBL
- * @license http://www.php.net/license/3_0.txt
- * @version 0.5.4
+ * @license http://www.php.net/license/3_01.txt
+ * @version 1.2.0
*/
-require_once dirname(__FILE__) . '/../../Cache/Lite.php';
-require_once dirname(__FILE__) . '/../../HTTP/Request.php';
-require_once dirname(__FILE__) . '/../CheckIP.php';
-require_once dirname(__FILE__) . '/../DNSBL.php';
class Net_DNSBL_SURBL extends Net_DNSBL {
array_shift($host_elements);
} // while
$host_3_elements = implode('.', $host_elements);
-
+
$host_elements = explode('.', $host);
while (count($host_elements) > 2) {
array_shift($host_elements);
} // while
$host_2_elements = implode('.', $host_elements);
-
+
// (3b) IS_FQDN Check if is in "CC-2-level-TLD"
if ($this->isDoubleCcTld($host_2_elements)) {
// (3b1) IS_IN_2LEVEL: we want the last three names
$host .= '.'.$blacklist;
return $host;
} // function
-
+
} // class
?>
\ No newline at end of file