Blame ares_init_options.3

Packit 514978
.\"
Packit 514978
.\" Copyright 1998 by the Massachusetts Institute of Technology.
Packit 514978
.\" Copyright (C) 2004-2010 by Daniel Stenberg
Packit 514978
.\"
Packit 514978
.\" Permission to use, copy, modify, and distribute this
Packit 514978
.\" software and its documentation for any purpose and without
Packit 514978
.\" fee is hereby granted, provided that the above copyright
Packit 514978
.\" notice appear in all copies and that both that copyright
Packit 514978
.\" notice and this permission notice appear in supporting
Packit 514978
.\" documentation, and that the name of M.I.T. not be used in
Packit 514978
.\" advertising or publicity pertaining to distribution of the
Packit 514978
.\" software without specific, written prior permission.
Packit 514978
.\" M.I.T. makes no representations about the suitability of
Packit 514978
.\" this software for any purpose.  It is provided "as is"
Packit 514978
.\" without express or implied warranty.
Packit 514978
.\"
Packit 514978
.TH ARES_INIT 3 "5 March 2010"
Packit 514978
.SH NAME
Packit 514978
ares_init_options \- Initialize a resolver channel
Packit 514978
.SH SYNOPSIS
Packit 514978
.nf
Packit 514978
#include <ares.h>
Packit 514978
Packit 514978
struct ares_options {
Packit 514978
  int flags;
Packit 514978
  int timeout; /* in seconds or milliseconds, depending on options */
Packit 514978
  int tries;
Packit 514978
  int ndots;
Packit 514978
  unsigned short udp_port;
Packit 514978
  unsigned short tcp_port;
Packit 514978
  int socket_send_buffer_size;
Packit 514978
  int socket_receive_buffer_size;
Packit 514978
  struct in_addr *servers;
Packit 514978
  int nservers;
Packit 514978
  char **domains;
Packit 514978
  int ndomains;
Packit 514978
  char *lookups;
Packit 514978
  ares_sock_state_cb sock_state_cb;
Packit 514978
  void *sock_state_cb_data;
Packit 514978
  struct apattern *sortlist;
Packit 514978
  int nsort;
Packit 514978
  int ednspsz;
Packit 514978
};
Packit 514978
Packit 514978
int ares_init_options(ares_channel *\fIchannelptr\fP,
Packit 514978
                      struct ares_options *\fIoptions\fP,
Packit 514978
                      int \fIoptmask\fP)
