"PHPresolver" - PHP DNS resolver library

PHPresolver class library reference

version 1.1
Copyright(c) 2001, 2002 Moriyoshi Koizumi. All Rights Reserved.



class DNSResolver

DNS resolver object.

constructor

DNSResolver( string nameserver [, int port] [, int timeout] )

[parameters]
nameserver
specifies a domain name or an IP address of the domain name server(DNS) used for domain name resolution.
port (optional)
specifies the number of the port that accepts DNS service. Default value is 53.
timeout (optional)
specifies the connection timeout in nano seconds. default value is 10000000 (1 second).

methods

DNSAnswer sendQuery( DNSQuery dnsquery [, boolean useTCP] )

[parameters]
dnsquery
specifies an DNSQuery object which contains information to query to the name server.
useTCP (optional)
This flag forces the resolver to use TCP connection for querying a server. By default it uses UDP connection and switches to use TCP when it is necessary.
[return value]
A DNSAnswer Object

class DNSName

The object that holds a series of subdomains, i.e. a domain name.

constructor

DNSName( array labels )

[parameters]
labels
An array of sub-domain strings. For example, domain name "a.b.c" is represented as:
array[0] => 'a'
array[1] => 'b'
array[2] => 'c'
array[3] => '' (void string)
[note]
Literal IP addresses should be represented as subdomains of ARPA domain.

methods

DNSName DNSName::newFromString( string domainname )

[parameters]
domainname
specifies a domain name which will be converted into an DNSName object.
Acceptable formats are listed below;
192.168.0.1 (literal IPv4 address format)
1.0.168.192.IN-ADDR.ARPA (defined in RFC1035; the value is same as above)
www.example.com (generic domain name)
ffff:0:4567:89ab:fdfa:132:0:413 (literal IPv6 address format)
3.1.4.0.0.0.0.0.a.f.d.f.b.a.9.8.7.6.5.4.3.2.1.0.f.f.f.f.IP6.ARPA (defined in RFC1886; same as above)
ffff::192.168.0.1 (literal IPv6 address format)

and those formats are currently unsupported;
\[xffff0123456789abfdfa013200000413/128].IP6.ARPA (defined in RFC2874)
\[x89abfdfa013200000413/80].\[xffff01234567/48].IP6.ARPA (same as above)
[return value]
an DNSName Object

boolean isRealDomainName()

[parameters]
none
[return value]
true if the domain name this object represents does not belong to ARPA domain.

string asOctets()

[parameters]
None
[return value]
Binary representation of sub-domains.

string getCanonicalName()

[parameters]
None
[return value]
String representation of sub-domains.

class DNSAnswer

The object that holds responses from the name server.

constructor

DNSAnswer( int stream, int limit )

[parameters]
stream
specifies file pointer returned by fsockopen.
limit
specifies the maximum number of bytes to read from the stream.
[note]
This object should be created via DNSResolver::sendQuery() method. To directly instantiate this object with a new operator is not a generic way.
If the actual message length is found exceeding the limit length while reading the response message stream, the rest would be ignored and the parser would return an error status.

fields

result_code
result code returned by the name server. the value has following meanings: (mostly cited from RFC1035)
value meaning description
0 no error condition
The query was successfully accepted and interpreted by the name server.
1 format error The name server was unable to interpret the query.
2 server failure
The name server was unable to process this query due to a problem with the name server.
3 name error
Meaningful only for responses from an authoritative name server, this code signifies that the domain name referenced in the query does not exist.
4 not implemented
The name server does not support the requested kind of query.
5 refused
The name server refuses to perform the specified operation for policy reasons. For example, a name server may not wish to provide the information to the particular requester, or a name server may not wish to perform a particular operation (e.g., zone transfer) for particular data.
6-15 reserved Reserved for future use.
flags
flags.
rec_query
an array of DNSRecord objects that hold the same query record as given to DNSQuery object.
rec_answer
an array of DNSRecord objects that hold ANSWER records returned by the name server.
rec_authority
an array of DNSRecord objects that hold AUTHORITY records returned by the name server.
rec_additional
an array of DNSRecord objects that hold ADDITIONAL records returned by the name server.

class DNSQuery

The object that holds a query to ask the name server.

constructor

DNSQuery( DNSRecord dnsrecord [, int flags ] )

[parameters]
dnsrecord
specifies a query to ask the name server that is described by a DNSRecord object.
flag
specifies the quering option flags. The flags consists of following bitfields:
name description
DNS_HEADERSPEC_RECURSION_DESIRED (default) If set, it directs the name server to pursue the query recursively over the reachable name servers. This bit is copied into the query record of response message.

methods

string asOctets()

[parameters]
none
[return value]
binary representation of the query.

class DNSRecord

The object that represents a RECORD, a unit of meaningful information to be exchanged between the name server and the client.

constructor

DNSRecord( DNSName name, int type [, int dclass] [, int ttl] [, array specific_fields] )

[parameters]
name
DNSName object for a domain name
type
DNS record type.
value meaning
DNS_RECORDTYPE_A a host address
DNS_RECORDTYPE_NS an authoritative name server
DNS_RECORDTYPE_CNAME an alias
DNS_RECORDTYPE_SOA start of authority zone
DNS_RECORDTYPE_PTR a domain name pointer
DNS_RECORDTYPE_MX mail exchange
DNS_RECORDTYPE_AAAA a IPv6 host address
DNS_RECORDTYPE_ANY (used only for querying) to retrieve any records associated with the name
dclass (optional)
This must be the value of DNS_CLASS_INTERNET.
ttl (optional)
(abbreviation for time-to-live) The period in seconds during which the (retrieved) information should be cached. the value 0 means that no cache is to be performed.
specific_fields (optional)
Type-specific fields.

fields

name
type
dclass
ttl
see the "constructor" section.
specific_fields
An associative array of type-specific fields.
key name type value
address DNS_RECORDTYPE_A
DNS_RECORDTYPE_AAAA
A DNSName object that represents an IP address.
dname DNS_RECORDTYPE_PTR
DNS_RECORDTYPE_NS
DNS_RECORDTYPE_CNAME
A DNSName object that represents a domain name.
preference DNS_RECORDTYPE_MX An integer value that specifies how much preferred the host is for mail exchange among others. The lower value means the stronger preference.
exchange DNS_RECORDTYPE_MX A DNSName object that represents the domain name of the host to use for mail exchange.
resp_person DNS_RECORDTYPE_SOA The mail address of the person responsible for this zone.
source DNS_RECORDTYPE_SOA A DNSName object that specifies the domain name of the master name server, from which the zone information is transferred.
serial DNS_RECORDTYPE_SOA An integer value with which the slave(secondary) server identifies the revision of the zone information transferred from the master(primary) name server.
refresh DNS_RECORDTYPE_SOA An integer value that specifies in seconds the interval after which the slaveserver tries to check the master name server for the updated zone information.
retry DNS_RECORDTYPE_SOA An integer value that specifies in seconds the interval after which the slave server retries zone transfer when the previous try failed.
expire DNS_RECORDTYPE_SOA An integer value that specifies in seconds the period during which the slave server sees the zone information is valid. After the expiry, the server will stop sending any records of the zone in response to the queries until the entire zone information is updated.
minttl DNS_RECORDTYPE_SOA An integer value that specifies in seconds the minimum time the DNS records should be cached for.

methods

mixed getTypeSpecificField( string name )

[parameters]
name
specifies a field name. The acceptable names depend on the record type.
[return value]
Value of the field.