 |
» |
|
|
 |
You can configure the timeout value for clients that use DNS to resolve a host name. The timeout value specifies the number of retransmissions of a query and the time (in milliseconds) between each retransmission. The performance of the resolver improves with smaller timeout values. You can configure the timeout values by defining environment variables, editing the /etc/resolv.conf configuration file, or using the resolver APIs. Configuring Timeout Values Using APIs |  |
You can configure the timeout values using the following APIs: Using these two APIs, you can set and get values for the retransmission time and the time between each retransmission in the instance of the a _res_state structure. When you configure the timeout values using the APIs, you must make certain changes to the code and recompile the code. The returned values of the APIs indicate if the specified values are correct. The syntax for the set_resfield function is as follows: set_resfield(int field, void *value) |
The set_resfield() function contains two parameters: field and *value. You can set the resolver option using the field parameter and the value for the field using the value parameter. The set_resfield() function returns either 0 or -1. It returns a value0 if the function successfully sets the value for the resolver option in the instance of the_res_state structure, which holds all the resolver options. A value of -1 denotes a failure to set the resolver option. The syntax for the get_resfield() function is as follows: get_resfield(int field, void *value, sizeof value) |
The get_resfield() function contains three parameters: field, *value, and value. The parameter field contains the resolver option. The parameter *value is the pointer to the location where the option value is stored. The value parameter specifies the memory (in bytes) allocated for a variable when a function is invoked. The get_resfield() function returns either 0 or -1. It returns a value of 0 if the function successfully gets the value of the field in the value parameter and returns a value -1 on failure. Sample Program with Timeout Values |  |
A sample program with timeout values is as follows: 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_RETRY, &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((caddr_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);
} |
|