This topic describes how to use the domain name resolution.
You must be familiar with RHostResolver() to understand this tutorial. The RHostResolver() function is defined in es_sock.h. Types and constants specific to TCP/IP are used in RHostResolver() arguments are defined in in_sock.h.
The TCP/IP stack contains a Domain Name Service (DNS). The client programs conducts DNS queries through the generic host name resolution interface RHostResolver, specifying protocol-specific behaviour through the argument values. This tutorial describes how the RHostResolver() functions are used for DNS.
When a query is made, the protocol takes the following sequence of actions:
Searches the local HOSTS file, if it exists. The hosts file is stored in the \private\10000882\ directory.
If an answer is not found, it checks the DNS cache. The protocol queries the DNS server using a UDP socket. If there is no current connection, a dial-up connection is called.
If an answer is found, the answer is added to the cache.
Note: The cache entries are held continuously while the client RHostResolver object is open, for TTL 0 records. The client queries the RHostResolver object to get the latest records.
Note: The DNS server used is managed by PPP to establish a dial-up connection, or configured by the user in ISP settings.
The RHostResolver::GetByName() or RHostResolver::GetByAddress() can be called asynchronously, so that the application can select the program and the data when it is required. For more information see Next Result.
Resolve name
Use RHostResolver::GetByName() to resolve a symbolic name to an IP address. The parameters are as follows:
Parameter |
Description |
aName |
The symbolic name to resolve. Note: If you pass the local host name or a null descriptor the result is the address of the network interface. The RHostResolver::GetHostName() returns the local host name. |
aResult |
Returns the result of the name resolution. Unpack the TNameEntry to get a TNameRecord with the following members: iName: the value of the passed aName iAddr: the address information. Assign the iAddr to TInetAddr to get the IP address. iFlags: a bitmask of TNameRecordFlags flags. |
Get name
Use RHostResolver::GetByAddress() to get an IP address from a symbolic name. The parameters are as follows:
Parameter |
Description |
anAddr |
A TInetAddr specifies the IP address to use. Note: If you pass a null address or an address that matches the primary network interface, the local host name is returned. |
aResult |
Returns the result of the name resolution. Unpack 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 finds more 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: The 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 the name of the local host.
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.