3 * $Id: addr.h,v 1.2 1999/07/27 18:30:53 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.2 1999/07/27 18:30:53 mdw
33 * Various minor portability fixes.
35 * Revision 1.1 1999/07/26 23:34:26 mdw
36 * Socket address type management.
47 /*----- Header files ------------------------------------------------------*/
49 #include <sys/types.h>
50 #include <sys/socket.h>
52 #include <mLib/dstr.h>
62 /*----- Data structures ---------------------------------------------------*/
64 /* --- A generic socket address --- *
66 * Not all systems understand @sa_len@ fields. (In particular, Linux
67 * doesn't.) Some fairly ugly hacking is then performed on particular
76 typedef struct gen_addr
{
81 #define ADDRSZ(sz) (sizeof(addr) + (sz))
83 /* --- Address configuration --- *
85 * An address family will want to extend this.
88 typedef struct addr_opts
{
92 #define ADDRF_NOLOG 1u
94 /* --- Address types --- *
96 * For things like Internet addresses, source and destinations look
105 /* --- Description of an address type handler --- */
107 typedef struct addr_ops
{
108 const char *name
; /* Protocol's internal name */
109 int pf
; /* Protocol family number */
113 * Arguments: @scanner *sc@ = pointer to scanner to read from
114 * @unsigned type@ = type of address to be read
116 * Returns: A filled-in socket address.
118 * Use: Parses a textual representation of a socket address.
121 addr
*(*read
)(scanner */
*sc*/
, unsigned /*type*/);
123 /* --- @destroy@ --- *
125 * Arguments: @addr *a@ = pointer to an address block
129 * Use: Disposes of an address block in some suitable fashion.
132 void (*destroy
)(addr */
*a*/
);
136 * Arguments: @addr *a@ = pointer to socket address to read
137 * @unsigned type@ = type of address to be written
138 * @dstr *d@ = string on which to write the description
142 * Use: Writes a textual representation of a socket address to
146 void (*print
)(addr */
*a*/
, unsigned /*type*/, dstr */
*d*/
);
148 /* --- @initopts@ --- *
152 * Returns: A pointer to a protocol-specific data block for a listener
154 * Use: Creates a data block for a listener. This is attached to the
155 * listener data structure. Options can then be requested, and
156 * are added to the block when necessary.
159 addr_opts
*(*initopts
)(void);
161 /* --- @option@ --- *
163 * Arguments: @scanner *sc@ = pointer to a scanner to read from
164 * @addr_opts *ao@ = data block to modify (from @init@), or null
166 * Returns: Nonzero to claim the option.
168 * Use: Parses an option, either global or listener-specific.
171 int (*option
)(scanner */
*sc*/
, addr_opts */
*ao*/
);
173 /* --- @accept@ --- *
175 * Arguments: @int fd@ = listening file descriptor
176 * @addr_opts *ao@ = data block to get configuration from
177 * @const char *desc@ = description of the listener
179 * Returns: Pointer to a reference counted file descriptor.
181 * Use: Accepts, verifies and logs an incoming connection.
184 reffd
*(*accept
)(int /*fd*/, addr_opts */
*ao*/
, const char */
*desc*/
);
186 /* --- @freeopts@ --- *
188 * Arguments: @addr_opts *ao@ = data block to remove
192 * Use: Throws away all the configuration data for an address type.
195 void (*freeopts
)(addr_opts */
*ao*/
);
199 * Arguments: @addr *a@ = pointer to an address
200 * @addr_opts *ao@ = pointer to attributes block
204 * Use: Reports that a file descriptor has been (successfully) bound
208 void (*bound
)(addr */
*a*/
, addr_opts */
*ao*/
);
210 /* --- @unbind@ --- *
212 * Arguments: @addr *a@ = pointer to an address
216 * Use: Unbinds an address. This is used when tidying up. The main
217 * purpose is to let the Unix-domain handler remove its socket
218 * node from the filesystem.
221 void (*unbind
)(addr */
*a*/
);
225 /*----- That's all, folks -------------------------------------------------*/