Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pstun.h

Go to the documentation of this file.
00001 /* 00002 * pstun.h 00003 * 00004 * STUN client 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 2003 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: pstun.h,v $ 00027 * Revision 1.8 2004/03/14 05:47:52 rjongbloed 00028 * Fixed incorrect detection of symmetric NAT (eg Linux masquerading) and also 00029 * some NAT systems which are partially blocked due to firewall rules. 00030 * 00031 * Revision 1.7 2004/02/24 11:15:48 rjongbloed 00032 * Added function to get external router address, also did a bunch of documentation. 00033 * 00034 * Revision 1.6 2004/01/17 17:54:02 rjongbloed 00035 * Added function to get server name from STUN client. 00036 * 00037 * Revision 1.5 2003/10/05 00:56:25 rjongbloed 00038 * Rewrite of STUN to not to use imported code with undesirable license. 00039 * 00040 * Revision 1.4 2003/02/05 06:26:49 robertj 00041 * More work in making the STUN usable for Symmetric NAT systems. 00042 * 00043 * Revision 1.3 2003/02/04 07:01:02 robertj 00044 * Added ip/port version of constructor. 00045 * 00046 * Revision 1.2 2003/02/04 05:05:55 craigs 00047 * Added new functions 00048 * 00049 * Revision 1.1 2003/02/04 03:31:04 robertj 00050 * Added STUN 00051 * 00052 */ 00053 00054 #ifndef _PSTUN_H 00055 #define _PSTUN_H 00056 00057 #ifdef P_USE_PRAGMA 00058 #pragma interface 00059 #endif 00060 00061 #include <ptlib.h> 00062 #include <ptlib/sockets.h> 00063 00064 00067 class PSTUNUDPSocket : public PUDPSocket 00068 { 00069 PCLASSINFO(PSTUNUDPSocket, PUDPSocket); 00070 public: 00071 PSTUNUDPSocket(); 00072 00073 virtual BOOL GetLocalAddress( 00074 Address & addr 00075 ); 00076 virtual BOOL GetLocalAddress( 00077 Address & addr, 00078 WORD & port 00079 ); 00080 00081 protected: 00082 PIPSocket::Address externalIP; 00083 00084 friend class PSTUNClient; 00085 }; 00086 00087 00090 class PSTUNClient : public PObject 00091 { 00092 PCLASSINFO(PSTUNClient, PObject); 00093 public: 00094 enum { 00095 DefaultPort = 3478 00096 }; 00097 00098 PSTUNClient( 00099 const PString & server, 00100 WORD portBase = 0, 00101 WORD portMax = 0, 00102 WORD portPairBase = 0, 00103 WORD portPairMax = 0 00104 ); 00105 PSTUNClient( 00106 const PIPSocket::Address & serverAddress, 00107 WORD serverPort = DefaultPort, 00108 WORD portBase = 0, 00109 WORD portMax = 0, 00110 WORD portPairBase = 0, 00111 WORD portPairMax = 0 00112 ); 00113 00114 00117 PString GetServer() const; 00118 00125 BOOL SetServer( 00126 const PString & server 00127 ); 00128 00132 BOOL SetServer( 00133 const PIPSocket::Address & serverAddress, 00134 WORD serverPort = 0 00135 ); 00136 00147 void SetPortRanges( 00148 WORD portBase, 00149 WORD portMax = 0, 00150 WORD portPairBase = 0, 00151 WORD portPairMax = 0 00152 ); 00153 00154 00155 enum NatTypes { 00156 UnknownNat, 00157 OpenNat, 00158 ConeNat, 00159 RestrictedNat, 00160 PortRestrictedNat, 00161 SymmetricNat, 00162 SymmetricFirewall, 00163 BlockedNat, 00164 PartialBlockedNat, 00165 NumNatTypes 00166 }; 00167 00172 NatTypes GetNatType( 00173 BOOL force = FALSE 00174 ); 00175 00179 PString GetNatTypeName( 00180 BOOL force = FALSE 00181 ); 00182 00190 BOOL GetExternalAddress( 00191 PIPSocket::Address & externalAddress, // External address of router 00192 const PTimeInterval & maxAge = 1000 // Maximum age for caching 00193 ); 00194 00207 BOOL CreateSocket( 00208 PUDPSocket * & socket 00209 ); 00210 00224 BOOL CreateSocketPair( 00225 PUDPSocket * & socket1, 00226 PUDPSocket * & socket2 00227 ); 00228 00229 protected: 00230 void Construct(); 00231 00232 PIPSocket::Address serverAddress; 00233 WORD serverPort; 00234 00235 struct PortInfo { 00236 PMutex mutex; 00237 WORD basePort; 00238 WORD maxPort; 00239 WORD currentPort; 00240 } singlePortInfo, pairedPortInfo; 00241 bool OpenSocket(PUDPSocket & socket, PortInfo & portInfo) const; 00242 00243 int numSocketsForPairing; 00244 00245 NatTypes natType; 00246 PIPSocket::Address cachedExternalAddress; 00247 PTime timeAddressObtained; 00248 }; 00249 00250 00251 00252 #endif // _PSTUN_H 00253 00254 00255 // End of file ////////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7