PortGenerator.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: PortGenerator.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef _MK_PORTGENERATOR_HPP_ 00045 #define _MK_PORTGENERATOR_HPP_ 00046 00047 #include "global.hpp" 00048 00049 #define PROT_UDP 1 00050 #define PROT_TCP 0 00051 #define PORT_OFFS 19998 00052 #define PORT_RANGE 20000 00053 00065 class PortGenerator { 00066 00067 public: 00068 PortGenerator(); 00069 virtual ~ PortGenerator(); 00070 00071 /* randomly finds two consequtive udp ports for eg. RTSP handshake usage. 00072 * first port is even, second is first_port+1, so its always odd 00073 * @returns the first and even port number 00074 */ 00075 int getNextFreePortPair(int proto=PROT_UDP); 00076 00077 00078 /* use this to request a certain single port to be socket()ized and bind() 00079 * @returns the socket fd on success or zero 00080 */ 00081 int setSockAndPort(int port, int proto=PROT_UDP); 00082 00083 /* @returns the socket fd on success or zero */ 00084 int getSockFromPort(int port, int proto=PROT_UDP); 00085 00086 /* closes the port and socket 00087 * @returns true on success or false else */ 00088 bool closePort(int port, int proto=PROT_UDP); 00089 00090 /* closes the consequtive port pair and according sockets 00091 * @returns true on success or false else */ 00092 bool closePortPair(int port, int proto=PROT_UDP); 00093 00094 protected: 00095 void initialize(); 00096 00097 int UDPsocketOf[PORT_RANGE]; 00098 int TCPsocketOf[PORT_RANGE]; 00099 }; 00100 00101 #endif