cvs: peardoc /en/package networking.xml /en/package/networking net-dns.xml /en/package/networking/net-dns/net-dns-resolver query.xml
| From: | Eric Kilfoil | Date: | Sun, 10 Apr 2005 17:25:42 +0000 |
| Subject: | cvs: peardoc /en/package networking.xml /en/package/networking net-dns.xml /en/package/networking/net-dns/net-dns-resolver query.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-5913@lists.php.net to get a copy of this message | ||
ekilfoil Sun Apr 10 13:25:42 2005 EDT
Modified files:
/peardoc/en/package networking.xml
/peardoc/en/package/networking net-dns.xml
/peardoc/en/package/networking/net-dns/net-dns-resolver query.xml
Log:
Initial Net_DNS documentation. No syntax errors reported locally.
http://cvs.php.net/diff.php/peardoc/en/package/networking.xml?r1=1.15&r2=1.16&ty=u Index: peardoc/en/package/networking.xml diff -u peardoc/en/package/networking.xml:1.15 peardoc/en/package/networking.xml:1.16 --- peardoc/en/package/networking.xml:1.15 Sun Nov 28 06:40:46 2004 +++ peardoc/en/package/networking.xml Sun Apr 10 13:25:40 2005 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.15 $ --> +<!-- $Revision: 1.16 $ --> <chapter id="package.networking"> <title>Networking</title> @@ -13,6 +13,7 @@ </sect1> &package.networking.net-checkip; + &package.networking.net-dns; &package.networking.net-dnsbl; &package.networking.net-finger; &package.networking.net-ftp; http://cvs.php.net/diff.php/peardoc/en/package/networking/net-dns.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/package/networking/net-dns.xml diff -u peardoc/en/package/networking/net-dns.xml:1.1 peardoc/en/package/networking/net-dns.xml:1.2 --- peardoc/en/package/networking/net-dns.xml:1.1 Sat Apr 9 13:52:05 2005 +++ peardoc/en/package/networking/net-dns.xml Sun Apr 10 13:25:42 2005 @@ -1,51 +1,60 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <sect1 id="package.networking.net-dns"> - <title>Net_DNS</title> - <para> - Provides methods for parsing and manipulating DNS packets as returned from - DNS servers and provides communication methods for sending and receiving DNS - packets. - </para> - &package.networking.net-dns.intro; - &package.networking.net-dns.example; - &package.networking.net-dns.constants; - <refentry id="package.networking.net-dns.net-dns-summary"> - <refnamediv> - <refname>Class Summary <classname>Net_DNS</classname></refname> - <refpurpose>PHP DNS Packet manipulation class</refpurpose> - </refnamediv> + <title>Net_DNS</title> + <para> + Provides methods for parsing and manipulating DNS packets as returned from + DNS servers and provides communication methods for sending and receiving + DNS packets. + </para> + &package.networking.net-dns.intro; + <refentry id="package.networking.net-dns.net-dns-summary"> + <refnamediv> + <refname>Class Summary <classname>Net_DNS</classname></refname> + <refpurpose>DNS Packet manipulation class</refpurpose> + </refnamediv> - <refsect1> - <title>PHP DNS Packet manipulation class</title> - <para> - This class includes sub-classses that provide methods for - creating, parsing, sending, and receving DNS nameserver - packets. - </para> - <para> - This class is only a container class and generally should - never be constructed. It contains constants defined in RFC - 1035 with methods for converting between the integer and the - name values of such constants. - </para> - </refsect1> - </refentry> - <refentry id="package.networking.net-dns.net-dns-resolver-summary"> - <refnamediv> - <refname> - Class Summary <classname>Net_DNS_Resolver</classname> - </refname> - <refpurpose> - Provides a resolver implementation to handle DNS queries - </refpurpose> - </refnamediv> - <refsect1> - <title> - Provides a resolver implementation to handle DNS queries - </title> - &package.networking.net-dns.net-dns-resolver.query; - </refsect1> - </refentry> + <refsect1> + <title>DNS Packet manipulation class</title> + <para> + This class includes sub-classses that provide methods for creating, + parsing, sending, and receving DNS nameserver packets. + </para> + <para> + This class is only a container class and generally should never be + constructed. It contains constants defined in RFC 1035 with methods for + converting between the integer and the name values of such constants. + </para> + <para> + For information on sending a basic query to a nameserver for a specific + record, see <link + linkend="package.networking.net-dns.net-dns-resolver.query">Net_DNS_Resolver::query()</link>. + </para> + </refsect1> + </refentry> + <refentry id="package.networking.net-dns.net-dns-resolver-summary"> + <refnamediv> + <refname> + Class Summary <classname>Net_DNS_Resolver</classname> + </refname> + <refpurpose> + Provides a resolver implementation to handle DNS queries + </refpurpose> + </refnamediv> + <refsect1> + <title>Net_DNS_Resolver</title> + <para> + The resolver class a high level interface for communicating with DNS + servers. It uses the UNIX system stub resolver configuration files (if + available) to configure the resolver. The resolver can also be configured + manually by overriding the system configuration. This is done by setting + the appropriate values in the Net_DNS_Resolver object. See <link + linkend="package.networking.net-dns.net-dns-resolver.query">Net_DNS_Resolver::query()</link> + for more information on the resolver configuration. + </para> + </refsect1> + </refentry> + &package.networking.net-dns.net-dns-resolver.query; + &package.networking.net-dns.net-dns-resolver.rawQuery; </sect1> <!-- Generated by phpDocumentor v 1.2.3 http://www.phpdoc.org --> <!-- Keep this comment at the end of the file http://cvs.php.net/diff.php/peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml diff -u peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml:1.1 peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml:1.2 --- peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml:1.1 Sat Apr 9 13:52:05 2005 +++ peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml Sun Apr 10 13:25:42 2005 @@ -1,36 +1,319 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.networking.net-dns.net-dns-resolver.query"> - <refnamediv> - <refname>Net_DNS_Resolver::query()</refname> - <refpurpose>Queries a nameserver and returns a response</refpurpose> - </refnamediv> - <refsynopsisdiv> - <funcsynopsis> - <funcsynopsisinfo> - require_once('Net/DNS.php'); - </funcsynopsisinfo> - <funcprototype> - <funcdef>string <function>query</function></funcdef> - <paramdef>string <parameter>$hostname</parameter></paramdef> - <paramdef>string <parameter>$type</parameter></paramdef> - <paramdef>string <parameter>$class</parameter></paramdef> - </funcprototype> - </funcsynopsis> - </refsynopsisdiv> - <refsect1 id="package.networking.net-dns.net-dns-resolver.query.desc"> - &title.desc; - <para> - Constructs a DNS query packet and forwards the query to a - nameserver configured in the system stub resolver (ie. - /etc/resolv.conf). When a response is received from the DNS - server, a fully populated Net_DNS_Packet object is returned that - represents the response. - </para> - </refsect1> - <refsect1 id="package.networking.net-dns.net-dns-resolver.query.note"> - &title.note; - ¬e.notstatic; - </refsect1> + <refnamediv> + <refname>Net_DNS_Resolver::query()</refname> + <refpurpose>Queries a nameserver and returns a response</refpurpose> + </refnamediv> + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo> + require_once('Net/DNS.php'); + </funcsynopsisinfo> + <funcprototype> + <funcdef>Net_DNS_Packet <function>Net_DNS_Resolver::query</function></funcdef> + <paramdef>string <parameter>$hostname</parameter></paramdef> + <paramdef>string <parameter><optional>$type = 'A'</optional></parameter></paramdef> + <paramdef>string <parameter><optional>$class = 'IN'</optional></parameter></paramdef> + </funcprototype> + </funcsynopsis> + </refsynopsisdiv> + <refsect1 id="package.networking.net-dns.net-dns-resolver.query.desc"> + &title.desc; + <para> + Constructs a DNS query packet and forwards the query to a + nameserver configured in the system stub resolver (ie. + /etc/resolv.conf). When a response is received from the DNS + server, a fully populated Net_DNS_Packet object is returned + that represents the response. + </para> + <para> + The resolver object contains many properties that control + that behaviour of the resolver. Some of these settings + are automatically read from the system resolver + configuration if available. On Linux/UNIX based systems, + this includes /etc/resolv.conf as well as various + environment variables. This configuration is done at the + time of object instantiation and can be overridden by + setting the appropriate object properties. + </para> + <para> + This function will only return a Net_DNS_Packet if the + ANSWER section contains resource records. Specifically, + if the ANCOUNT variable in the DNS packet header is 0, + query() will return FALSE. If you are expecting a + packet without resource records in the ANSWER section, + use <link + linkend="package.networking.net-dns.net-dns-resolver.rawQuery">Net_DNS_Resolver::rawQuery()</link>. + This is useful when doing manual recursion. + </para> + <para> + Resolver Configuration Object Properties: + <itemizedlist> + <listitem> + <para>array $nameservers</para> + <para> + An array of nameserver IP addresses that should be + queried. + </para> + </listitem> + <listitem> + <para>int $port</para> + <para> + The port on which nameservers should be queried. The default is 53. + </para> + </listitem> + <listitem> + <para>array $domain</para> + <para> + The domain in which the resolver client host resides. + </para> + </listitem> + <listitem> + <para>array $searchlist</para> + <para> + An array of strings containingg domains to apply to unqualified hosts + passed to the resolver. + </para> + </listitem> + <listitem> + <para>int $retry</para> + <para> + The number of seconds between retransmission of unaswered queries + </para> + </listitem> + <listitem> + <para>int $retrans</para> + <para> + The number of times unanswered requests should be retried + </para> + </listitem> + <listitem> + <para>int $recurse</para> + <para> + Sets the value of the RD (recursion desired) bit in the header. If the + RD bit is set to 0, the server will not perform recursion on the + request. + </para> + </listitem> + <listitem> + <para>int $usevc</para> + <para> + Whether or not to use TCP (Virtual Circuits) instead of UDP If set + to 0, UDP will be used unless TCP is required. TCP is required for + questions or responses greater than 512 bytes. + </para> + </listitem> + <listitem> + <para>int $debug</para> + <para> + If set to TRUE (non-zero), debugging code will be displayed as the + resolver makes the request. + </para> + </listitem> + </itemizedlist> + </para> + <para> + Environment Variables: + <itemizedlist> + <listitem> + <para>RES_NAMESERVERS</para> + <para> + Space separated list of nameserver IP addresses + to query + </para> + </listitem> + <listitem> + <para>RES_SEARCHLIST</para> + <para> + Space separated list of domain names to add to + unqualified search requests. + </para> + </listitem> + <listitem> + <para>LOCALDOMAIN</para> + <para> + The name of the domain + </para> + </listitem> + <listitem> + <para>RES_OPTIONS</para> + <para> + A space separated list of options formatted as: + </para> + <para> + optionname:value + </para> + <para> + If the value is ommited, the value defaults to 1 + (true). [optionname] corresponds to an object + property. + </para> + </listitem> + </itemizedlist> + </para> + </refsect1> + <refsect1 id="packages.networking.net-dns.net-dns-resolver.query.example"> + &title.example; + <example> + <title>Using <function>Net_DNS_Resolver::query</function></title> + <programlisting role="php"> + <![CDATA[ +<?php +require_once 'Net/DNS.php'; + +$resolver = new Net_DNS_Resolver(); +$response = $resolver->query('example.com'); +if ($response) { + foreach ($response->answer as $rr) { + $rr->display(); + } +} +?>]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +example.com. 129808 IN A 192.0.34.166]]> + </screen> + </example> + <para> + Example 1-2 shows a DNS query for an MX record. Note + that the IP address for the mail exchanger listed within + the zone is returned with the response in the additional + section. The second exchanger (that is not inside this + zone) is not listed. To receive this address, you must + perform another query specifically for the A record using + the returned hostname. + </para> + <example> + <title>Using <function>Net_DNS_Resolver::query</function> to look up an MX record</title> + <programlisting role="php"> + <![CDATA[ +<?php +require_once 'Net/DNS.php'; + +$resolver = new Net_DNS_Resolver(); +$response = $resolver->query('php.net', 'MX'); +if ($response) { + foreach ($response->answer as $rr) { + $rr->display(); + } + if (count($response->additional)) { + foreach ($response->additional as $rr) { + $rr->display(); + } + } +} +?> +]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +php.net. 86121 IN MX 15 smtp.osuosl.org. +php.net. 86121 IN MX 5 osu1.php.net. +osu1.php.net. 86121 IN A 140.211.166.39 +]]> + </screen> + </example> + <para> + Example 1-3 shows a more complex query with debugging + information enabled. Note that the usevc option is set + to TRUE. This forces the resolver to use TCP instead of + UDP. This can be seen in the debug output on the + send_tcp() line. + </para> + <example> + <title>Using <function>Net_DNS_Resolver::query</function> with specific nameservers and options</title> + <programlisting role="php"> + <![CDATA[ +<?php +require_once 'Net/DNS.php'; + +$resolver = new Net_DNS_Resolver(); +$resolver->debug = 1; // Turn on debugging output to show the query +$resolver->usevc = 1; // Force the use of TCP instead of UDP +$resolver->nameservers = array( // Set the IP addresses + '198.41.0.4', // of the nameservers + '192.228.79.201' // to query. + ); +$response = $resolver->query('example.com'); +if (! $response) { + echo "\n"; + echo "ANCOUNT is 0, therefore the query() 'failed'\n"; + echo "See Net_DNS_Resolver::rawQuery() to receive this packet\n"; +} +?>]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +;; query(example.com, A, IN) +;; send_tcp(198.41.0.4:53) +;; sending 29 bytes +;; received 517 bytes +;; HEADER SECTION +;; id = 58298 +;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1 +;; ra = 0 rcode = NOERROR +;; qdcount = 1 ancount = 0 nscount = 13 arcount = 15 + +;; QUESTION SECTION (1 record) +;; +;example.com. IN A + +;; ANSWER SECTION (0 records) + +;; AUTHORITY SECTION (13 records) +com. 172800 IN NS A.GTLD-SERVERS.NET. +com. 172800 IN NS G.GTLD-SERVERS.NET. +com. 172800 IN NS H.GTLD-SERVERS.NET. +com. 172800 IN NS C.GTLD-SERVERS.NET. +com. 172800 IN NS I.GTLD-SERVERS.NET. +com. 172800 IN NS B.GTLD-SERVERS.NET. +com. 172800 IN NS D.GTLD-SERVERS.NET. +com. 172800 IN NS L.GTLD-SERVERS.NET. +com. 172800 IN NS F.GTLD-SERVERS.NET. +com. 172800 IN NS J.GTLD-SERVERS.NET. +com. 172800 IN NS K.GTLD-SERVERS.NET. +com. 172800 IN NS E.GTLD-SERVERS.NET. +com. 172800 IN NS M.GTLD-SERVERS.NET. + +;; ADDITIONAL SECTION (15 records) +A.GTLD-SERVERS.NET. 172800 IN AAAA 2001:503:a83e::2:30 +A.GTLD-SERVERS.NET. 172800 IN A 192.5.6.30 +G.GTLD-SERVERS.NET. 172800 IN A 192.42.93.30 +H.GTLD-SERVERS.NET. 172800 IN A 192.54.112.30 +C.GTLD-SERVERS.NET. 172800 IN A 192.26.92.30 +I.GTLD-SERVERS.NET. 172800 IN A 192.43.172.30 +B.GTLD-SERVERS.NET. 172800 IN AAAA 2001:503:231d::2:30 +B.GTLD-SERVERS.NET. 172800 IN A 192.33.14.30 +D.GTLD-SERVERS.NET. 172800 IN A 192.31.80.30 +L.GTLD-SERVERS.NET. 172800 IN A 192.41.162.30 +F.GTLD-SERVERS.NET. 172800 IN A 192.35.51.30 +J.GTLD-SERVERS.NET. 172800 IN A 192.48.79.30 +K.GTLD-SERVERS.NET. 172800 IN A 192.52.178.30 +E.GTLD-SERVERS.NET. 172800 IN A 192.12.94.30 +M.GTLD-SERVERS.NET. 172800 IN A 192.55.83.30 + +ANCOUNT is 0, therefore the query() 'failed' +See Net_DNS_Resolver::rawQuery() to receive this packet +]]> + </screen> + </example> + </refsect1> + <refsect1 id="package.networking.net-dns.net-dns-resolver.query.note"> + &title.note; + ¬e.notstatic; + </refsect1> + + </refentry> <!-- Keep this comment at the end of the file Local variables: @@ -48,6 +331,6 @@ sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si -vim: et tw=78 syn=sgml +vim: et tw=60 syn=sgml vi: ts=1 sw=1 -->
http://cvs.php.net/diff.php/peardoc/en/package/networking.xml?r1=1.15&r2=1.16&ty=u Index: peardoc/en/package/networking.xml diff -u peardoc/en/package/networking.xml:1.15 peardoc/en/package/networking.xml:1.16 --- peardoc/en/package/networking.xml:1.15 Sun Nov 28 06:40:46 2004 +++ peardoc/en/package/networking.xml Sun Apr 10 13:25:40 2005 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.15 $ --> +<!-- $Revision: 1.16 $ --> <chapter id="package.networking"> <title>Networking</title> @@ -13,6 +13,7 @@ </sect1> &package.networking.net-checkip; + &package.networking.net-dns; &package.networking.net-dnsbl; &package.networking.net-finger; &package.networking.net-ftp; http://cvs.php.net/diff.php/peardoc/en/package/networking/net-dns.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/package/networking/net-dns.xml diff -u peardoc/en/package/networking/net-dns.xml:1.1 peardoc/en/package/networking/net-dns.xml:1.2 --- peardoc/en/package/networking/net-dns.xml:1.1 Sat Apr 9 13:52:05 2005 +++ peardoc/en/package/networking/net-dns.xml Sun Apr 10 13:25:42 2005 @@ -1,51 +1,60 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <sect1 id="package.networking.net-dns"> - <title>Net_DNS</title> - <para> - Provides methods for parsing and manipulating DNS packets as returned from - DNS servers and provides communication methods for sending and receiving DNS - packets. - </para> - &package.networking.net-dns.intro; - &package.networking.net-dns.example; - &package.networking.net-dns.constants; - <refentry id="package.networking.net-dns.net-dns-summary"> - <refnamediv> - <refname>Class Summary <classname>Net_DNS</classname></refname> - <refpurpose>PHP DNS Packet manipulation class</refpurpose> - </refnamediv> + <title>Net_DNS</title> + <para> + Provides methods for parsing and manipulating DNS packets as returned from + DNS servers and provides communication methods for sending and receiving + DNS packets. + </para> + &package.networking.net-dns.intro; + <refentry id="package.networking.net-dns.net-dns-summary"> + <refnamediv> + <refname>Class Summary <classname>Net_DNS</classname></refname> + <refpurpose>DNS Packet manipulation class</refpurpose> + </refnamediv> - <refsect1> - <title>PHP DNS Packet manipulation class</title> - <para> - This class includes sub-classses that provide methods for - creating, parsing, sending, and receving DNS nameserver - packets. - </para> - <para> - This class is only a container class and generally should - never be constructed. It contains constants defined in RFC - 1035 with methods for converting between the integer and the - name values of such constants. - </para> - </refsect1> - </refentry> - <refentry id="package.networking.net-dns.net-dns-resolver-summary"> - <refnamediv> - <refname> - Class Summary <classname>Net_DNS_Resolver</classname> - </refname> - <refpurpose> - Provides a resolver implementation to handle DNS queries - </refpurpose> - </refnamediv> - <refsect1> - <title> - Provides a resolver implementation to handle DNS queries - </title> - &package.networking.net-dns.net-dns-resolver.query; - </refsect1> - </refentry> + <refsect1> + <title>DNS Packet manipulation class</title> + <para> + This class includes sub-classses that provide methods for creating, + parsing, sending, and receving DNS nameserver packets. + </para> + <para> + This class is only a container class and generally should never be + constructed. It contains constants defined in RFC 1035 with methods for + converting between the integer and the name values of such constants. + </para> + <para> + For information on sending a basic query to a nameserver for a specific + record, see <link + linkend="package.networking.net-dns.net-dns-resolver.query">Net_DNS_Resolver::query()</link>. + </para> + </refsect1> + </refentry> + <refentry id="package.networking.net-dns.net-dns-resolver-summary"> + <refnamediv> + <refname> + Class Summary <classname>Net_DNS_Resolver</classname> + </refname> + <refpurpose> + Provides a resolver implementation to handle DNS queries + </refpurpose> + </refnamediv> + <refsect1> + <title>Net_DNS_Resolver</title> + <para> + The resolver class a high level interface for communicating with DNS + servers. It uses the UNIX system stub resolver configuration files (if + available) to configure the resolver. The resolver can also be configured + manually by overriding the system configuration. This is done by setting + the appropriate values in the Net_DNS_Resolver object. See <link + linkend="package.networking.net-dns.net-dns-resolver.query">Net_DNS_Resolver::query()</link> + for more information on the resolver configuration. + </para> + </refsect1> + </refentry> + &package.networking.net-dns.net-dns-resolver.query; + &package.networking.net-dns.net-dns-resolver.rawQuery; </sect1> <!-- Generated by phpDocumentor v 1.2.3 http://www.phpdoc.org --> <!-- Keep this comment at the end of the file http://cvs.php.net/diff.php/peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml diff -u peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml:1.1 peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml:1.2 --- peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml:1.1 Sat Apr 9 13:52:05 2005 +++ peardoc/en/package/networking/net-dns/net-dns-resolver/query.xml Sun Apr 10 13:25:42 2005 @@ -1,36 +1,319 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.networking.net-dns.net-dns-resolver.query"> - <refnamediv> - <refname>Net_DNS_Resolver::query()</refname> - <refpurpose>Queries a nameserver and returns a response</refpurpose> - </refnamediv> - <refsynopsisdiv> - <funcsynopsis> - <funcsynopsisinfo> - require_once('Net/DNS.php'); - </funcsynopsisinfo> - <funcprototype> - <funcdef>string <function>query</function></funcdef> - <paramdef>string <parameter>$hostname</parameter></paramdef> - <paramdef>string <parameter>$type</parameter></paramdef> - <paramdef>string <parameter>$class</parameter></paramdef> - </funcprototype> - </funcsynopsis> - </refsynopsisdiv> - <refsect1 id="package.networking.net-dns.net-dns-resolver.query.desc"> - &title.desc; - <para> - Constructs a DNS query packet and forwards the query to a - nameserver configured in the system stub resolver (ie. - /etc/resolv.conf). When a response is received from the DNS - server, a fully populated Net_DNS_Packet object is returned that - represents the response. - </para> - </refsect1> - <refsect1 id="package.networking.net-dns.net-dns-resolver.query.note"> - &title.note; - ¬e.notstatic; - </refsect1> + <refnamediv> + <refname>Net_DNS_Resolver::query()</refname> + <refpurpose>Queries a nameserver and returns a response</refpurpose> + </refnamediv> + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo> + require_once('Net/DNS.php'); + </funcsynopsisinfo> + <funcprototype> + <funcdef>Net_DNS_Packet <function>Net_DNS_Resolver::query</function></funcdef> + <paramdef>string <parameter>$hostname</parameter></paramdef> + <paramdef>string <parameter><optional>$type = 'A'</optional></parameter></paramdef> + <paramdef>string <parameter><optional>$class = 'IN'</optional></parameter></paramdef> + </funcprototype> + </funcsynopsis> + </refsynopsisdiv> + <refsect1 id="package.networking.net-dns.net-dns-resolver.query.desc"> + &title.desc; + <para> + Constructs a DNS query packet and forwards the query to a + nameserver configured in the system stub resolver (ie. + /etc/resolv.conf). When a response is received from the DNS + server, a fully populated Net_DNS_Packet object is returned + that represents the response. + </para> + <para> + The resolver object contains many properties that control + that behaviour of the resolver. Some of these settings + are automatically read from the system resolver + configuration if available. On Linux/UNIX based systems, + this includes /etc/resolv.conf as well as various + environment variables. This configuration is done at the + time of object instantiation and can be overridden by + setting the appropriate object properties. + </para> + <para> + This function will only return a Net_DNS_Packet if the + ANSWER section contains resource records. Specifically, + if the ANCOUNT variable in the DNS packet header is 0, + query() will return FALSE. If you are expecting a + packet without resource records in the ANSWER section, + use <link + linkend="package.networking.net-dns.net-dns-resolver.rawQuery">Net_DNS_Resolver::rawQuery()</link>. + This is useful when doing manual recursion. + </para> + <para> + Resolver Configuration Object Properties: + <itemizedlist> + <listitem> + <para>array $nameservers</para> + <para> + An array of nameserver IP addresses that should be + queried. + </para> + </listitem> + <listitem> + <para>int $port</para> + <para> + The port on which nameservers should be queried. The default is 53. + </para> + </listitem> + <listitem> + <para>array $domain</para> + <para> + The domain in which the resolver client host resides. + </para> + </listitem> + <listitem> + <para>array $searchlist</para> + <para> + An array of strings containingg domains to apply to unqualified hosts + passed to the resolver. + </para> + </listitem> + <listitem> + <para>int $retry</para> + <para> + The number of seconds between retransmission of unaswered queries + </para> + </listitem> + <listitem> + <para>int $retrans</para> + <para> + The number of times unanswered requests should be retried + </para> + </listitem> + <listitem> + <para>int $recurse</para> + <para> + Sets the value of the RD (recursion desired) bit in the header. If the + RD bit is set to 0, the server will not perform recursion on the + request. + </para> + </listitem> + <listitem> + <para>int $usevc</para> + <para> + Whether or not to use TCP (Virtual Circuits) instead of UDP If set + to 0, UDP will be used unless TCP is required. TCP is required for + questions or responses greater than 512 bytes. + </para> + </listitem> + <listitem> + <para>int $debug</para> + <para> + If set to TRUE (non-zero), debugging code will be displayed as the + resolver makes the request. + </para> + </listitem> + </itemizedlist> + </para> + <para> + Environment Variables: + <itemizedlist> + <listitem> + <para>RES_NAMESERVERS</para> + <para> + Space separated list of nameserver IP addresses + to query + </para> + </listitem> + <listitem> + <para>RES_SEARCHLIST</para> + <para> + Space separated list of domain names to add to + unqualified search requests. + </para> + </listitem> + <listitem> + <para>LOCALDOMAIN</para> + <para> + The name of the domain + </para> + </listitem> + <listitem> + <para>RES_OPTIONS</para> + <para> + A space separated list of options formatted as: + </para> + <para> + optionname:value + </para> + <para> + If the value is ommited, the value defaults to 1 + (true). [optionname] corresponds to an object + property. + </para> + </listitem> + </itemizedlist> + </para> + </refsect1> + <refsect1 id="packages.networking.net-dns.net-dns-resolver.query.example"> + &title.example; + <example> + <title>Using <function>Net_DNS_Resolver::query</function></title> + <programlisting role="php"> + <![CDATA[ +<?php +require_once 'Net/DNS.php'; + +$resolver = new Net_DNS_Resolver(); +$response = $resolver->query('example.com'); +if ($response) { + foreach ($response->answer as $rr) { + $rr->display(); + } +} +?>]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +example.com. 129808 IN A 192.0.34.166]]> + </screen> + </example> + <para> + Example 1-2 shows a DNS query for an MX record. Note + that the IP address for the mail exchanger listed within + the zone is returned with the response in the additional + section. The second exchanger (that is not inside this + zone) is not listed. To receive this address, you must + perform another query specifically for the A record using + the returned hostname. + </para> + <example> + <title>Using <function>Net_DNS_Resolver::query</function> to look up an MX record</title> + <programlisting role="php"> + <![CDATA[ +<?php +require_once 'Net/DNS.php'; + +$resolver = new Net_DNS_Resolver(); +$response = $resolver->query('php.net', 'MX'); +if ($response) { + foreach ($response->answer as $rr) { + $rr->display(); + } + if (count($response->additional)) { + foreach ($response->additional as $rr) { + $rr->display(); + } + } +} +?> +]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +php.net. 86121 IN MX 15 smtp.osuosl.org. +php.net. 86121 IN MX 5 osu1.php.net. +osu1.php.net. 86121 IN A 140.211.166.39 +]]> + </screen> + </example> + <para> + Example 1-3 shows a more complex query with debugging + information enabled. Note that the usevc option is set + to TRUE. This forces the resolver to use TCP instead of + UDP. This can be seen in the debug output on the + send_tcp() line. + </para> + <example> + <title>Using <function>Net_DNS_Resolver::query</function> with specific nameservers and options</title> + <programlisting role="php"> + <![CDATA[ +<?php +require_once 'Net/DNS.php'; + +$resolver = new Net_DNS_Resolver(); +$resolver->debug = 1; // Turn on debugging output to show the query +$resolver->usevc = 1; // Force the use of TCP instead of UDP +$resolver->nameservers = array( // Set the IP addresses + '198.41.0.4', // of the nameservers + '192.228.79.201' // to query. + ); +$response = $resolver->query('example.com'); +if (! $response) { + echo "\n"; + echo "ANCOUNT is 0, therefore the query() 'failed'\n"; + echo "See Net_DNS_Resolver::rawQuery() to receive this packet\n"; +} +?>]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +;; query(example.com, A, IN) +;; send_tcp(198.41.0.4:53) +;; sending 29 bytes +;; received 517 bytes +;; HEADER SECTION +;; id = 58298 +;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1 +;; ra = 0 rcode = NOERROR +;; qdcount = 1 ancount = 0 nscount = 13 arcount = 15 + +;; QUESTION SECTION (1 record) +;; +;example.com. IN A + +;; ANSWER SECTION (0 records) + +;; AUTHORITY SECTION (13 records) +com. 172800 IN NS A.GTLD-SERVERS.NET. +com. 172800 IN NS G.GTLD-SERVERS.NET. +com. 172800 IN NS H.GTLD-SERVERS.NET. +com. 172800 IN NS C.GTLD-SERVERS.NET. +com. 172800 IN NS I.GTLD-SERVERS.NET. +com. 172800 IN NS B.GTLD-SERVERS.NET. +com. 172800 IN NS D.GTLD-SERVERS.NET. +com. 172800 IN NS L.GTLD-SERVERS.NET. +com. 172800 IN NS F.GTLD-SERVERS.NET. +com. 172800 IN NS J.GTLD-SERVERS.NET. +com. 172800 IN NS K.GTLD-SERVERS.NET. +com. 172800 IN NS E.GTLD-SERVERS.NET. +com. 172800 IN NS M.GTLD-SERVERS.NET. + +;; ADDITIONAL SECTION (15 records) +A.GTLD-SERVERS.NET. 172800 IN AAAA 2001:503:a83e::2:30 +A.GTLD-SERVERS.NET. 172800 IN A 192.5.6.30 +G.GTLD-SERVERS.NET. 172800 IN A 192.42.93.30 +H.GTLD-SERVERS.NET. 172800 IN A 192.54.112.30 +C.GTLD-SERVERS.NET. 172800 IN A 192.26.92.30 +I.GTLD-SERVERS.NET. 172800 IN A 192.43.172.30 +B.GTLD-SERVERS.NET. 172800 IN AAAA 2001:503:231d::2:30 +B.GTLD-SERVERS.NET. 172800 IN A 192.33.14.30 +D.GTLD-SERVERS.NET. 172800 IN A 192.31.80.30 +L.GTLD-SERVERS.NET. 172800 IN A 192.41.162.30 +F.GTLD-SERVERS.NET. 172800 IN A 192.35.51.30 +J.GTLD-SERVERS.NET. 172800 IN A 192.48.79.30 +K.GTLD-SERVERS.NET. 172800 IN A 192.52.178.30 +E.GTLD-SERVERS.NET. 172800 IN A 192.12.94.30 +M.GTLD-SERVERS.NET. 172800 IN A 192.55.83.30 + +ANCOUNT is 0, therefore the query() 'failed' +See Net_DNS_Resolver::rawQuery() to receive this packet +]]> + </screen> + </example> + </refsect1> + <refsect1 id="package.networking.net-dns.net-dns-resolver.query.note"> + &title.note; + ¬e.notstatic; + </refsect1> + + </refentry> <!-- Keep this comment at the end of the file Local variables: @@ -48,6 +331,6 @@ sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si -vim: et tw=78 syn=sgml +vim: et tw=60 syn=sgml vi: ts=1 sw=1 -->