@@@ much mess, mostly manpages
[mLib] / sel / bres.3.in
CommitLineData
83856dde 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for background name resolution
4.\"
5.\" (c) 1999, 2001, 2003, 2005, 2007, 2009, 2023, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
12.\" mLib is free software: you can redistribute it and/or modify it under
13.\" the terms of the GNU Library General Public License as published by
14.\" the Free Software Foundation; either version 2 of the License, or (at
15.\" your option) any later version.
16.\"
17.\" mLib is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20.\" License for more details.
21.\"
22.\" You should have received a copy of the GNU Library General Public
23.\" License along with mLib. If not, write to the Free Software
24.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH bres 3mLib "1 October 1999" "Straylight/Edgeware" "mLib utilities library"
83856dde 32.\" @bres_abort
33.\" @bres_byname
34.\" @bres_byaddr
35.\" @bres_exec
36.\" @bres_init
c4ccbbf9
MW
37.
38.\"--------------------------------------------------------------------------
39.SH NAME
40bres \- background name resolver
41.
42.\"--------------------------------------------------------------------------
83856dde 43.SH SYNOPSIS
c4ccbbf9 44.
83856dde 45.nf
46.B "#include <mLib/bres.h>"
d056fbdf 47.PP
4729aa69 48.B "typedef struct { ...\& } bres_client;"
d056fbdf 49.PP
adec5584
MW
50.ta \w'\fBvoid bres_byname('u
51.BI "void bres_byname(bres_client *" rc ", const char *" name ,
52.BI " void (*" func ")(struct hostent *" h ", void *" p ),
53.BI " void *" p );
54.ta \w'\fBvoid bres_byaddr('u
55.BI "void bres_byaddr(res_client *" rc ", struct inaddr " addr ,
56.BI " void (*" func ")(struct hostent *" h ", void *" p ),
57.BI " void *" p );
83856dde 58.BI "void bres_abort(bres_client *" rc );
59.BI "void bres_exec(const char *" file );
60.BI "void bres_init(sel_state *" sel );
61.fi
c4ccbbf9
MW
62.
63.\"--------------------------------------------------------------------------
83856dde 64.SH DESCRIPTION
c4ccbbf9 65.
83856dde 66The
67.B bres.h
68header file declares types and functions for doing translation between
69host names and IP addresses in the background.
70.PP
71The system must be initialized before use by a call to
72.BR bres_init ,
73passing it the address of an I/O multiplexor (see
74.BR sel (3)).
75.PP
76A resolver task is stored in an object of type
77.BR bres_client ,
78the storage for which is allocated by the caller. The object is a
79structure, and its contents are unspecified. The object is initialized
80by one of the name resolution functions
81.B bres_byname
82and
83.BR bres_byaddr .
84Each function is passed the following arguments:
85.TP
86.BI "bres_client *" rc
87Pointer to the client block to initialize and store the resolver job's
88state.
89.TP
adec5584
MW
90.BR "struct in_addr " \fIaddr "" " (" bres_byaddr )
91.ie t .sp -0.4v
92.el .sp -1v
83856dde 93.TP
adec5584 94.BR "const char *" \fIname "" " (" bres_byname )
83856dde 95The IP address or hostname to resolve.
96.TP
97.BI "void (*" func ")(struct hostent *" h ", void *" p )
98A handler function to call when the resolver job is complete.
99.TP
100.BI "void *" p
101A pointer argument to pass to the handler function.
102.PP
103The
104.B bres_client
105block must not be discarded until either the job is complete (i.e., the
106handler function has been called) or
107.B bres_abort
108is called on it.
109.PP
110The handler function is passed either the address of a
111.B "struct hostent"
112structure describing the resolved host, or a null pointer indicating
113failure. The
114.B hostent
115structure is as returned by the standard
116.BR gethostbyname (3)
117and
118.BR gethostbyaddr (3)
119functions. This isn't the most convenient format for the results, but
120it does have the benefit of being standard. Similarly, errors are
121reported through the global
122.B h_errno
123variable.
124.PP
125The function
126.B bres_abort
127cancels a running resolver job. When it returns, the client structure
128is safe to discard.
129.PP
d4efbcd9 130There are two versions of
14d7100d 131.BR bres .
132The standard one uses a pool of server processes. Incoming resolver
133jobs are passed to an available server, or a new server is started if
134all are busy. There is a maximum number of servers, and jobs are queued
135once this limit is reached. Old servers which have been idle for a
136period of time are killed off. Servers are also killed if they start
137misbehaving or their jobs are aborted.
83856dde 138.PP
139By default, servers are started simply by calling
140.BR fork (2).
141This can cause undesirably high memory usage in large programs. The
142function
143.B bres_exec
144requests the resolver system to
145.BR exec (2)
146a small dedicated server program to perform name lookups to reduce
147memory consumption. The argument to
148.B bres_exec
149is the full pathname of the server program, or null to accept the
150default set at library configuration time (which is usually correct).
151.PP
14d7100d 152The other implementation of
153.B bres
154uses the
155.B adns
156library to do asynchronous resolution. It can cope with many more
157simultaneous resolver jobs, and doesn't use up external processes. If
158you're using the
159.BR adns -based
160resolver, then the
161.B bres_exec
162function does nothing at all.
163.PP
83856dde 164For security reasons, when an address is resolved, the hostname received
165is verified by performing a forward lookup. If the forward lookup fails
166to return the expected IP address, an error is reported.
c4ccbbf9
MW
167.
168.\"--------------------------------------------------------------------------
83856dde 169.SH "SEE ALSO"
c4ccbbf9 170.
83856dde 171.BR gethostbyname (3),
172.BR gethostbyaddr (3),
173.BR sel (3),
174.BR mLib (3).
c4ccbbf9
MW
175.
176.\"--------------------------------------------------------------------------
83856dde 177.SH "AUTHOR"
c4ccbbf9 178.
9b5ac6ff 179Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
180.
181.\"----- That's all, folks --------------------------------------------------