Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
$Id: lwres_context.3,v 1.6 2001/01/09 21:49:19 bwelling Exp $
.Dd Jun 30, 2000 .Dt LWRES_CONTEXT 3 .Os BIND9 9 .Sh NAME .Nm lwres_context_create , .Nm lwres_context_destroy , .Nm lwres_context_nextserial , .Nm lwres_context_initserial , .Nm lwres_context_freemem , .Nm lwres_context_allocmem , .Nm lwres_context_sendrecv .Nd lightweight resolver context management .Sh SYNOPSIS .Fd #include <lwres/lwres.h> .Fd .Ft lwres_result_t .Fo lwres_context_create .Fa "lwres_context_t **contextp" .Fa "void *arg" .Fa "lwres_malloc_t malloc_function" .Fa "lwres_free_t free_function" .Fc .Ft lwres_result_t .Fo lwres_context_destroy .Fa "lwres_context_t **contextp" .Fc .Ft void .Fo lwres_context_initserial .Fa "lwres_context_t *ctx" .Fa "lwres_uint32_t serial" .Fc .Ft lwres_uint32_t .Fo lwres_context_nextserial .Fa "lwres_context_t *ctx" .Fc .Ft void .Fo lwres_context_freemem .Fa "lwres_context_t *ctx" .Fa "void *mem" .Fa "size_t len" .Fc .Ft void .Fo lwres_context_allocmem .Fa "lwres_context_t *ctx" .Fa "size_t len" .Fc .Ft void * .Fo lwres_context_sendrecv .Fa "lwres_context_t *ctx" .Fa "void *sendbase" .Fa "int sendlen" .Fa "void *recvbase" .Fa "int recvlen" .Fa "int *recvd_len" .Fc .Sh DESCRIPTION .Fn lwres_context_create creates a .Dv lwres_context_t structure for use in lightweight resolver operations. It holds a socket and other data needed for communicating with a resolver daemon. The new .Dv lwres_context_t is returned throught .Fa contextp , a pointer to a .Dv "lwres_context_t" pointer. This .Dv "lwres_context_t" pointer must initially be NULL, and is modified to point to the newly created .Dv "lwres_context_t" .
p When the lightweight resolver needs to perform dynamic memory allocation, it will call .Fa malloc_function to allocate memory and .Fa free_function to free it. If .Fa malloc_function and .Fa free_function are NULL, memory is allocated using .Xr malloc 3 and .Xr free 3 . It is not permitted to have a NULL .Fa malloc_function and a non-NULL .Fa free_function or vice versa. .Fa arg is passed as the first parameter to the memory allocation functions. If .Fa malloc_function and .Fa free_function are NULL, .Fa arg is unused and should be passed as NULL.
Once memory for the structure has been allocated, it is initialized using .Xr lwres_conf_init 3 and returned via .Fa *contextp .
p .Fn lwres_context_destroy destroys a .Dv "lwres_context_t" , closing its socket. .Fa contextp 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.
p 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 .Fn lwres_context_initserial and .Fn lwres_context_nextserial . .Fn lwres_context_initserial sets the serial number for context .Fa *ctx to .Fa serial . .Fn lwres_context_nextserial increments the serial number and returns the previous value.
p Memory for a lightweight resolver context is allocated and freed using .Fn lwres_context_allocmem and .Fn lwres_context_freemem . These use whatever allocations were defined when the context was created with .Fn lwres_context_create . .Fn lwres_context_allocmem allocates .Fa len bytes of memory and if successful returns a pointer to the allocated storage. .Fn lwres_context_allocmem checks that .Fa len must be greater than 0. .Fn lwres_context_freemem frees .Fa len bytes of space starting at location .Fa mem .
p .Fn lwres_context_sendrecv performs I/O for the context .Fa ctx . Data are read and written from the context's socket. It writes data from .Fa sendbase - typically a lightweight resolver query packet - and waits for a reply which is copied to the receive buffer at .Fa recvbase . The number of bytes that were written to this receive buffer is returned in .Fa *recvd_len . .Sh RETURN VALUES .Fn lwres_context_create returns .Er LWRES_R_NOMEMORY if memory for the .Dv "struct lwres_context" could not be allocated, .Er LWRES_R_SUCCESS otherwise.
p Successful calls to the memory allocator .Fn lwres_context_allocmem return a pointer to the start of the allocated space. It returns NULL if memory could not be allocated.
p .Er LWRES_R_SUCCESS is returned when .Fn lwres_context_sendrecv completes successfully. .Er LWRES_R_IOERROR is returned if an I/O error occurs and .Er LWRES_R_TIMEOUT is returned if .Fn lwres_context_sendrecv times out waiting for a response. .Sh SEE ALSO .Xr lwres_conf_init 3 , .Xr malloc 3 , .Xr free 3