#include <sys/types.h> #include <netinet/in.h> #include <arpa/nameser.h> #include <resolv.h> void res_init(void)
The res_init() function is used to initialize the _res structure for name resolution. Two bits are set in the structure to indicate that it has been initialized. (These are the RES_INIT and RES_XINIT bits in the options field of the _res structure.) Also, the default domain name and other components of the domain to search are put into the _res structure.
The _res structure is defined in <resolv.h>.
struct state {
int retrans;
int retry;
long options;
int nscount;
struct sockaddr_in nsaddr_list[MAXNS];
u_short id;
char defdname[MAXDNAME];
char reserved0[1];
char reserved1[13];
char *dnsrch[MAXDNSRCH+1];
/* Extended state structure begins here.*/
struct {
struct in_addr addr;
uint mask;
} sort_list[MAXRESOLVSORT];
int res_h_errno;
int extended_error;
unsigned ndots:4;
unsigned nsort:4;
char state_data[27];
int internal_use[4];
char reserved[444];
};
#define nsaddr nsaddr_list[0]
extern struct state _res;
| RES_INIT | Indicates that the res structure
has been initialized. |
| RES_AAONLY | Requests the answer be authoritative and not from
a name server's cache. |
| RES_USEVC | Tells the resolver to use TCP instead of UDP. |
| RES_IGNTC | Tells the resolver to ignore truncation. |
| RES_RECURSE | Specifies that recursion is desired. |
| RES_DEFNAMES | Appends the default domain name to single label
queries. |
| RES_STAYOPEN | Causes the TCP connection to remain open (used
with RES_USEVC). |
| RES_DNSRCH | Searches using dnsrch. |
| RES_INSECURE1 | Disables type 1 security. Type 1 security rejects
responses that didn't come from one of the configured DNS servers. |
| RES_INSECURE2 | Disables type 2 security. Type 2 security checks
the question section of the reply to ensure it matches the original query
sent. |
| RES_NOALIASES | Tells the resolver to ignore the HOSTALIASES
environment variable. |
| RES_ROTATE | Tells the resolver to rotate through the list of
DNS servers (nsaddr_list). |
| RES_NOCHECKNAME | Tells the resolver not to check host names in
replies for disallowed characters such as underscore (_), non-ASCII, or control
characters. |
| RES_KEEPTSIG | Stops the resolver from stripping TSIG records on
replies. |
| RES_NOCACHE | Do not look in the resolver answer cache. Query the name server. The answer may still be locally cached. |
The following four values are i5/OS specific.
| RES_XINIT | Indicates that the extended portion of the
res structure has been initialized. |
| RES_CP850 | Use ASCII code page 850 and not ASCII code page
819. |
| RES_RETRYTCP | Retry with a TCP connection if the UDP connection
fails for any reason. |
| RES_NSADDRONLY | Only use the list of addresses in
nsaddr. There may be a separate SOCKS DNS configured that would
normally be used. |
| RES_DEFAULT | This is the default. Causes an OR operation on the RES_RECURSE, RES_DEFNAMES, RES_DNSRCH values. |
No authorization is required.
None.
res_init() can set errno to the following:
_res appears to have been previously initialized but the reserved field is not set to zeros.
res_init() was unable to retrieve the DNS server configuration.
The configured search list (struct state.defdname and struct state.dnsrch) can be overridden by setting the environment variable LOCALDOMAIN to a space-separated list of up to 6 search domains with a total of 256 characters (including spaces). If a search list is specified, the default local domain is not used on queries.
The RES_DEFAULT options (struct state.options) and system configured values
(Change TCP/IP Domain - CHGTCPDMN) can be overridden by setting the environment
variable QIBM_BIND_RESOLVER_FLAGS to a space separated list of resolver option
flags. The state.options structure will be initialized normally, using
RES_DEFAULT, OPTIONS environment values and CHGTCPDMN configured values. Then
this environment varible will be used to override those defaults. The flags
named in this environment variable may be prepended with a '+', '-' or 'NOT_'
to set ('+') or reset ('-','NOT_') the value. For example, to turn on
RES_NOCHECKNAME and turn off RES_ROTATE:
ADDENVVAR ENVVAR(QIBM_BIND_RESOLVER_FLAGS) VALUE('RES_NOCHECKNAME
NOT_RES_ROTATE')
or
ADDENVVAR ENVVAR(QIBM_BIND_RESOLVER_FLAGS) VALUE('+RES_NOCHECKNAME
-RES_ROTATE')
A sort list (struct state.sort_list) can be configured by setting the environment variable QIBM_BIND_RESOLVER_SORTLIST to a space-separated list of up to 10 ip addresses/mask pairs in dotted decimal format (9.5.9.0/255.255.255.0)
Note: Environment variables are only checked after a successful call to res_init() or res_ninit(). So if the structure has been manually initialized, environment variables are ignored. Also note that the structure is only initialized once so later changes to the environment variables will be ignored.
| Top | UNIX-Type APIs | APIs by category |