3 * $Id: addr.h,v 1.1 1999/07/26 23:34:26 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.1 1999/07/26 23:34:26 mdw
33 * Socket address type management.
44 /*----- Header files ------------------------------------------------------*/
46 #include <sys/socket.h>
48 #include <mLib/dstr.h>
58 /*----- Data structures ---------------------------------------------------*/
60 /* --- A generic socket address --- *
62 * Not all systems understand @sa_len@ fields. (In particular, Linux
63 * doesn't.) Some fairly ugly hacking is then performed on particular
72 typedef struct gen_addr {
77 #define ADDRSZ(sz) (sizeof(addr) + (sz))
79 /* --- Address configuration --- *
81 * An address family will want to extend this.
84 typedef struct addr_opts {
88 #define ADDRF_NOLOG 1u
90 /* --- Address types --- *
92 * For things like Internet addresses, source and destinations look
101 /* --- Description of an address type handler --- */
103 typedef struct addr_ops {
104 const char *name; /* Protocol's internal name */
105 int pf; /* Protocol family number */
109 * Arguments: @scanner *sc@ = pointer to scanner to read from
110 * @unsigned type@ = type of address to be read
112 * Returns: A filled-in socket address.
114 * Use: Parses a textual representation of a socket address.
117 addr *(*read)(scanner */*sc*/, unsigned /*type*/);
119 /* --- @destroy@ --- *
121 * Arguments: @addr *a@ = pointer to an address block
125 * Use: Disposes of an address block in some suitable fashion.
128 void (*destroy)(addr */*a*/);
132 * Arguments: @addr *a@ = pointer to socket address to read
133 * @unsigned type@ = type of address to be written
134 * @dstr *d@ = string on which to write the description
138 * Use: Writes a textual representation of a socket address to
142 void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/);
144 /* --- @initopts@ --- *
148 * Returns: A pointer to a protocol-specific data block for a listener
150 * Use: Creates a data block for a listener. This is attached to the
151 * listener data structure. Options can then be requested, and
152 * are added to the block when necessary.
155 addr_opts *(*initopts)(void);
157 /* --- @option@ --- *
159 * Arguments: @scanner *sc@ = pointer to a scanner to read from
160 * @addr_opts *ao@ = data block to modify (from @init@), or null
162 * Returns: Nonzero to claim the option.
164 * Use: Parses an option, either global or listener-specific.
167 int (*option)(scanner */*sc*/, addr_opts */*ao*/);
169 /* --- @accept@ --- *
171 * Arguments: @int fd@ = listening file descriptor
172 * @addr_opts *ao@ = data block to get configuration from
173 * @const char *desc@ = description of the listener
175 * Returns: Pointer to a reference counted file descriptor.
177 * Use: Accepts, verifies and logs an incoming connection.
180 reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
182 /* --- @freeopts@ --- *
184 * Arguments: @addr_opts *ao@ = data block to remove
188 * Use: Throws away all the configuration data for an address type.
191 void (*freeopts)(addr_opts */*ao*/);
195 * Arguments: @addr *a@ = pointer to an address
196 * @addr_opts *ao@ = pointer to attributes block
200 * Use: Reports that a file descriptor has been (successfully) bound
204 void (*bound)(addr */*a*/, addr_opts */*ao*/);
206 /* --- @unbind@ --- *
208 * Arguments: @addr *a@ = pointer to an address
212 * Use: Unbinds an address. This is used when tidying up. The main
213 * purpose is to let the Unix-domain handler remove its socket
214 * node from the filesystem.
217 void (*unbind)(addr */*a*/);
221 /*----- That's all, folks -------------------------------------------------*/