1941N/A - Copyright (C) 2000, 2001, 2003-2005, 2007, 2014-2016 Internet Systems Consortium, Inc. ("ISC") 1941N/A - This Source Code Form is subject to the terms of the Mozilla Public 1941N/A - License, v. 2.0. If a copy of the MPL was not distributed with this 1941N/A<
meta http-
equiv="Content-Type" content="text/html; charset=ISO-8859-1">
1941N/A<
title>lwres_context</
title>
1941N/A<
meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
1941N/A<
body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><
div class="refentry">
1941N/A<
a name="id-1"></
a><
div class="titlepage"></
div>
2362N/A<
p>lwres_context_create, lwres_context_destroy, lwres_context_nextserial, lwres_context_initserial, lwres_context_freemem, lwres_context_allocmem, lwres_context_sendrecv — lightweight resolver context management</
p>
2362N/A<
div class="refsynopsisdiv">
1941N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
1941N/A<
b class="fsfunc">lwres_context_create</
b>(</
code></
td>
1941N/A<
td>lwres_context_t **<
var class="pdparam">contextp</
var>, </
td>
1941N/A<
td>void *<
var class="pdparam">arg</
var>, </
td>
1941N/A<
td>lwres_malloc_t <
var class="pdparam">malloc_function</
var>, </
td>
1941N/A<
td>lwres_free_t <
var class="pdparam">free_function</
var><
code>)</
code>;</
td>
1941N/A<
div class="funcprototype-spacer">�</
div>
1941N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><
tr>
1941N/A<
b class="fsfunc">lwres_context_destroy</
b>(</
code></
td>
1941N/A<
td>lwres_context_t **<
var class="pdparam">contextp</
var><
code>)</
code>;</
td>
1941N/A<
div class="funcprototype-spacer">�</
div>
1941N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
1941N/A<
b class="fsfunc">lwres_context_initserial</
b>(</
code></
td>
1941N/A<
td>lwres_context_t *<
var class="pdparam">ctx</
var>, </
td>
1941N/A<
td>lwres_uint32_t <
var class="pdparam">serial</
var><
code>)</
code>;</
td>
1941N/A<
div class="funcprototype-spacer">�</
div>
1941N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><
tr>
1941N/A<
b class="fsfunc">lwres_context_nextserial</
b>(</
code></
td>
1941N/A<
td>lwres_context_t *<
var class="pdparam">ctx</
var><
code>)</
code>;</
td>
1941N/A<
div class="funcprototype-spacer">�</
div>
1941N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
1941N/A<
b class="fsfunc">lwres_context_freemem</
b>(</
code></
td>
1941N/A<
td>lwres_context_t *<
var class="pdparam">ctx</
var>, </
td>
<
td>void *<
var class="pdparam">mem</
var>, </
td>
<
td>size_t <
var class="pdparam">len</
var><
code>)</
code>;</
td>
<
div class="funcprototype-spacer">�</
div>
<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_context_allocmem</
b>(</
code></
td>
<
td>lwres_context_t *<
var class="pdparam">ctx</
var>, </
td>
<
td>size_t <
var class="pdparam">len</
var><
code>)</
code>;</
td>
<
div class="funcprototype-spacer">�</
div>
<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_context_sendrecv</
b>(</
code></
td>
<
td>lwres_context_t *<
var class="pdparam">ctx</
var>, </
td>
<
td>void *<
var class="pdparam">sendbase</
var>, </
td>
<
td>int <
var class="pdparam">sendlen</
var>, </
td>
<
td>void *<
var class="pdparam">recvbase</
var>, </
td>
<
td>int <
var class="pdparam">recvlen</
var>, </
td>
<
td>int *<
var class="pdparam">recvd_len</
var><
code>)</
code>;</
td>
<
div class="funcprototype-spacer">�</
div>
<
a name="id-1.7"></
a><
h2>DESCRIPTION</
h2>
<
p><
code class="function">lwres_context_create()</
code>
creates a <
span class="type">lwres_context_t</
span> structure for use in
lightweight resolver operations. It holds a socket and other
data needed for communicating with a resolver daemon. The new
<
span class="type">lwres_context_t</
span> is returned through
<
em class="parameter"><
code>contextp</
code></
em>, a pointer to a
<
span class="type">lwres_context_t</
span> pointer. This
<
span class="type">lwres_context_t</
span> pointer must initially be NULL, and
is modified to point to the newly created
<
span class="type">lwres_context_t</
span>.
When the lightweight resolver needs to perform dynamic memory
<
em class="parameter"><
code>malloc_function</
code></
em>
<
em class="parameter"><
code>free_function</
code></
em>
<
em class="parameter"><
code>malloc_function</
code></
em>
<
em class="parameter"><
code>free_function</
code></
em>
are NULL, memory is allocated using
<
span class="citerefentry"><
span class="refentrytitle">malloc</
span>(3)</
span>.
<
span class="citerefentry"><
span class="refentrytitle">free</
span>(3)</
span>.
It is not permitted to have a NULL
<
em class="parameter"><
code>malloc_function</
code></
em> and a non-NULL
<
em class="parameter"><
code>free_function</
code></
em> or vice versa.
<
em class="parameter"><
code>arg</
code></
em> is passed as the first parameter to
the memory allocation functions. If
<
em class="parameter"><
code>malloc_function</
code></
em> and
<
em class="parameter"><
code>free_function</
code></
em> are NULL,
<
em class="parameter"><
code>arg</
code></
em> is unused and should be passed as
Once memory for the structure has been allocated,
<
span class="citerefentry"><
span class="refentrytitle">lwres_conf_init</
span>(3)</
span>
and returned via <
em class="parameter"><
code>*contextp</
code></
em>.
<
p><
code class="function">lwres_context_destroy()</
code>
destroys a <
span class="type">lwres_context_t</
span>, closing its socket.
<
em class="parameter"><
code>contextp</
code></
em> 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.
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
<
code class="function">lwres_context_initserial()</
code> and
<
code class="function">lwres_context_nextserial()</
code>.
<
code class="function">lwres_context_initserial()</
code> sets the serial
number for context <
em class="parameter"><
code>*ctx</
code></
em> to
<
em class="parameter"><
code>serial</
code></
em>.
<
code class="function">lwres_context_nextserial()</
code> increments the
serial number and returns the previous value.
Memory for a lightweight resolver context is allocated and freed
using <
code class="function">lwres_context_allocmem()</
code> and
<
code class="function">lwres_context_freemem()</
code>. These use
whatever allocations were defined when the context was created
with <
code class="function">lwres_context_create()</
code>.
<
code class="function">lwres_context_allocmem()</
code> allocates
<
em class="parameter"><
code>len</
code></
em> bytes of memory and if successful
returns a pointer to the allocated storage.
<
code class="function">lwres_context_freemem()</
code> frees
<
em class="parameter"><
code>len</
code></
em> bytes of space starting at location
<
em class="parameter"><
code>mem</
code></
em>.
<
p><
code class="function">lwres_context_sendrecv()</
code>
performs I/O for the context <
em class="parameter"><
code>ctx</
code></
em>. Data
are read and written from the context's socket. It writes data
from <
em class="parameter"><
code>sendbase</
code></
em> — typically a
lightweight resolver query packet — and waits for a reply
which is copied to the receive buffer at
<
em class="parameter"><
code>recvbase</
code></
em>. The number of bytes that were
written to this receive buffer is returned in
<
em class="parameter"><
code>*recvd_len</
code></
em>.
<
a name="id-1.8"></
a><
h2>RETURN VALUES</
h2>
<
p><
code class="function">lwres_context_create()</
code>
returns <
span class="errorcode">LWRES_R_NOMEMORY</
span> if memory for
the <
span class="type">struct lwres_context</
span> could not be allocated,
<
span class="errorcode">LWRES_R_SUCCESS</
span> otherwise.
Successful calls to the memory allocator
<
code class="function">lwres_context_allocmem()</
code>
return a pointer to the start of the allocated space.
It returns NULL if memory could not be allocated.
<
p><
span class="errorcode">LWRES_R_SUCCESS</
span>
<
code class="function">lwres_context_sendrecv()</
code>
<
span class="errorcode">LWRES_R_IOERROR</
span>
is returned if an I/O error occurs and
<
span class="errorcode">LWRES_R_TIMEOUT</
span>
<
code class="function">lwres_context_sendrecv()</
code>
times out waiting for a response.
<
a name="id-1.9"></
a><
h2>SEE ALSO</
h2>
<
p><
span class="citerefentry"><
span class="refentrytitle">lwres_conf_init</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">malloc</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">free</
span>(3)</
span>.