Resolver


Contents


Introduction and Overview

Internet based applications are required to connect to other hosts throughout the world. Location of these hosts is via numeric addresses which are determined by human readable names. The process of converting from names to addresses is performed by 'Domain Name Servers' (DNS).

Under RISC OS, communication with DNS is performed by the Resolver module.

This chapter describes how the Resolver module is configured to use DNS, and applications should interact with it.


Terminology

The Resolver module provides shared Internet IP address resolution facilities to the system.

The Hosts file is the file InetDBase:Hosts. It is used to initialise the local DNS cache with entries.

DNS servers are queried by the Resolver and the results are cached.

Application is used within this chapter as a description of the Resolver querant, but this may also apply to Modules.


Technical Details

How the Resolver works

The Resolver functions as follows :

  • The user configures the resolver through serial variables. Usually this is performed on machine start up from pre-set values.
  • When an address is requested the application requests a lookup from the Resolver.
  • The Resolver module checks its cached entries and if one exists that matches the request, it is returned immediately. Otherwise a request is sent to the configured DNS servers.
  • The application continues to request a lookup from the Resolver. The Resolver continues to try to look up the request until it times out.
  • If the request to the DNS servers is satisfied, or a failure is returned, the result is returned to the application.
  • If the request is not responded to within a period, a failure is returned to the application.

SWI interface

The module provides two interfaces for resolving addresses :

  • Resolver_GetHostByName to provide an equivilent operation to that expected by unix applications. This SWI will not return until a result or failure has been determined.
  • Resolver_GetHost to provide a multi-tasking version of GetHostByName. This SWI returns a notification that the resolve is 'in progress' and should be polled until a result has been received.

In addition, there is a means for controlling the cache :

Host entries

All results are returned in the form of NetBSD standard 'hostent' structures. These structures should be considered to be read only by the application.

A hostent has the following structure :

OffsetContents
+0Pointer to host name
+4Pointer to 0 terminated list of pointers to aliases for this host
+8Address type (usually AF_INET)
+12Address length (4 for AF_INET)
+16Pointer to 0 terminated list of addresses

System variables

The Resolver module uses a number of system variables for its configuration. These determine how and where it resolves Internet addresses from. In general, these variables are initialised during machine startup. They may be modified by the user once the Internet stack has started. They will be read when the re-configure call is made to the Resolver, either via the Resolver_CacheControl SWI or by the *ResolverConfig command. In addition, they will be re-read whenever the InetDBaseChanged service is issued.


System variables


Inet$Resolvers

Lists the DNS servers that should be queried
Use

This variable lists the DNS servers that will be queried during resolution requestes. It consists of a space separated list of dotted IP addresses. Up to three addresses may be supplied. Addresses will be queried in the order supplied.

Related APIs
None

Inet$Hostname

Local name of this host
Use

This variable gives the local name of this host. Attempts to set this variable to a fully qualified hostname will result in it and Inet$LocalDomain being set to the correct values.

Related system variables
Inet$LocalDomain

Inet$LocalDomain

Local domain name
Use

This variable gives the local domain name for the network this host is connected to. Together with Inet$Hostname, this provides the name of this host on a network. It may be that this host name is not visible from certain networks due to firewalls, proxying and other network-specific issues.

Related system variables
Inet$Hostname

Inet$SearchDomains

List of domains to use search hostnames in
Use

This variable describes the domains which should be appended to failed host lookups in an attempt to resolve them.

After being modified, the Resolver module must be notified by requesting it re-read its configuration.

Related * commands
*ResolverConfig
Related SWIs
Resolver_CacheControl
Related system variables
Inet$LocalDomain

Inet$ResolverRetries

Number of times that the resolver should re-try resolving
Use

This variable should be set to the number of retries that the resolve should made. During resolution, the Resolver may get no response to its requests. This may be due to network bandwidth limitations, or a busy server. The number of retries may be configured to allow for greater numbers of retries if necessary.

After being modified, the Resolver module must be notified by requesting it re-read its configuration.

Related * commands
*ResolverConfig
Related SWIs
Resolver_CacheControl
Related system variables
Inet$ResolverDelay

Inet$ResolverDelay

Delay between resolution requests
Use

This variable should be set to the number of seconds that should be waited between resolution requests. During resolution, the Resolver may get no response to its requests. This may be due to network bandwidth limitations, or a busy server. The delay between retries may be configured to allow for faster requests (if the server is known to accept such requests - consult the server operators) or longer delays if the server is known to be under load.

After being modified, the Resolver module must be notified by requesting it re-read its configuration.

Related * commands
*ResolverConfig
Related SWIs
Resolver_CacheControl
Related system variables
Inet$ResolverRetries

Inet$ResolverServer

Determines whether the DNS relay is active
Use

This variable should be set to '1' to configure the DNS relay to be active, or '0' to deactivate it.

After being modified, the Resolver module must be notified by requesting it re-read its configuration.

Related * commands
*ResolverConfig
Related SWIs
Resolver_CacheControl

Service calls


Service_InternetVars
(Service &80C41)

Notification of variable changes
On entry
R0=reason code :
ValueMeaning
0 Change in the location of the internet database
1 Change in the name of this host
otherReserved
R1=service call number
On exit
R0preserved
R1preserved
Use

