lwres_context.docbook revision be8aff07bb6a863c46874021f2ce8304b721632a
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
010a51c427bfb6ab658fc0056955a1a5b69810beTinderbox User<!--
9b20c5d7ff43224f60c4f8049fa2e4fef9d374f0Tinderbox User - Copyright (C) 2001 Internet Software Consortium.
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews -
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - Permission to use, copy, modify, and distribute this software for any
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - purpose with or without fee is hereby granted, provided that the above
9b20c5d7ff43224f60c4f8049fa2e4fef9d374f0Tinderbox User - copyright notice and this permission notice appear in all copies.
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews -
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9b20c5d7ff43224f60c4f8049fa2e4fef9d374f0Tinderbox User - DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews-->
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<!-- $Id: lwres_context.docbook,v 1.4 2003/03/19 17:43:41 marka Exp $ -->
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<refentry>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refentryinfo>
0a330c717a298b60fb357999baac7c08dfc29046Tinderbox User
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<date>Jun 30, 2000</date>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User</refentryinfo>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<refmeta>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refentrytitle>lwres_context</refentrytitle>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<manvolnum>3</manvolnum>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refmiscinfo>BIND9</refmiscinfo>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User</refmeta>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refnamediv>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refname>lwres_context_create</refname>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refname>lwres_context_destroy</refname>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refname>lwres_context_nextserial</refname>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<refname>lwres_context_initserial</refname>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<refname>lwres_context_freemem</refname>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<refname>lwres_context_allocmem</refname>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<refname>lwres_context_sendrecv</refname>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refpurpose>lightweight resolver context management</refpurpose>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User</refnamediv>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<refsynopsisdiv>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<funcsynopsis>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<funcsynopsisinfo>#include &lt;lwres/lwres.h&gt;</funcsynopsisinfo>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<funcprototype>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<funcdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewslwres_result_t
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<function>lwres_context_create</function></funcdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<paramdef>lwres_context_t **contextp</paramdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<paramdef>void *arg</paramdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<paramdef>lwres_malloc_t malloc_function</paramdef>
9d557856c2a19ec95ee73245f60a92f8675cf5baTinderbox User<paramdef>lwres_free_t free_function</paramdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews</funcprototype>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<funcprototype>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<funcdef>
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox Userlwres_result_t
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<function>lwres_context_destroy</function></funcdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<paramdef>lwres_context_t **contextp</paramdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User</funcprototype>
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User<funcprototype>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<funcdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox Uservoid
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<function>lwres_context_initserial</function></funcdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<paramdef>lwres_context_t *ctx</paramdef>
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User<paramdef>lwres_uint32_t serial</paramdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews</funcprototype>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<funcprototype>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<funcdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox Userlwres_uint32_t
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<function>lwres_context_nextserial</function></funcdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<paramdef>lwres_context_t *ctx</paramdef>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User</funcprototype>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<funcprototype>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<funcdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewsvoid
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<function>lwres_context_freemem</function></funcdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<paramdef>lwres_context_t *ctx</paramdef>
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews<paramdef>void *mem</paramdef>
<paramdef>size_t len</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_context_allocmem</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
<paramdef>size_t len</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void *
<function>lwres_context_sendrecv</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
<paramdef>void *sendbase</paramdef>
<paramdef>int sendlen</paramdef>
<paramdef>void *recvbase</paramdef>
<paramdef>int recvlen</paramdef>
<paramdef>int *recvd_len</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>lwres_context_create()</function>
creates a
<type>lwres_context_t</type>
structure for use in lightweight resolver operations.
It holds a socket and other data needed for communicating
with a resolver daemon.
The new
<type>lwres_context_t</type>
is returned through
<parameter>contextp</parameter>,
a pointer to a
<type>lwres_context_t</type>
pointer. This
<type>lwres_context_t</type>
pointer must initially be NULL, and is modified
to point to the newly created
<type>lwres_context_t</type>.
</para>
<para>
When the lightweight resolver needs to perform dynamic memory
allocation, it will call
<parameter>malloc_function</parameter>
to allocate memory and
<parameter>free_function</parameter>
to free it. If
<parameter>malloc_function</parameter>
and
<parameter>free_function</parameter>
are NULL, memory is allocated using
.Xr malloc 3
and
<citerefentry>
<refentrytitle>free</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>.
It is not permitted to have a NULL
<parameter>malloc_function</parameter>
and a non-NULL
<parameter>free_function</parameter>
or vice versa.
<parameter>arg</parameter>
is passed as the first parameter to the memory
allocation functions.
If
<parameter>malloc_function</parameter>
and
<parameter>free_function</parameter>
are NULL,
<parameter>arg</parameter>
is unused and should be passed as NULL.
</para>
<para>
Once memory for the structure has been allocated,
it is initialized using
<citerefentry>
<refentrytitle>lwres_conf_init</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>
and returned via
<parameter>*contextp</parameter>.
</para>
<para>
<function>lwres_context_destroy()</function>
destroys a
<type>lwres_context_t</type>,
closing its socket.
<parameter>contextp</parameter>
is a pointer to a pointer to the context that is to be destroyed.
The pointer will be set to NULL when the context has been destroyed.
</para>
<para>
The context holds a serial number that is used to identify resolver
request packets and associate responses with the corresponding requests.
This serial number is controlled using
<function>lwres_context_initserial()</function>
and
<function>lwres_context_nextserial()</function>.
<function>lwres_context_initserial()</function>
sets the serial number for context
<parameter>*ctx</parameter>
to
<parameter>serial</parameter>.
<function>lwres_context_nextserial()</function>
increments the serial number and returns the previous value.
</para>
<para>
Memory for a lightweight resolver context is allocated and freed using
<function>lwres_context_allocmem()</function>
and
<function>lwres_context_freemem()</function>.
These use whatever allocations were defined when the context was
created with
<function>lwres_context_create()</function>.
<function>lwres_context_allocmem()</function>
allocates
<parameter>len</parameter>
bytes of memory and if successful returns a pointer to the allocated
storage.
<function>lwres_context_freemem()</function>
frees
<parameter>len</parameter>
bytes of space starting at location
<parameter>mem</parameter>.
</para>
<para>
<function>lwres_context_sendrecv()</function>
performs I/O for the context
<parameter>ctx</parameter>.
Data are read and written from the context's socket.
It writes data from
<parameter>sendbase</parameter>
&mdash; typically a lightweight resolver query packet &mdash;
and waits for a reply which is copied to the receive buffer at
<parameter>recvbase</parameter>.
The number of bytes that were written to this receive buffer is
returned in
<parameter>*recvd_len</parameter>.
</para>
</refsect1>
<refsect1>
<title>RETURN VALUES</title>
<para>
<function>lwres_context_create()</function>
returns
<errorcode>LWRES_R_NOMEMORY</errorcode>
if memory for the
<type>struct lwres_context</type>
could not be allocated,
<errorcode>LWRES_R_SUCCESS</errorcode>
otherwise.
</para>
<para>
Successful calls to the memory allocator
<function>lwres_context_allocmem()</function>
return a pointer to the start of the allocated space.
It returns NULL if memory could not be allocated.
</para>
<para>
<errorcode>LWRES_R_SUCCESS</errorcode>
is returned when
<function>lwres_context_sendrecv()</function>
completes successfully.
<errorcode>LWRES_R_IOERROR</errorcode>
is returned if an I/O error occurs and
<errorcode>LWRES_R_TIMEOUT</errorcode>
is returned if
<function>lwres_context_sendrecv()</function>
times out waiting for a response.
</para>
</refsect1>
<refsect1>
<title>SEE ALSO</title>
<para>
<citerefentry>
<refentrytitle>lwres_conf_init</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>malloc</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>free</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>.
</para>
</refsect1>
</refentry>