/* -*-c-*-
*
- * $Id: addr.h,v 1.1 1999/07/26 23:34:26 mdw Exp $
- *
* Generic interface to network address handlers
*
* (c) 1999 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of the `fw' port forwarder.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* `fw' is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with `fw'; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: addr.h,v $
- * Revision 1.1 1999/07/26 23:34:26 mdw
- * Socket address type management.
- *
- */
-
#ifndef ADDR_H
#define ADDR_H
/*----- Header files ------------------------------------------------------*/
+#include <sys/types.h>
#include <sys/socket.h>
#include <mLib/dstr.h>
+#include <mLib/conn.h>
#ifndef REFFD_H
# include "reffd.h"
#endif
+#ifndef ENDPT_H
+# include "endpt.h"
+#endif
+
#ifndef SCAN_H
# include "scan.h"
#endif
/*----- Data structures ---------------------------------------------------*/
-
+
/* --- A generic socket address --- *
*
* Not all systems understand @sa_len@ fields. (In particular, Linux
size_t sz;
} addr;
-typedef struct gen_addr {
- addr a;
- struct sockaddr sa;
-} gen_addr;
-
#define ADDRSZ(sz) (sizeof(addr) + (sz))
/* --- Address configuration --- *
enum {
ADDR_SRC,
- ADDR_DEST
+ ADDR_DEST,
+ ADDR_GLOBAL
};
/* --- Description of an address type handler --- */
typedef struct addr_ops {
const char *name; /* Protocol's internal name */
- int pf; /* Protocol family number */
/* --- @read@ --- *
*
void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/);
- /* --- @initopts@ --- *
+ /* --- @initsrcopts@ --- *
*
* Arguments: ---
*
* are added to the block when necessary.
*/
- addr_opts *(*initopts)(void);
+ addr_opts *(*initsrcopts)(void);
/* --- @option@ --- *
*
* Arguments: @scanner *sc@ = pointer to a scanner to read from
+ * @unsigned type@ = kind of option this is
* @addr_opts *ao@ = data block to modify (from @init@), or null
*
* Returns: Nonzero to claim the option.
*
- * Use: Parses an option, either global or listener-specific.
+ * Use: Parses a source option, either global or listener-specific.
*/
- int (*option)(scanner */*sc*/, addr_opts */*ao*/);
+ int (*option)(scanner */*sc*/, addr_opts */*ao*/, unsigned /*type*/);
- /* --- @accept@ --- *
+ /* --- @confirm@ --- *
*
- * Arguments: @int fd@ = listening file descriptor
- * @addr_opts *ao@ = data block to get configuration from
- * @const char *desc@ = description of the listener
+ * Arguments: @addr *a@ = pointer to an address structure
+ * @unsigned type@ = kind of address this is
+ * @addr_opts *ao@ = address options
*
- * Returns: Pointer to a reference counted file descriptor.
+ * Returns: ---
*
- * Use: Accepts, verifies and logs an incoming connection.
+ * Use: Called during initialization when an address is fully
+ * configured.
*/
- reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
+ void (*confirm)(addr */*a*/, unsigned /*type*/, addr_opts */*ao*/);
- /* --- @freeopts@ --- *
+ /* --- @freesrcopts@ --- *
*
* Arguments: @addr_opts *ao@ = data block to remove
*
* Use: Throws away all the configuration data for an address type.
*/
- void (*freeopts)(addr_opts */*ao*/);
+ void (*freesrcopts)(addr_opts */*ao*/);
- /* --- @bound@ --- *
+ /* --- @bind@ --- *
*
- * Arguments: @addr *a@ = pointer to an address
- * @addr_opts *ao@ = pointer to attributes block
+ * Arguments: @addr *a@ = the address to bind to
+ * @addr_opts *ao@ = the address options
*
- * Returns: ---
+ * Returns: File descriptor of bound socket if OK, or @-1@ on error.
*
- * Use: Reports that a file descriptor has been (successfully) bound
- * to an address.
+ * Use: Binds a listening socket. The tedious stuff with @listen@
+ * isn't necessary.
*/
- void (*bound)(addr */*a*/, addr_opts */*ao*/);
+ int (*bind)(addr */*a*/, addr_opts */*ao*/);
/* --- @unbind@ --- *
*
void (*unbind)(addr */*a*/);
+ /* --- @accept@ --- *
+ *
+ * Arguments: @int fd@ = listening file descriptor
+ * @addr_opts *ao@ = data block to get configuration from
+ * @const char *desc@ = description of the listener
+ *
+ * Returns: Pointer to a reference counted file descriptor.
+ *
+ * Use: Accepts, verifies and logs an incoming connection.
+ */
+
+ reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
+
+ /* --- @inittargopts@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: A pointer to a protocol-specific data block for a connecter
+ *
+ * Use: Creates a data block for a target. This is attached to the
+ * target data structure. Options can then be requested, and
+ * are added to the block when necessary.
+ */
+
+ addr_opts *(*inittargopts)(void);
+
+ /* --- @freetargopts@ --- *
+ *
+ * Arguments: @addr_opts *ao@ = data block to remove
+ *
+ * Returns: ---
+ *
+ * Use: Throws away all the configuration data for an address type.
+ */
+
+ void (*freetargopts)(addr_opts */*ao*/);
+
+ /* --- @connect@ --- *
+ *
+ * Arguments: @addr *a@ = destination address
+ * @addr_opts *ao@ = target address options
+ * @conn *c@ = connection structure
+ * @endpt *e@ = endpoint structure
+ *
+ * Returns: Zero if OK, @-1@ on some error.
+ *
+ * Use: Requests that a connection be made, or at least set in
+ * motion. An address may do one of these things:
+ *
+ * * Return @-1@.
+ *
+ * * Call @starget_connected@ with @-1@ or a connected file
+ * descriptor and the pointer @e@.
+ *
+ * * Call @conn_init@ or @conn_fd@, giving @starget_connected@
+ * and @e@ as the function to call.
+ */
+
+ int (*connect)(addr */*a*/, addr_opts */*ao*/, conn */*c*/, endpt */*e*/);
+
} addr_ops;
-
+
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus