Commit | Line | Data |
---|---|---|
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 | |
40 | bres \- 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 | 66 | The |
67 | .B bres.h | |
68 | header file declares types and functions for doing translation between | |
69 | host names and IP addresses in the background. | |
70 | .PP | |
71 | The system must be initialized before use by a call to | |
72 | .BR bres_init , | |
73 | passing it the address of an I/O multiplexor (see | |
74 | .BR sel (3)). | |
75 | .PP | |
76 | A resolver task is stored in an object of type | |
77 | .BR bres_client , | |
78 | the storage for which is allocated by the caller. The object is a | |
79 | structure, and its contents are unspecified. The object is initialized | |
80 | by one of the name resolution functions | |
81 | .B bres_byname | |
82 | and | |
83 | .BR bres_byaddr . | |
84 | Each function is passed the following arguments: | |
85 | .TP | |
86 | .BI "bres_client *" rc | |
87 | Pointer to the client block to initialize and store the resolver job's | |
88 | state. | |
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 | 95 | The IP address or hostname to resolve. |
96 | .TP | |
97 | .BI "void (*" func ")(struct hostent *" h ", void *" p ) | |
98 | A handler function to call when the resolver job is complete. | |
99 | .TP | |
100 | .BI "void *" p | |
101 | A pointer argument to pass to the handler function. | |
102 | .PP | |
103 | The | |
104 | .B bres_client | |
105 | block must not be discarded until either the job is complete (i.e., the | |
106 | handler function has been called) or | |
107 | .B bres_abort | |
108 | is called on it. | |
109 | .PP | |
110 | The handler function is passed either the address of a | |
111 | .B "struct hostent" | |
112 | structure describing the resolved host, or a null pointer indicating | |
113 | failure. The | |
114 | .B hostent | |
115 | structure is as returned by the standard | |
116 | .BR gethostbyname (3) | |
117 | and | |
118 | .BR gethostbyaddr (3) | |
119 | functions. This isn't the most convenient format for the results, but | |
120 | it does have the benefit of being standard. Similarly, errors are | |
121 | reported through the global | |
122 | .B h_errno | |
123 | variable. | |
124 | .PP | |
125 | The function | |
126 | .B bres_abort | |
127 | cancels a running resolver job. When it returns, the client structure | |
128 | is safe to discard. | |
129 | .PP | |
d4efbcd9 | 130 | There are two versions of |
14d7100d | 131 | .BR bres . |
132 | The standard one uses a pool of server processes. Incoming resolver | |
133 | jobs are passed to an available server, or a new server is started if | |
134 | all are busy. There is a maximum number of servers, and jobs are queued | |
135 | once this limit is reached. Old servers which have been idle for a | |
136 | period of time are killed off. Servers are also killed if they start | |
137 | misbehaving or their jobs are aborted. | |
83856dde | 138 | .PP |
139 | By default, servers are started simply by calling | |
140 | .BR fork (2). | |
141 | This can cause undesirably high memory usage in large programs. The | |
142 | function | |
143 | .B bres_exec | |
144 | requests the resolver system to | |
145 | .BR exec (2) | |
146 | a small dedicated server program to perform name lookups to reduce | |
147 | memory consumption. The argument to | |
148 | .B bres_exec | |
149 | is the full pathname of the server program, or null to accept the | |
150 | default set at library configuration time (which is usually correct). | |
151 | .PP | |
14d7100d | 152 | The other implementation of |
153 | .B bres | |
154 | uses the | |
155 | .B adns | |
156 | library to do asynchronous resolution. It can cope with many more | |
157 | simultaneous resolver jobs, and doesn't use up external processes. If | |
158 | you're using the | |
159 | .BR adns -based | |
160 | resolver, then the | |
161 | .B bres_exec | |
162 | function does nothing at all. | |
163 | .PP | |
83856dde | 164 | For security reasons, when an address is resolved, the hostname received |
165 | is verified by performing a forward lookup. If the forward lookup fails | |
166 | to 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 | 179 | Mark Wooding, <mdw@distorted.org.uk> |
c4ccbbf9 MW |
180 | . |
181 | .\"----- That's all, folks -------------------------------------------------- |