This service is issued by the Resolver module when certain variables that it monitors change. Other components may use the service as an indication that their configuration has changed.

Related APIs
None

Service_InternetVars 0
(Service &80C41)

Change in the location of the internet database
On entry
R0=0 (reason code)
R1=service call number
On exit
R0preserved
R1preserved
Use

This service is issued by the Resolver module when InetDBase$Path is changed. Components which hold resources in the database should re-read those resources.

Related services
Service_InternetVars

Service_InternetVars 1
(Service &80C41)

Change in the name of this host
On entry
R0=1 (reason code)
R1=service call number
On exit
R0preserved
R1preserved
Use

This service is issued by the Resolver module when Inet$Hostname is changed. Components which use the hostname to refer to objects should update their concept of the local name

Related services
Service_InternetVars
Related system variables
Inet$Hostname

SWI calls


Resolver_GetHostByName
(SWI &46000)

Initiate a non-blocking name resolution
On entry
R1=Pointer to host name string
On exit
R0=Internet error number, indicating the state of the lookup :
ValueMeaning
0Resolve successful
-1Host was not found
-2Remove request failure, eg no response from servers
36Resolve in progress
otherStandard internet error numbers
R1=Pointer to 'hostent' structure if successful, or 0 if failed
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

This SWI is provided primarily for backwards compatibility, since new network applications can use the more flexible Resolver_GetHost.

The main use of this SWI is by the simple ports of unix applications using the gethostbyname() function call.

Although this SWI is marked as non-reentrant, it is expected that this SWI be preempted by OS_UpCall 6 when used in a TaskWindow. This is a safe operation.

Related SWIs
Resolver_GetHost

Resolver_GetHost
(SWI &46001)

Initiate a non-blocking name resolution
On entry
R1=Pointer to host name string
On exit
R0=Internet error number, indicating the state of the lookup :
ValueMeaning
0Resolve successful
-1Host was not found
-2Remove request failure, eg no response from servers
36Resolve in progress
otherStandard internet error numbers
R1=Pointer to 'hostent' structure if successful, or 0 if failed
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

This SWI provides a DNS resolution facility that runs in the background (unlike Resolver_GetHostByName). Applications must poll the Resolver module for the state of the resolution.

If the hostname is a valid cache item, or present in the hosts file on disc, it is returned immediately in R1, with R0 set to 0.

If the hostname is a cache item, marked as failed, then R1 is set to 0 and R0 is either -1 (host not found), or -2 (remote failure. eg, configured resolver didn't respond).

If the hostname is a cache item, marked as pending, then R1 is set to 0 and R0 is EINPROGRESS (36 decimal). Items are marked as pending when a remote resolver lookup is in progress. The calling program is expected to periodically call Resolver_GetHost until a valid hostent is returned, or an error condition occurs.

Because name lookups can take anything up to 20 seconds or so, it is important to be able to give feedback to the user on the status of the lookup, as well as giving the foreground application time to perform other tasks.

Cache sweeps occur periodically - pending items are marked as failed (remote failure) after a short period, failed items are removed after a longer period, and valid items are removed after 24 hours.

If there is a configuration error (such as Inet$Resolvers not being set), then a RISC OS error block pointer is returned in R0, and the V flag is set on exit.

Example

The calling program might run something like:

REM 'EINPROGRESS' error number is 36 decimal
REPEAT
  SYS "Resolver_GetHost","host.net" TO status,hostent;flags
  error = (flags AND 1) == 1
  REM Perhaps inform user of the state of this lookup
UNTIL (error) OR (status != EINPROGRESS)
REM hostent is a valid pointer, or 0

Related SWIs
Resolver_GetHostByName

Resolver_GetCache
(SWI &46002)

This SWI call is for internal use only. You must not use it in your own code.


Resolver_CacheControl
(SWI &46003)

Perform operations on the Resolver cache
On entry
R0=Reason code :
ValueMeaning
0Flush cache of failed lookups
1Flush cache of all items
2Flush cache of hosts file items
3Re-read configuration
8Disable caching of failed lookups
9Enable caching of failed lookups
otherReserved
On exit
R0preserved
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

This SWI is provided to allow a calling application to control the Resolver cache in a limited way. Currently, the only reason codes supported are to force flushes of certain cache entries, and dis(abling) of the caching of lookups that fail.

Caching of lookup failures is disabled by default. You might wish to enable the caching of lookup failures if you are sure that any failures are genuine bad host errors and not due to packet loss, remote server timeouts, etc.

Related * commands
*ResolverConfig

*Commands


*ResolverConfig

Request that the resolver re-read its configuration
Syntax
*ResolverConfig
Parameters
None
Use

This command is used to request that the Resolver re-read the system variables for configuration.

Example
*ResolverConfig
Related SWIs
Resolver_CacheControl

Document information

Maintainer(s): RISCOS Ltd <developer@riscos.com>
History:
RevisionDateAuthorChanges
1ROLInitial version
Disclaimer:

Copyright © Pace Micro Technolgy plc, 2002.
Portions copyright © RISCOS Ltd, 2002.
Published by RISCOS Limited.
No part of this publication may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, or stored in any retrieval system of any nature, without the written permission of the copyright holder and the publisher, application for which shall be made to the publisher.