From 479a34d9c4a1c520d43f9502747285cd060661da Mon Sep 17 00:00:00 2001 From: mdw Date: Mon, 26 Jul 1999 23:34:26 +0000 Subject: [PATCH] Socket address type management. --- addr.h | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 addr.h diff --git a/addr.h b/addr.h new file mode 100644 index 0000000..411d0a7 --- /dev/null +++ b/addr.h @@ -0,0 +1,227 @@ +/* -*-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 --------------------------------------------------* + * + * This file is part of the `fw' port forwarder. + * + * `fw' is free software; you can redistribute it and/or modify + * 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 + +#ifdef __cplusplus + extern "C" { +#endif + +/*----- Header files ------------------------------------------------------*/ + +#include + +#include + +#ifndef REFFD_H +# include "reffd.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 + * doesn't.) Some fairly ugly hacking is then performed on particular + * address types. + */ + +typedef struct addr { + struct addr_ops *ops; + size_t sz; +} addr; + +typedef struct gen_addr { + addr a; + struct sockaddr sa; +} gen_addr; + +#define ADDRSZ(sz) (sizeof(addr) + (sz)) + +/* --- Address configuration --- * + * + * An address family will want to extend this. + */ + +typedef struct addr_opts { + unsigned f; +} addr_opts; + +#define ADDRF_NOLOG 1u + +/* --- Address types --- * + * + * For things like Internet addresses, source and destinations look + * different. + */ + +enum { + ADDR_SRC, + ADDR_DEST +}; + +/* --- Description of an address type handler --- */ + +typedef struct addr_ops { + const char *name; /* Protocol's internal name */ + int pf; /* Protocol family number */ + + /* --- @read@ --- * + * + * Arguments: @scanner *sc@ = pointer to scanner to read from + * @unsigned type@ = type of address to be read + * + * Returns: A filled-in socket address. + * + * Use: Parses a textual representation of a socket address. + */ + + addr *(*read)(scanner */*sc*/, unsigned /*type*/); + + /* --- @destroy@ --- * + * + * Arguments: @addr *a@ = pointer to an address block + * + * Returns: --- + * + * Use: Disposes of an address block in some suitable fashion. + */ + + void (*destroy)(addr */*a*/); + + /* --- @print@ --- * + * + * Arguments: @addr *a@ = pointer to socket address to read + * @unsigned type@ = type of address to be written + * @dstr *d@ = string on which to write the description + * + * Returns: --- + * + * Use: Writes a textual representation of a socket address to + * a string. + */ + + void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/); + + /* --- @initopts@ --- * + * + * Arguments: --- + * + * Returns: A pointer to a protocol-specific data block for a listener + * + * Use: Creates a data block for a listener. This is attached to the + * listener data structure. Options can then be requested, and + * are added to the block when necessary. + */ + + addr_opts *(*initopts)(void); + + /* --- @option@ --- * + * + * Arguments: @scanner *sc@ = pointer to a scanner to read from + * @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. + */ + + int (*option)(scanner */*sc*/, addr_opts */*ao*/); + + /* --- @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*/); + + /* --- @freeopts@ --- * + * + * Arguments: @addr_opts *ao@ = data block to remove + * + * Returns: --- + * + * Use: Throws away all the configuration data for an address type. + */ + + void (*freeopts)(addr_opts */*ao*/); + + /* --- @bound@ --- * + * + * Arguments: @addr *a@ = pointer to an address + * @addr_opts *ao@ = pointer to attributes block + * + * Returns: --- + * + * Use: Reports that a file descriptor has been (successfully) bound + * to an address. + */ + + void (*bound)(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*/); + +} addr_ops; + +/*----- That's all, folks -------------------------------------------------*/ + +#ifdef __cplusplus + } +#endif + +#endif -- 2.11.0