HPlogo Installing and Administering Internet Services: HP 9000 Networking > Chapter 3 Configuring and Administering the BIND Name Service

Configuring the Resolver to Set Timeout Values

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Timeout values are configured for clients (resolver routines) that use DNS with the RES_RETRY and RES_RETRANS options. These options allow you to set the number of re-transmissions (RES_RETRY) and the time between each retransmission (RES_RETRANS). Setting smaller timeout values enable you to get better performance. You can configure the timeout values by defining environment variables, editing the /etc/resolv.conf configuration file, or using the resolver APIs.

Valid values for RES_RETRY and RES_RETRANS options are any positive, non-zero integer. By default, the system will try to re-transmit 4 times, and the time between each retransmission is 5000 milliseconds.

If the RES_RETRY and RES_RETRANS options contain an invalid value, the default values are set and an error message is logged in the syslog. The returned values of the APIs will indicate if the values specified were valid or not.

Configuring Timeout Values using Environment Variables

You can set the RES_RETRY and RES_RETRANS options by defining them as environment variables. Setting the timeout values using environment variables only sets the RES_RETRY and RES_RETRANS values for individual users.

  • Set the environment variable with the export command, typing the following at the prompt:

    export RES_RETRY=1

    export RES_RETRANS=300

    The variable values, 1 and 300, can be replaced with another value. The value for RES_RETRANS should not be less than 200 milliseconds.

Configuring Timeout Values using the Configuration File

You can set the RES_RETRY and RES_RETRANS options in the /etc/resolv.conf configuration file. Setting the timeout value with the configuration file sets the RES_RETRY and RES_RETRANS values on a specific system.

  • Add the following line to the /etc/resolv.conf configuration file after the domain and nameserver entries. You specify the value for retrans and retry:

    retrans 600

    retry 1

Configuring Timeout Values using APIs

If you configure the timeout values using the APIs, you will have to make code changes and re-compile the code.

There are two APIs you can use to set and get the RES_RETRY and RES_RETRANS values in the _res_state_structure :

  • set_resfield()

  • get_resfield()

set_resfield

The syntax for this function is:

set_resfield(int field, void *value)

The parameter field is the resolver option that you want to set. The parameter value is the value you want to set for the field.

The return value of this function is 0 if the function successfully sets the value for the option in the _res_state structure, which holds all the resolver options and -1 on failure.

get_resfield

The syntax for this function is:

get_res(int field, void *value, sizeof value)

The parameter field is the resolver option that you want to get. The parameter value is the pointer to the location where the option value is stored. The sizeof value parameter is used to obtain the number of bytes required for the variable so that memory can be allocated to that variable when a function is invoked.

The return value of this function is 0 if the function successfully gets the value of the field in the value parameter. It will return -1 on failure.

Sample Program With Timeout Values

main()
{
int retrans = 600;
int retry =1;
struct hostent *hp;
struct in_addr ia;
char *name = "localhost";

res_init();
set_resfield(RES_RETRANS, &retrans);
set_resfield(RES_RETRANS, &retry);

hp = gethostbyname (name);
if (hp == NULL )
{
printf ("gethostbyname failed\n");
herror("Error");
}
else
{
int i;
for (i=o; hp->h_addr_list[i]; i++)
{
memcpy((caddre_t)&ia, hep->h_addr_list[i],\
sizeof(ia));
printf("%s", inet_ntoa(ia));
}
}

get_resfield (RES_RETRANS, &retrans, sizeof\
retrans);
get_resfield (RES_RETRY, &retry, sizeof retry);

printf ("retry = %d \n retrans = %d\n", retry,\
retrans);
}
© 2000 Hewlett-Packard Development Company, L.P.