Packit 514978
.fi
Packit 514978
.SH DESCRIPTION
Packit 514978
The \fBares_init_options(3)\fP function initializes a communications channel
Packit 514978
for name service lookups.  If it returns successfully,
Packit 514978
\fBares_init_options(3)\fP will set the variable pointed to by
Packit 514978
\fIchannelptr\fP to a handle used to identify the name service channel.  The
Packit 514978
caller should invoke \fIares_destroy(3)\fP on the handle when the channel is
Packit 514978
no longer needed.
Packit 514978
Packit 514978
The \fIoptmask\fP parameter generally specifies which fields in the structure pointed to
Packit 514978
by \fIoptions\fP are set, as follows:
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_FLAGS
Packit 514978
.B int \fIflags\fP;
Packit 514978
.br
Packit 514978
Flags controlling the behavior of the resolver.  See below for a
Packit 514978
description of possible flag values.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_TIMEOUT
Packit 514978
.B int \fItimeout\fP;
Packit 514978
.br
Packit 514978
The number of seconds each name server is given to respond to a query on the
Packit 514978
first try.  (After the first try, the timeout algorithm becomes more
Packit 514978
complicated, but scales linearly with the value of \fItimeout\fP.)  The
Packit 514978
default is five seconds. This option is being deprecated by
Packit 514978
\fIARES_OPT_TIMEOUTMS\fP starting in c-ares 1.5.2.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_TIMEOUTMS
Packit 514978
.B int \fItimeout\fP;
Packit 514978
.br
Packit 514978
The number of milliseconds each name server is given to respond to a query on
Packit 514978
the first try.  (After the first try, the timeout algorithm becomes more
Packit 514978
complicated, but scales linearly with the value of \fItimeout\fP.)  The
Packit 514978
default is five seconds. Note that this option is specified with the same
Packit 514978
struct field as the former \fIARES_OPT_TIMEOUT\fP, it is but the option bits
Packit 514978
that tell c-ares how to interpret the number. This option was added in c-ares
Packit 514978
1.5.2.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_TRIES
Packit 514978
.B int \fItries\fP;
Packit 514978
.br
Packit 514978
The number of tries the resolver will try contacting each name server
Packit 514978
before giving up.  The default is four tries.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_NDOTS
Packit 514978
.B int \fIndots\fP;
Packit 514978
.br
Packit 514978
The number of dots which must be present in a domain name for it to be
Packit 514978
queried for "as is" prior to querying for it with the default domain
Packit 514978
extensions appended.  The default value is 1 unless set otherwise by
Packit 514978
resolv.conf or the RES_OPTIONS environment variable.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_UDP_PORT
Packit 514978
.B unsigned short \fIudp_port\fP;
Packit 514978
.br
Packit 514978
The port to use for queries over UDP, in network byte order.
Packit 514978
The default value is 53 (in network byte order), the standard name
Packit 514978
service port.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_TCP_PORT
Packit 514978
.B unsigned short \fItcp_port\fP;
Packit 514978
.br
Packit 514978
The port to use for queries over TCP, in network byte order.
Packit 514978
The default value is 53 (in network byte order), the standard name
Packit 514978
service port.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_SERVERS
Packit 514978
.B struct in_addr *\fIservers\fP;
Packit 514978
.br
Packit 514978
.B int \fInservers\fP;
Packit 514978
.br
Packit 514978
The list of IPv4 servers to contact, instead of the servers specified in
Packit 514978
resolv.conf or the local named. In order to allow specification of either
Packit 514978
IPv4 or IPv6 name servers, the
Packit 514978
.BR ares_set_servers(3)
Packit 514978
function must be used instead.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_DOMAINS
Packit 514978
.B char **\fIdomains\fP;
Packit 514978
.br
Packit 514978
.B int \fIndomains\fP;
Packit 514978
.br
Packit 514978
The domains to search, instead of the domains specified in resolv.conf
Packit 514978
or the domain derived from the kernel hostname variable.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_LOOKUPS
Packit 514978
.B char *\fIlookups\fP;
Packit 514978
.br
Packit 514978
The lookups to perform for host queries.
Packit 514978
.I lookups
Packit 514978
should be set to a string of the characters "b" or "f", where "b"
Packit 514978
indicates a DNS lookup and "f" indicates a lookup in the hosts file.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_SOCK_STATE_CB
Packit 514978
.B void (*\fIsock_state_cb\fP)(void *data, int s, int read, int write);
Packit 514978
.br
Packit 514978
.B void *\fIsock_state_cb_data\fP;
Packit 514978
.br
Packit 514978
A callback function to be invoked when a socket changes state.
Packit 514978
.I s
Packit 514978
will be passed the socket whose state has changed;
Packit 514978
.I read
Packit 514978
will be set to true if the socket should listen for read events, and
Packit 514978
.I write
Packit 514978
will be set to true if the socket should listen for write events.
Packit 514978
The value of
Packit 514978
.I sock_state_cb_data
Packit 514978
will be passed as the
Packit 514978
.I data
Packit 514978
argument.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_SORTLIST
Packit 514978
.B struct apattern *\fIsortlist\fP;
Packit 514978
.br
Packit 514978
.B int \fInsort\fP;
Packit 514978
.br
Packit 514978
A list of IP address ranges that specifies the order of preference that
Packit 514978
results from \fIares_gethostbyname\fP should be returned in.  Note that
Packit 514978
this can only be used with a sortlist retrieved via
Packit 514978
\fBares_save_options(3)\fP (because
Packit 514978
.B struct apattern
Packit 514978
is opaque); to set a fresh sort list, use \fBares_set_sortlist(3)\fP.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_SOCK_SNDBUF
Packit 514978
.B int \fIsocket_send_buffer_size\fP;
Packit 514978
.br
Packit 514978
The send buffer size to set for the socket.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_SOCK_RCVBUF
Packit 514978
.B int \fIsocket_receive_buffer_size\fP;
Packit 514978
.br
Packit 514978
The receive buffer size to set for the socket.
Packit 514978
.TP 18
Packit 514978
.B ARES_OPT_EDNSPSZ
Packit 514978
.B int \fIednspsz\fP;
Packit 514978
.br
Packit 514978
The message size to be advertized in EDNS; only takes effect if the
Packit 514978
.B ARES_FLAG_EDNS
Packit 514978
flag is set.
Packit 514978
.br
Packit 514978
.PP
Packit 514978
The \fIoptmask\fP parameter also includes options without a corresponding
Packit 514978
field in the
Packit 514978
.B ares_options
Packit 514978
structure, as follows:
Packit 514978
.TP 23
Packit 514978
.B ARES_OPT_ROTATE
Packit 514978
Perform round-robin selection of the nameservers configured for the channel
Packit 514978
for each resolution.
Packit 514978
.TP 23
Packit 514978
.B ARES_OPT_NOROTATE
Packit 514978
Do not perform round-robin nameserver selection; always use the list of
Packit 514978
nameservers in the same order.
Packit 514978
.PP
Packit 514978
The
Packit 514978
.I flags
Packit 514978
field should be the bitwise or of some subset of the following values:
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_USEVC
Packit 514978
Always use TCP queries (the "virtual circuit") instead of UDP
Packit 514978
queries.  Normally, TCP is only used if a UDP query yields a truncated
Packit 514978
result.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_PRIMARY
Packit 514978
Only query the first server in the list of servers to query.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_IGNTC
Packit 514978
If a truncated response to a UDP query is received, do not fall back
Packit 514978
to TCP; simply continue on with the truncated response.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_NORECURSE
Packit 514978
Do not set the "recursion desired" bit on outgoing queries, so that the name
Packit 514978
server being contacted will not try to fetch the answer from other servers if
Packit 514978
it doesn't know the answer locally. Be aware that ares will not do the
Packit 514978
recursion for you.  Recursion must be handled by the application calling ares
Packit 514978
if \fIARES_FLAG_NORECURSE\fP is set.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_STAYOPEN
Packit 514978
Do not close communications sockets when the number of active queries
Packit 514978
drops to zero.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_NOSEARCH
Packit 514978
Do not use the default search domains; only query hostnames as-is or
Packit 514978
as aliases.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_NOALIASES
Packit 514978
Do not honor the HOSTALIASES environment variable, which normally
Packit 514978
specifies a file of hostname translations.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_NOCHECKRESP
Packit 514978
Do not discard responses with the SERVFAIL, NOTIMP, or REFUSED
Packit 514978
response code or responses whose questions don't match the questions
Packit 514978
in the request.  Primarily useful for writing clients which might be
Packit 514978
used to test or debug name servers.
Packit 514978
.TP 23
Packit 514978
.B ARES_FLAG_EDNS
Packit 514978
Include an EDNS pseudo-resource record (RFC 2671) in generated requests.
Packit 514978
.SH RETURN VALUES
Packit 514978
\fBares_init_options(3)\fP can return any of the following values:
Packit 514978
.TP 14
Packit 514978
.B ARES_SUCCESS
Packit 514978
Initialization succeeded.
Packit 514978
.TP 14
Packit 514978
.B ARES_EFILE
Packit 514978
A configuration file could not be read.
Packit 514978
.TP 14
Packit 514978
.B ARES_ENOMEM
Packit 514978
The process's available memory was exhausted.
Packit 514978
.TP 14
Packit 514978
.B ARES_ENOTINITIALIZED
Packit 514978
c-ares library initialization not yet performed.
Packit 514978
.SH NOTES
Packit 514978
When initializing from
Packit 514978
.B /etc/resolv.conf,
Packit 514978
\fBares_init_options(3)\fP reads the \fIdomain\fP and \fIsearch\fP directives
Packit 514978
to allow lookups of short names relative to the domains specified. The
Packit 514978
\fIdomain\fP and \fIsearch\fP directives override one another. If more that
Packit 514978
one instance of either \fIdomain\fP or \fIsearch\fP directives is specified,
Packit 514978
the last occurrence wins. For more information, please see the
Packit 514978
.BR resolv.conf (5)
Packit 514978
manual page.
Packit 514978
.SH SEE ALSO
Packit 514978
.BR ares_init(3),
Packit 514978
.BR ares_destroy(3),
Packit 514978
.BR ares_dup(3),
Packit 514978
.BR ares_library_init(3),
Packit 514978
.BR ares_save_options(3),
Packit 514978
.BR ares_set_servers(3),
Packit 514978
.BR ares_set_sortlist(3)
Packit 514978
.SH AUTHOR
Packit 514978
Greg Hudson, MIT Information Systems
Packit 514978
.br
Packit 514978
Copyright 1998 by the Massachusetts Institute of Technology.
Packit 514978
.br
Packit 514978
Copyright (C) 2004-2010 by Daniel Stenberg.
Packit 514978