ares_init_options.3 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. .\"
  2. .\" Copyright 1998 by the Massachusetts Institute of Technology.
  3. .\" Copyright (C) 2004-2010 by Daniel Stenberg
  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 "5 March 2010"
  18. .SH NAME
  19. ares_init_options \- Initialize a resolver channel
  20. .SH SYNOPSIS
  21. .nf
  22. #include <ares.h>
  23. struct ares_options {
  24. int flags;
  25. int timeout; /* in seconds or milliseconds, depending on options */
  26. int tries;
  27. int ndots;
  28. unsigned short udp_port;
  29. unsigned short tcp_port;
  30. int socket_send_buffer_size;
  31. int socket_receive_buffer_size;
  32. struct in_addr *servers;
  33. int nservers;
  34. char **domains;
  35. int ndomains;
  36. char *lookups;
  37. ares_sock_state_cb sock_state_cb;
  38. void *sock_state_cb_data;
  39. struct apattern *sortlist;
  40. int nsort;
  41. int ednspsz;
  42. char *resolvconf_path;
  43. };
  44. int ares_init_options(ares_channel *\fIchannelptr\fP,
  45. struct ares_options *\fIoptions\fP,
  46. int \fIoptmask\fP)
  47. .fi
  48. .SH DESCRIPTION
  49. The \fBares_init_options(3)\fP function initializes a communications channel
  50. for name service lookups. If it returns successfully,
  51. \fBares_init_options(3)\fP will set the variable pointed to by
  52. \fIchannelptr\fP to a handle used to identify the name service channel. The
  53. caller should invoke \fIares_destroy(3)\fP on the handle when the channel is
  54. no longer needed.
  55. The \fIoptmask\fP parameter generally specifies which fields in the structure pointed to
  56. by \fIoptions\fP are set, as follows:
  57. .TP 18
  58. .B ARES_OPT_FLAGS
  59. .B int \fIflags\fP;
  60. .br
  61. Flags controlling the behavior of the resolver. See below for a
  62. description of possible flag values.
  63. .TP 18
  64. .B ARES_OPT_TIMEOUT
  65. .B int \fItimeout\fP;
  66. .br
  67. The number of seconds each name server is given to respond to a query on the
  68. first try. (After the first try, the timeout algorithm becomes more
  69. complicated, but scales linearly with the value of \fItimeout\fP.) The
  70. default is five seconds. This option is being deprecated by
  71. \fIARES_OPT_TIMEOUTMS\fP starting in c-ares 1.5.2.
  72. .TP 18
  73. .B ARES_OPT_TIMEOUTMS
  74. .B int \fItimeout\fP;
  75. .br
  76. The number of milliseconds each name server is given to respond to a query on
  77. the first try. (After the first try, the timeout algorithm becomes more
  78. complicated, but scales linearly with the value of \fItimeout\fP.) The
  79. default is five seconds. Note that this option is specified with the same
  80. struct field as the former \fIARES_OPT_TIMEOUT\fP, it is but the option bits
  81. that tell c-ares how to interpret the number. This option was added in c-ares
  82. 1.5.2.
  83. .TP 18
  84. .B ARES_OPT_TRIES
  85. .B int \fItries\fP;
  86. .br
  87. The number of tries the resolver will try contacting each name server
  88. before giving up. The default is four tries.
  89. .TP 18
  90. .B ARES_OPT_NDOTS
  91. .B int \fIndots\fP;
  92. .br
  93. The number of dots which must be present in a domain name for it to be
  94. queried for "as is" prior to querying for it with the default domain
  95. extensions appended. The default value is 1 unless set otherwise by
  96. resolv.conf or the RES_OPTIONS environment variable.
  97. .TP 18
  98. .B ARES_OPT_UDP_PORT
  99. .B unsigned short \fIudp_port\fP;
  100. .br
  101. The port to use for queries over UDP, in network byte order.
  102. The default value is 53 (in network byte order), the standard name
  103. service port.
  104. .TP 18
  105. .B ARES_OPT_TCP_PORT
  106. .B unsigned short \fItcp_port\fP;
  107. .br
  108. The port to use for queries over TCP, in network byte order.
  109. The default value is 53 (in network byte order), the standard name
  110. service port.
  111. .TP 18
  112. .B ARES_OPT_SERVERS
  113. .B struct in_addr *\fIservers\fP;
  114. .br
  115. .B int \fInservers\fP;
  116. .br
  117. The list of IPv4 servers to contact, instead of the servers specified in
  118. resolv.conf or the local named. In order to allow specification of either
  119. IPv4 or IPv6 name servers, the
  120. .BR ares_set_servers(3)
  121. function must be used instead.
  122. .TP 18
  123. .B ARES_OPT_DOMAINS
  124. .B char **\fIdomains\fP;
  125. .br
  126. .B int \fIndomains\fP;
  127. .br
  128. The domains to search, instead of the domains specified in resolv.conf
  129. or the domain derived from the kernel hostname variable.
  130. .TP 18
  131. .B ARES_OPT_LOOKUPS
  132. .B char *\fIlookups\fP;
  133. .br
  134. The lookups to perform for host queries.
  135. .I lookups
  136. should be set to a string of the characters "b" or "f", where "b"
  137. indicates a DNS lookup and "f" indicates a lookup in the hosts file.
  138. .TP 18
  139. .B ARES_OPT_SOCK_STATE_CB
  140. .B void (*\fIsock_state_cb\fP)(void *data, ares_socket_t socket_fd, int readable, int writable);
  141. .br
  142. .B void *\fIsock_state_cb_data\fP;
  143. .br
  144. A callback function to be invoked when a socket changes state.
  145. .I socket_fd
  146. will be passed the socket whose state has changed;
  147. .I readable
  148. will be set to true if the socket should listen for read events, and
  149. .I writable
  150. will be set to true if the socket should listen for write events.
  151. The value of
  152. .I sock_state_cb_data
  153. will be passed as the
  154. .I data
  155. argument.
  156. .TP 18
  157. .B ARES_OPT_SORTLIST
  158. .B struct apattern *\fIsortlist\fP;
  159. .br
  160. .B int \fInsort\fP;
  161. .br
  162. A list of IP address ranges that specifies the order of preference that
  163. results from \fIares_gethostbyname\fP should be returned in. Note that
  164. this can only be used with a sortlist retrieved via
  165. \fBares_save_options(3)\fP (because
  166. .B struct apattern
  167. is opaque); to set a fresh sort list, use \fBares_set_sortlist(3)\fP.
  168. .TP 18
  169. .B ARES_OPT_SOCK_SNDBUF
  170. .B int \fIsocket_send_buffer_size\fP;
  171. .br
  172. The send buffer size to set for the socket.
  173. .TP 18
  174. .B ARES_OPT_SOCK_RCVBUF
  175. .B int \fIsocket_receive_buffer_size\fP;
  176. .br
  177. The receive buffer size to set for the socket.
  178. .TP 18
  179. .B ARES_OPT_EDNSPSZ
  180. .B int \fIednspsz\fP;
  181. .br
  182. The message size to be advertized in EDNS; only takes effect if the
  183. .B ARES_FLAG_EDNS
  184. flag is set.
  185. .TP 18
  186. .B ARES_OPT_RESOLVCONF
  187. .B char *\fIresolvconf_path\fP;
  188. .br
  189. The path to use for reading the resolv.conf file. The
  190. .I resolvconf_path
  191. should be set to a path string, and will be honoured on *nix like systems. The
  192. default is
  193. .B /etc/resolv.conf
  194. .br
  195. .PP
  196. The \fIoptmask\fP parameter also includes options without a corresponding
  197. field in the
  198. .B ares_options
  199. structure, as follows:
  200. .TP 23
  201. .B ARES_OPT_ROTATE
  202. Perform round-robin selection of the nameservers configured for the channel
  203. for each resolution.
  204. .TP 23
  205. .B ARES_OPT_NOROTATE
  206. Do not perform round-robin nameserver selection; always use the list of
  207. nameservers in the same order.
  208. .PP
  209. The
  210. .I flags
  211. field should be the bitwise or of some subset of the following values:
  212. .TP 23
  213. .B ARES_FLAG_USEVC
  214. Always use TCP queries (the "virtual circuit") instead of UDP
  215. queries. Normally, TCP is only used if a UDP query yields a truncated
  216. result.
  217. .TP 23
  218. .B ARES_FLAG_PRIMARY
  219. Only query the first server in the list of servers to query.
  220. .TP 23
  221. .B ARES_FLAG_IGNTC
  222. If a truncated response to a UDP query is received, do not fall back
  223. to TCP; simply continue on with the truncated response.
  224. .TP 23
  225. .B ARES_FLAG_NORECURSE
  226. Do not set the "recursion desired" bit on outgoing queries, so that the name
  227. server being contacted will not try to fetch the answer from other servers if
  228. it doesn't know the answer locally. Be aware that ares will not do the
  229. recursion for you. Recursion must be handled by the application calling ares
  230. if \fIARES_FLAG_NORECURSE\fP is set.
  231. .TP 23
  232. .B ARES_FLAG_STAYOPEN
  233. Do not close communications sockets when the number of active queries
  234. drops to zero.
  235. .TP 23
  236. .B ARES_FLAG_NOSEARCH
  237. Do not use the default search domains; only query hostnames as-is or
  238. as aliases.
  239. .TP 23
  240. .B ARES_FLAG_NOALIASES
  241. Do not honor the HOSTALIASES environment variable, which normally
  242. specifies a file of hostname translations.
  243. .TP 23
  244. .B ARES_FLAG_NOCHECKRESP
  245. Do not discard responses with the SERVFAIL, NOTIMP, or REFUSED
  246. response code or responses whose questions don't match the questions
  247. in the request. Primarily useful for writing clients which might be
  248. used to test or debug name servers.
  249. .TP 23
  250. .B ARES_FLAG_EDNS
  251. Include an EDNS pseudo-resource record (RFC 2671) in generated requests.
  252. .SH RETURN VALUES
  253. \fBares_init_options(3)\fP can return any of the following values:
  254. .TP 14
  255. .B ARES_SUCCESS
  256. Initialization succeeded.
  257. .TP 14
  258. .B ARES_EFILE
  259. A configuration file could not be read.
  260. .TP 14
  261. .B ARES_ENOMEM
  262. The process's available memory was exhausted.
  263. .TP 14
  264. .B ARES_ENOTINITIALIZED
  265. c-ares library initialization not yet performed.
  266. .SH NOTES
  267. When initializing from
  268. .B /etc/resolv.conf,
  269. (or, alternatively when specified by the
  270. .I resolvconf_path
  271. path location)
  272. \fBares_init_options(3)\fP reads the \fIdomain\fP and \fIsearch\fP directives
  273. to allow lookups of short names relative to the domains specified. The
  274. \fIdomain\fP and \fIsearch\fP directives override one another. If more that
  275. one instance of either \fIdomain\fP or \fIsearch\fP directives is specified,
  276. the last occurrence wins. For more information, please see the
  277. .BR resolv.conf (5)
  278. manual page.
  279. .SH SEE ALSO
  280. .BR ares_init(3),
  281. .BR ares_destroy(3),
  282. .BR ares_dup(3),
  283. .BR ares_library_init(3),
  284. .BR ares_save_options(3),
  285. .BR ares_set_servers(3),
  286. .BR ares_set_sortlist(3)
  287. .SH AUTHOR
  288. Greg Hudson, MIT Information Systems
  289. .br
  290. Copyright 1998 by the Massachusetts Institute of Technology.
  291. .br
  292. Copyright (C) 2004-2010 by Daniel Stenberg.