Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to use Domain Name Resolution

[Top]


Overview

The TCP/IP stack contains a domain name full resolver service. Client programs make DNS queries through the generic host name resolution interface RHostResolver, specifying protocol-specific behaviour through argument values. This section contains notes on the particular usage of RHostResolver functions for DNS. It does not repeat the information contained in the documentation for RHostResolver, to which you should always refer first.

RHostResolver is defined in es_sock.h. Types and constants specific to TCP/IP that are used in RHostResolver arguments are defined in in_sock.h.

[Top]


Opening and closing

DNS access is initialised with RHostResolver::Open().

The argument values are:

addrFamily

Always KAfInet

aProtocol

Always KProtocolInetUdp

When DNS is no longer needed, access should be closed using RHostResolver::Close().

[Top]


Queries


Overview

When a query is made, the protocol takes the following sequence of actions:

Note that cached entries are held indefinitely as long as the Client's RHostResolver object is open - even for TTL 0 records. Therefore, if the client wishes to ensure only the most up to date records are returned from its query, it should Open a fresh RHostResolver for each new query.

Note that the DNS server used is either negotiated by PPP in establishing a dial-up connection, or configured by the user in ISP settings.

Note that the RHostResolver::GetByName()/RHostResolver::GetByAddress() can be called asynchronously so that the application can choose to do that early in the program and the data will have arrived by the time it is needed later on. See comment under Next Result below on using Next.


Resolve name

Use RHostResolver::GetByName() to resolve a symbolic name to an IP address. The arguments are as follows:

aName

The symbolic name to resolve. Note that if you pass the local host name (as returned by RHostResolver::GetHostName()) or a null descriptor, the result is the address of the current primary network interface.

aResult

Returns the result of the name resolution. Unpackage the TNameEntry to get a TNameRecord with the following members:

iName: the value of the passed aName

iAddr: the address information. Cast this to a TInetAddr to obtain the IP address.

iFlags: a bitmask of TNameRecordFlags flags.


Get name

Use RHostResolver:: GetByAddress() to obtain an IP address from a symbolic name. The arguments are as follows:

anAddr

A TInetAddr specifying the IP address to use. Note that if you pass a null address or an address matching the primary network interface, the local host name is returned.

aResult

Returns the result of the name resolution. Unpackage the TNameEntry to get a TNameRecord with the following members:

iName: the symbolic name

iAddr: the value of the passed anAddr

iFlags: a bitmask of TNameRecordFlags flags.


Next result

The Next() function is used to find further answers after an initial GetByName() or GetByAddress() query.

For GetByName(), the matching A record (IP address) is returned first. Calls to Next() return any further CNAME (alias) or A records. CNAME records have the IP address set to 0 and the EDnsAlias flag set.

For GetByAddress(), the first matching PTR record (domain name) is returned first. Calls to Next() return any further PTR records.

Note that Next() can be called synchronously because all information is retrieved from a local buffer that was written by the initial query.


Local host

RHostResolver::GetHostName() and RHostResolver::SetHostName() get and set respectively the name of the local host. Note that these functions simply get and set a local variable.