/**************************************************************************** ** ** File: dynports.c ** ** Author: Mike Borella ** ** Comments: Support for dynamic port mapping. This allows a protocol to ** to listened for on a non-standard port. Each mapping is assigned a ** duration. Mappings that are user defined via the command line are ** considered permanent. Mappings that are made by protocols will time out ** in DYNPORTS_DURATION seconds unless they are refreshed. ** ** $Id: dynports.c,v 1.7 2002/01/02 18:16:39 mborella Exp $ ** ** This program 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. ** ** This program 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 Library General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ** *****************************************************************************/ #include "dynports.h" #include "error.h" #include "limits.h" #define DYNPORTS_NUM 256/* max number of dynamic ports on the system */ #define DYNPORTS_DURATION 5 /* # of seconds that nonpermanent mappings stay */ typedef struct portmap { u_int16_t port; service_func_t f; unsigned long t; } portmap_t; static portmap_t dynport_map[DYNPORTS_NUM]; static int current_ptr = 0; /*---------------------------------------------------------------------------- ** ** dynports_add() ** ** Adds a dynamic port mapping ** **---------------------------------------------------------------------------- */ void dynports_add(u_int16_t port, service_func_t f, unsigned long t) { if (current_ptr >= DYNPORTS_NUM) error_fatal("too many dynamic port mappings"); dynport_map[current_ptr].port = port; dynport_map[current_ptr].f = f; dynport_map[current_ptr].t = t; current_ptr++; } /*---------------------------------------------------------------------------- ** ** dynports_refresh() ** ** Refreshes dynamic port mapping, by adding the mapping again with the ** current time. ** **---------------------------------------------------------------------------- */ void dynports_refresh(u_int16_t port, service_func_t f) { struct timeval t; int i; /* get the current time */ gettimeofday(&t, NULL); /* refresh the dynamic port mapping with the current time */ for (i=0; i