3 * $Id: addr.h,v 1.3 2003/11/25 14:08:23 mdw Exp $
5 * Generic interface to network address handlers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the `fw' port forwarder.
14 * `fw' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `fw' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `fw'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.3 2003/11/25 14:08:23 mdw
33 * Debianization. Socket target options. Internet binding.
35 * Revision 1.2 1999/07/27 18:30:53 mdw
36 * Various minor portability fixes.
38 * Revision 1.1 1999/07/26 23:34:26 mdw
39 * Socket address type management.
50 /*----- Header files ------------------------------------------------------*/
52 #include <sys/types.h>
53 #include <sys/socket.h>
55 #include <mLib/dstr.h>
56 #include <mLib/conn.h>
70 /*----- Data structures ---------------------------------------------------*/
72 /* --- A generic socket address --- *
74 * Not all systems understand @sa_len@ fields. (In particular, Linux
75 * doesn't.) Some fairly ugly hacking is then performed on particular
84 #define ADDRSZ(sz) (sizeof(addr) + (sz))
86 /* --- Address configuration --- *
88 * An address family will want to extend this.
91 typedef struct addr_opts {
95 #define ADDRF_NOLOG 1u
97 /* --- Address types --- *
99 * For things like Internet addresses, source and destinations look
109 /* --- Description of an address type handler --- */
111 typedef struct addr_ops {
112 const char *name; /* Protocol's internal name */
116 * Arguments: @scanner *sc@ = pointer to scanner to read from
117 * @unsigned type@ = type of address to be read
119 * Returns: A filled-in socket address.
121 * Use: Parses a textual representation of a socket address.
124 addr *(*read)(scanner */*sc*/, unsigned /*type*/);
126 /* --- @destroy@ --- *
128 * Arguments: @addr *a@ = pointer to an address block
132 * Use: Disposes of an address block in some suitable fashion.
135 void (*destroy)(addr */*a*/);
139 * Arguments: @addr *a@ = pointer to socket address to read
140 * @unsigned type@ = type of address to be written
141 * @dstr *d@ = string on which to write the description
145 * Use: Writes a textual representation of a socket address to
149 void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/);
151 /* --- @initsrcopts@ --- *
155 * Returns: A pointer to a protocol-specific data block for a listener
157 * Use: Creates a data block for a listener. This is attached to the
158 * listener data structure. Options can then be requested, and
159 * are added to the block when necessary.
162 addr_opts *(*initsrcopts)(void);
164 /* --- @option@ --- *
166 * Arguments: @scanner *sc@ = pointer to a scanner to read from
167 * @unsigned type@ = kind of option this is
168 * @addr_opts *ao@ = data block to modify (from @init@), or null
170 * Returns: Nonzero to claim the option.
172 * Use: Parses a source option, either global or listener-specific.
175 int (*option)(scanner */*sc*/, addr_opts */*ao*/, unsigned /*type*/);
177 /* --- @freesrcopts@ --- *
179 * Arguments: @addr_opts *ao@ = data block to remove
183 * Use: Throws away all the configuration data for an address type.
186 void (*freesrcopts)(addr_opts */*ao*/);
190 * Arguments: @addr *a@ = the address to bind to
191 * @addr_opts *ao@ = the address options
193 * Returns: File descriptor of bound socket if OK, or @-1@ on error.
195 * Use: Binds a listening socket. The tedious stuff with @listen@
199 int (*bind)(addr */*a*/, addr_opts */*ao*/);
201 /* --- @unbind@ --- *
203 * Arguments: @addr *a@ = pointer to an address
207 * Use: Unbinds an address. This is used when tidying up. The main
208 * purpose is to let the Unix-domain handler remove its socket
209 * node from the filesystem.
212 void (*unbind)(addr */*a*/);
214 /* --- @accept@ --- *
216 * Arguments: @int fd@ = listening file descriptor
217 * @addr_opts *ao@ = data block to get configuration from
218 * @const char *desc@ = description of the listener
220 * Returns: Pointer to a reference counted file descriptor.
222 * Use: Accepts, verifies and logs an incoming connection.
225 reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
227 /* --- @inittargopts@ --- *
231 * Returns: A pointer to a protocol-specific data block for a connecter
233 * Use: Creates a data block for a target. This is attached to the
234 * target data structure. Options can then be requested, and
235 * are added to the block when necessary.
238 addr_opts *(*inittargopts)(void);
240 /* --- @freetargopts@ --- *
242 * Arguments: @addr_opts *ao@ = data block to remove
246 * Use: Throws away all the configuration data for an address type.
249 void (*freetargopts)(addr_opts */*ao*/);
251 /* --- @connect@ --- *
253 * Arguments: @addr *a@ = destination address
254 * @addr_opts *ao@ = target address options
255 * @conn *c@ = connection structure
256 * @endpt *e@ = endpoint structure
258 * Returns: Zero if OK, @-1@ on some error.
260 * Use: Requests that a connection be made, or at least set in
261 * motion. An address may do one of these things:
265 * * Call @starget_connected@ with @-1@ or a connected file
266 * descriptor and the pointer @e@.
268 * * Call @conn_init@ or @conn_fd@, giving @starget_connected@
269 * and @e@ as the function to call.
272 int (*connect)(addr */*a*/, addr_opts */*ao*/, conn */*c*/, endpt */*e*/);
276 /*----- That's all, folks -------------------------------------------------*/