lwres_resutil.3 revision 499b34cea04a46823d003d4c0520c8b03e8513cb
Copyright (C) 2000, 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 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_resutil.3,v 1.5 2001/01/09 21:50:21 bwelling Exp $
.Dd Jun 30, 2000 .Dt LWRES_RESUTIL 3 .Os BIND9 9 .Sh NAME .Nm lwres_string_parse , .Nm lwres_addr_parse , .Nm lwres_getaddrsbyname , .Nm lwres_getnamebyaddr .Nd lightweight resolver utility functions .Sh SYNOPSIS .Fd #include <lwres/lwres.h> .Fd .Ft lwres_result_t .Fo lwres_string_parse .Fa "lwres_buffer_t *b" .Fa "char **c" .Fa "lwres_uint16_t *len" .Fc .Ft lwres_result_t .Fo lwres_addr_parse .Fa "lwres_buffer_t *b" .Fa "lwres_addr_t *addr" .Fc .Ft lwres_result_t .Fo lwres_getaddrsbyname .Fa "lwres_context_t *ctx" .Fa "const char *name" .Fa "lwres_uint32_t addrtypes" .Fa "lwres_gabnresponse_t **structp" .Fc .Ft lwres_result_t .Fo lwres_getnamebyaddr .Fa "lwres_context_t *ctx" .Fa "lwres_uint32_t addrtype" .Fa "lwres_uint16_t addrlen" .Fa "const unsigned char *addr" .Fa "lwres_gnbaresponse_t **structp" .Fc .Sh DESCRIPTION .Fn lwres_string_parse retrieves a DNS-encoded string starting the current pointer of lightweight resolver buffer .Fa b : i.e. .Li b->current . When the function returns, the address of the first byte of the encoded string is returned via .Fa *c and the length of that string is given by .Fa *len . The buffer's current pointer is advanced to point at the character following the string length, the encoded string, and the trailing .Dv NULL character. .Fn lwres_string_parse has an assertion check that .Fa b is not .Dv NULL .

p .Fn lwres_addr_parse extracts an address from the buffer .Fa b . It checks that .Fa addr is not null. The buffer's current pointer .Li b->current is presumed to point at an encoded address: the address preceded by a 32-bit protocol family identifier and a 16-bit length field. The encoded address is copied to .Li addr->address and .Li addr->length indicates the size in bytes of the address that was copied. .Li b->current is advanced to point at the next byte of available data in the buffer following the encoded address.

p .Fn lwres_getaddrsbyname and .Fn lwres_getnamebyaddr use the .Dv "lwres_gnbaresponse_t" structure defined below: d -literal -offset indent 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; .Ed The contents of this structure are not manipulated directly but they are controlled through the .Xr lwres_gabn 3 functions.

p The lightweight resolver uses .Fn lwres_getaddrsbyname to perform foward lookups. Hostname .Fa name is looked up using the resolver context .Fa ctx for memory allocation. .Fa addrtypes is a bitmask indicating which type of addresses are to be looked up. Current values for this bitmask are .Dv LWRES_ADDRTYPE_V4 for IPv4 addresses and .Dv LWRES_ADDRTYPE_V6 for IPv6 addresses. Results of the lookup are returned in .Fa *structp . .Fn lwres_getaddrsbyname checks that its pointer arguments are not .Dv NULL and that .Fa addrtypes is non-zero.

p .Fn lwres_getnamebyaddr performs reverse lookups. Resolver context .Fa ctx is used for memory allocation. The address type is indicated by .Fa addrtype : .Dv LWRES_ADDRTYPE_V4 or .Dv LWRES_ADDRTYPE_V6 . The address to be looked up is given by .Fa addr and its length is .Fa addrlen bytes. The result of the function call is made available through .Fa *structp . Like .Fn lwres_getaddrsbyname , .Fn lwres_getnamebyaddr uses assertion checking to ensure its pointer arguments are not .Dv NULL and .Fa addrtype is not zero. .Fn lwres_getaddrsbyname also checks that .Fa addrlen is non-zero. .Sh RETURN VALUES Successful calls to .Fn lwres_string_parse and .Fn lwres_addr_parse return .Er LWRES_R_SUCCESS. Both functions return .Er LWRES_R_FAILURE if the buffer is corrupt or .Er LWRES_R_UNEXPECTEDEND if the buffer has less space than expected for the components of the encoded string or address.

p .Fn lwres_getaddrsbyname returns .Er LWRES_R_SUCCESS on success and it returns .Er LWRES_R_NOTFOUND if the hostname .Fa name could not be found.

p .Er LWRES_R_SUCCESS is returned by a successful call to .Fn lwres_getnamebyaddr .

p Both .Fn lwres_getaddrsbyname and .Fn lwres_getnamebyaddr return .Er LWRES_R_NOMEMORY when memory allocation requests fail and .Er LWRES_R_UNEXPECTEDEND if the buffers used for sending queries and receiving replies are too small. .Sh SEE ALSO .Xr lwres_buffer 3 , .Xr lwres_gabn 3 .