X-Git-Url: https://git.distorted.org.uk/~mdw/fwd/blobdiff_plain/e0ce9d387ef6ee881ef99317161eec97ebdcee38..bdbbfcd4eb2f6e15270f558342630d964cb9f418:/addr.h diff --git a/addr.h b/addr.h index cc5b790..6b16c52 100644 --- a/addr.h +++ b/addr.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: addr.h,v 1.2 1999/07/27 18:30:53 mdw Exp $ + * $Id: addr.h,v 1.4 2003/11/29 20:36:07 mdw Exp $ * * Generic interface to network address handlers * @@ -29,6 +29,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: addr.h,v $ + * Revision 1.4 2003/11/29 20:36:07 mdw + * Privileged outgoing connections. + * + * 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. * @@ -50,11 +56,16 @@ #include #include +#include #ifndef REFFD_H # include "reffd.h" #endif +#ifndef ENDPT_H +# include "endpt.h" +#endif + #ifndef SCAN_H # include "scan.h" #endif @@ -73,11 +84,6 @@ typedef struct addr { size_t sz; } addr; -typedef struct gen_addr { - addr a; - struct sockaddr sa; -} gen_addr; - #define ADDRSZ(sz) (sizeof(addr) + (sz)) /* --- Address configuration --- * @@ -99,14 +105,14 @@ typedef struct addr_opts { 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@ --- * * @@ -145,7 +151,7 @@ typedef struct addr_ops { void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/); - /* --- @initopts@ --- * + /* --- @initsrcopts@ --- * * * Arguments: --- * @@ -156,34 +162,36 @@ typedef struct addr_ops { * 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 * @@ -192,20 +200,20 @@ typedef struct addr_ops { * 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@ --- * * @@ -220,6 +228,66 @@ typedef struct addr_ops { 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 -------------------------------------------------*/