ares 1.1.1 with collected applied patches
[platform/upstream/c-ares.git] / ares_init.3
1 .\" $Id$
2 .\"
3 .\" Copyright 1998 by the Massachusetts Institute of Technology.
4 .\"
5 .\" Permission to use, copy, modify, and distribute this
6 .\" software and its documentation for any purpose and without
7 .\" fee is hereby granted, provided that the above copyright
8 .\" notice appear in all copies and that both that copyright
9 .\" notice and this permission notice appear in supporting
10 .\" documentation, and that the name of M.I.T. not be used in
11 .\" advertising or publicity pertaining to distribution of the
12 .\" software without specific, written prior permission.
13 .\" M.I.T. makes no representations about the suitability of
14 .\" this software for any purpose.  It is provided "as is"
15 .\" without express or implied warranty.
16 .\"
17 .TH ARES_INIT 3 "21 July 1998"
18 .SH NAME
19 ares_init, ares_init_options \- Initialize a resolver channel
20 .SH SYNOPSIS
21 .nf
22 .B #include <ares.h>
23 .PP
24 .B int ares_init(ares_channel *\fIchannel\fP)
25 .B int ares_init_options(ares_channel *\fIchannel\fP,
26 .B      struct ares_options *\fIoptions\fP, int \fIoptmask\fP)
27 .PP
28 .B cc file.c -lares
29 .fi
30 .SH DESCRIPTION
31 The
32 .B ares_init
33 function initializes a communications channel for name service
34 lookups.  If it returns successfully,
35 .B ares_init
36 will set the variable pointed to by
37 .I channel
38 to a handle used to identify the name service channel.  The caller
39 should invoke
40 .BR ares_destroy (3)
41 on the handle when the channel is no longer needed.
42 .PP
43 The
44 .B ares_init_options
45 function also initializes a name service channel, with additional
46 options useful for applications requiring more control over name
47 service configuration.  The
48 .I optmask
49 parameter specifies which fields in the structure pointed to by
50 .I options
51 are set, as follows:
52 .PP
53 .TP 18
54 .B ARES_OPT_FLAGS
55 .B int \fIflags\fP;
56 .br
57 Flags controlling the behavior of the resolver.  See below for a
58 description of possible flag values.
59 .TP 18
60 .B ARES_OPT_TIMEOUT
61 .B int \fItimeout\fP;
62 .br
63 The number of seconds each name server is given to respond to a query
64 on the first try.  (After the first try, the timeout algorithm becomes
65 more complicated, but scales linearly with the value of
66 \fItimeout\fP.)  The default is five seconds.
67 .TP 18
68 .B ARES_OPT_TRIES
69 .B int \fItries\fP;
70 .br
71 The number of tries the resolver will try contacting each name server
72 before giving up.  The default is four tries.
73 .TP 18
74 .B ARES_OPT_NDOTS
75 .B int \fIndots\fP;
76 .br
77 The number of dots which must be present in a domain name for it to be
78 queried for "as is" prior to querying for it with the default domain
79 extensions appended.  The default value is 1 unless set otherwise by
80 resolv.conf or the RES_OPTIONS environment variable.
81 .TP 18
82 .B ARES_OPT_PORT
83 .B unsigned short \fIport\fP;
84 .br
85 The port to use for queries (both TCP and UDP), in network byte order.
86 The default value is 53 (in network byte order), the standard name
87 service port.
88 .TP 18
89 .B ARES_OPT_SERVERS
90 .B struct in_addr *\fIservers\fP;
91 .br
92 .B int \fInservers\fP;
93 .br
94 The list of servers to contact, instead of the servers specified in
95 resolv.conf or the local named.
96 .TP 18
97 .B ARES_OPT_DOMAINS
98 .B char **\fIdomains\fP;
99 .br
100 .B int \fIndomains\fP;
101 .br
102 The domains to search, instead of the domains specified in resolv.conf
103 or the domain derived from the kernel hostname variable.
104 .TP 18
105 .B ARES_OPT_LOOKUPS
106 .B char *\fIlookups\fP;
107 .br
108 The lookups to perform for host queries.  
109 .I lookups
110 should be set to a string of the characters "b" or "f", where "b"
111 indicates a DNS lookup and "f" indicates a lookup in the hosts file.
112 .PP
113 The
114 .I flags
115 field should be the bitwise or of some subset of the following values:
116 .TP 23
117 .B ARES_FLAG_USEVC
118 Always use TCP queries (the "virtual circuit") instead of UDP
119 queries.  Normally, TCP is only used if a UDP query yields a truncated
120 result.
121 .TP 23
122 .B ARES_FLAG_PRIMARY
123 Only query the first server in the list of servers to query.
124 .TP 23
125 .B ARES_FLAG_IGNTC
126 If a truncated response to a UDP query is received, do not fall back
127 to TCP; simply continue on with the truncated response.
128 .TP 23
129 .B ARES_FLAG_NORECURSE
130 Do not set the "recursion desired" bit on outgoing queries, so that
131 the name server being contacted will not try to fetch the answer from
132 other servers if it doesn't know the answer locally.
133 .TP 23
134 .B ARES_FLAG_STAYOPEN
135 Do not close communciations sockets when the number of active queries
136 drops to zero.
137 .TP 23
138 .B ARES_FLAG_NOSEARCH
139 Do not use the default search domains; only query hostnames as-is or
140 as aliases.
141 .TP 23
142 .B ARES_FLAG_NOALIASES
143 Do not honor the HOSTALIASES environment variable, which normally
144 specifies a file of hostname translations.
145 .TP 23
146 .B ARES_FLAG_NOCHECKRESP
147 Do not discard responses with the SERVFAIL, NOTIMP, or REFUSED
148 response code or responses whose questions don't match the questions
149 in the request.  Primarily useful for writing clients which might be
150 used to test or debug name servers.
151 .SH RETURN VALUES
152 .I ares_init
153 or
154 .I ares_init_options
155 can return any of the following values:
156 .TP 14
157 .B ARES_SUCCESS
158 Initialization succeeded.
159 .TP 14
160 .B ARES_EFILE
161 A configuration file could not be read.
162 .TP 14
163 .B ARES_ENOMEM
164 The process's available memory was exhausted.
165 .SH SEE ALSO
166 .BR ares_destroy (3)
167 .SH AUTHOR
168 Greg Hudson, MIT Information Systems
169 .br
170 Copyright 1998 by the Massachusetts Institute of Technology.