/* -*-c-*-
*
- * $Id: addr.h,v 1.1 1999/07/26 23:34:26 mdw Exp $
+ * $Id: addr.h,v 1.3 2003/11/25 14:08:23 mdw Exp $
*
* Generic interface to network address handlers
*
/*----- Revision history --------------------------------------------------*
*
* $Log: addr.h,v $
+ * Revision 1.3 2003/11/25 14:08:23 mdw
+ * Debianization. Socket target options. Internet binding.
+ *
+ * Revision 1.2 1999/07/27 18:30:53 mdw
+ * Various minor portability fixes.
+ *
* Revision 1.1 1999/07/26 23:34:26 mdw
* Socket address type management.
*
/*----- 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
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*/, unsigned /*type*/);
+
+ /* --- @freesrcopts@ --- *
+ *
+ * Arguments: @addr_opts *ao@ = data block to remove
+ *
+ * Returns: ---
+ *
+ * Use: Throws away all the configuration data for an address type.
+ */
+
+ void (*freesrcopts)(addr_opts */*ao*/);
+
+ /* --- @bind@ --- *
+ *
+ * Arguments: @addr *a@ = the address to bind to
+ * @addr_opts *ao@ = the address options
+ *
+ * Returns: File descriptor of bound socket if OK, or @-1@ on error.
+ *
+ * Use: Binds a listening socket. The tedious stuff with @listen@
+ * isn't necessary.
*/
- int (*option)(scanner */*sc*/, addr_opts */*ao*/);
+ int (*bind)(addr */*a*/, addr_opts */*ao*/);
+
+ /* --- @unbind@ --- *
+ *
+ * Arguments: @addr *a@ = pointer to an address
+ *
+ * Returns: ---
+ *
+ * Use: Unbinds an address. This is used when tidying up. The main
+ * purpose is to let the Unix-domain handler remove its socket
+ * node from the filesystem.
+ */
+
+ void (*unbind)(addr */*a*/);
/* --- @accept@ --- *
*
reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
- /* --- @freeopts@ --- *
+ /* --- @inittargopts@ --- *
*
- * Arguments: @addr_opts *ao@ = data block to remove
+ * Arguments: ---
*
- * Returns: ---
+ * Returns: A pointer to a protocol-specific data block for a connecter
*
- * Use: Throws away all the configuration data for an address type.
+ * 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.
*/
- void (*freeopts)(addr_opts */*ao*/);
+ addr_opts *(*inittargopts)(void);
- /* --- @bound@ --- *
+ /* --- @freetargopts@ --- *
*
- * Arguments: @addr *a@ = pointer to an address
- * @addr_opts *ao@ = pointer to attributes block
+ * Arguments: @addr_opts *ao@ = data block to remove
*
* Returns: ---
*
- * Use: Reports that a file descriptor has been (successfully) bound
- * to an address.
+ * Use: Throws away all the configuration data for an address type.
*/
- void (*bound)(addr */*a*/, addr_opts */*ao*/);
+ void (*freetargopts)(addr_opts */*ao*/);
- /* --- @unbind@ --- *
+ /* --- @connect@ --- *
*
- * Arguments: @addr *a@ = pointer to an address
+ * Arguments: @addr *a@ = destination address
+ * @addr_opts *ao@ = target address options
+ * @conn *c@ = connection structure
+ * @endpt *e@ = endpoint structure
*
- * Returns: ---
+ * Returns: Zero if OK, @-1@ on some error.
*
- * Use: Unbinds an address. This is used when tidying up. The main
- * purpose is to let the Unix-domain handler remove its socket
- * node from the filesystem.
+ * 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.
*/
- void (*unbind)(addr */*a*/);
+ int (*connect)(addr */*a*/, addr_opts */*ao*/, conn */*c*/, endpt */*e*/);
} addr_ops;