📄 lwres_resutil.docbook
字号:
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN"><!-- - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") - Copyright (C) 2001 Internet Software Consortium. - - 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 ISC DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS. IN NO EVENT SHALL ISC 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_resutil.docbook,v 1.2 2004/09/20 18:00:50 mcr Exp $ --><refentry><refentryinfo><date>Jun 30, 2000</date></refentryinfo><refmeta> <refentrytitle>lwres_resutil</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>BIND9</refmiscinfo></refmeta><refnamediv><refname>lwres_string_parse</refname><refname>lwres_addr_parse</refname><refname>lwres_getaddrsbyname</refname><refname>lwres_getnamebyaddr</refname><refpurpose>lightweight resolver utility functions</refpurpose></refnamediv><refsynopsisdiv><funcsynopsis><funcsynopsisinfo>#include <lwres/lwres.h></funcsynopsisinfo><funcprototype><funcdef>lwres_result_t<function>lwres_string_parse</function></funcdef><paramdef>lwres_buffer_t *b</paramdef><paramdef>char **c</paramdef><paramdef>lwres_uint16_t *len</paramdef></funcprototype><funcprototype><funcdef>lwres_result_t<function>lwres_addr_parse</function></funcdef><paramdef>lwres_buffer_t *b</paramdef><paramdef>lwres_addr_t *addr</paramdef></funcprototype><funcprototype><funcdef>lwres_result_t<function>lwres_getaddrsbyname</function></funcdef><paramdef>lwres_context_t *ctx</paramdef><paramdef>const char *name</paramdef><paramdef>lwres_uint32_t addrtypes</paramdef><paramdef>lwres_gabnresponse_t **structp</paramdef></funcprototype><funcprototype><funcdef>lwres_result_t<function>lwres_getnamebyaddr</function></funcdef><paramdef>lwres_context_t *ctx</paramdef><paramdef>lwres_uint32_t addrtype</paramdef><paramdef>lwres_uint16_t addrlen</paramdef><paramdef>const unsigned char *addr</paramdef><paramdef>lwres_gnbaresponse_t **structp</paramdef></funcprototype></funcsynopsis></refsynopsisdiv><refsect1><title>DESCRIPTION</title><para><function>lwres_string_parse()</function> retrieves a DNS-encodedstring starting the current pointer of lightweight resolver buffer<parameter>b</parameter>: i.e. <constant>b->current</constant>.When the function returns, the address of the first byte of theencoded string is returned via <parameter>*c</parameter> and thelength of that string is given by <parameter>*len</parameter>. Thebuffer's current pointer is advanced to point at the characterfollowing the string length, the encoded string, and the trailing<type>NULL</type> character.</para><para><function>lwres_addr_parse()</function> extracts an address from thebuffer <parameter>b</parameter>. The buffer's current pointer<constant>b->current</constant> is presumed to point at an encodedaddress: the address preceded by a 32-bit protocol family identifierand a 16-bit length field. The encoded address is copied to<constant>addr->address</constant> and<constant>addr->length</constant> indicates the size in bytes ofthe address that was copied. <constant>b->current</constant> isadvanced to point at the next byte of available data in the bufferfollowing the encoded address.</para><para><function>lwres_getaddrsbyname()</function>and<function>lwres_getnamebyaddr()</function>use the<type>lwres_gnbaresponse_t</type>structure defined below:<programlisting>typedef struct { lwres_uint32_t flags; lwres_uint16_t naliases; lwres_uint16_t naddrs; char *realname; char **aliases; lwres_uint16_t realnamelen; lwres_uint16_t *aliaslen; lwres_addrlist_t addrs; void *base; size_t baselen;} lwres_gabnresponse_t;</programlisting>The contents of this structure are not manipulated directly butthey are controlled through the<citerefentry><refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum></citerefentry>functions.</para><para>The lightweight resolver uses<function>lwres_getaddrsbyname()</function> to perform foward lookups.Hostname <parameter>name</parameter> is looked up using the resolvercontext <parameter>ctx</parameter> for memory allocation.<parameter>addrtypes</parameter> is a bitmask indicating which type ofaddresses are to be looked up. Current values for this bitmask are<type>LWRES_ADDRTYPE_V4</type> for IPv4 addresses and<type>LWRES_ADDRTYPE_V6</type> for IPv6 addresses. Results of thelookup are returned in <parameter>*structp</parameter>.</para><para><function>lwres_getnamebyaddr()</function> performs reverse lookups.Resolver context <parameter>ctx</parameter> is used for memoryallocation. The address type is indicated by<parameter>addrtype</parameter>: <type>LWRES_ADDRTYPE_V4</type> or<type>LWRES_ADDRTYPE_V6</type>. The address to be looked up is givenby <parameter>addr</parameter> and its length is<parameter>addrlen</parameter> bytes. The result of the function callis made available through <parameter>*structp</parameter>.</para></refsect1><refsect1><title>RETURN VALUES</title><para>Successful calls to<function>lwres_string_parse()</function>and<function>lwres_addr_parse()</function>return<errorcode>LWRES_R_SUCCESS.</errorcode>Both functions return<errorcode>LWRES_R_FAILURE</errorcode>if the buffer is corrupt or<errorcode>LWRES_R_UNEXPECTEDEND</errorcode>if the buffer has less space than expected for the components of theencoded string or address.</para><para><function>lwres_getaddrsbyname()</function>returns<errorcode>LWRES_R_SUCCESS</errorcode>on success and it returns<errorcode>LWRES_R_NOTFOUND</errorcode>if the hostname<parameter>name</parameter>could not be found.</para><para><errorcode>LWRES_R_SUCCESS</errorcode>is returned by a successful call to<function>lwres_getnamebyaddr()</function>.</para><para>Both<function>lwres_getaddrsbyname()</function>and<function>lwres_getnamebyaddr()</function>return<errorcode>LWRES_R_NOMEMORY</errorcode>when memory allocation requests fail and<errorcode>LWRES_R_UNEXPECTEDEND</errorcode>if the buffers used for sending queries and receiving replies are toosmall.</para></refsect1><refsect1><title>SEE ALSO</title><para><citerefentry><refentrytitle>lwres_buffer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,<citerefentry><refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></refsect1></refentry>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -