📄 pstun_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>pstun.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center><hr><h1>pstun.h</h1><a href="pstun_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> * pstun.h</span>00003 <span class="comment"> *</span>00004 <span class="comment"> * STUN client</span>00005 <span class="comment"> *</span>00006 <span class="comment"> * Portable Windows Library</span>00007 <span class="comment"> *</span>00008 <span class="comment"> * Copyright (c) 2003 Equivalence Pty. Ltd.</span>00009 <span class="comment"> *</span>00010 <span class="comment"> * The contents of this file are subject to the Mozilla Public License</span>00011 <span class="comment"> * Version 1.0 (the "License"); you may not use this file except in</span>00012 <span class="comment"> * compliance with the License. You may obtain a copy of the License at</span>00013 <span class="comment"> * http://www.mozilla.org/MPL/</span>00014 <span class="comment"> *</span>00015 <span class="comment"> * Software distributed under the License is distributed on an "AS IS"</span>00016 <span class="comment"> * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See</span>00017 <span class="comment"> * the License for the specific language governing rights and limitations</span>00018 <span class="comment"> * under the License.</span>00019 <span class="comment"> *</span>00020 <span class="comment"> * The Original Code is Portable Windows Library.</span>00021 <span class="comment"> *</span>00022 <span class="comment"> * The Initial Developer of the Original Code is Equivalence Pty. Ltd.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> * Contributor(s): ______________________________________.</span>00025 <span class="comment"> *</span>00026 <span class="comment"> * $Log: pstun.h,v $</span>00027 <span class="comment"> * Revision 1.8 2004/03/14 05:47:52 rjongbloed</span>00028 <span class="comment"> * Fixed incorrect detection of symmetric NAT (eg Linux masquerading) and also</span>00029 <span class="comment"> * some NAT systems which are partially blocked due to firewall rules.</span>00030 <span class="comment"> *</span>00031 <span class="comment"> * Revision 1.7 2004/02/24 11:15:48 rjongbloed</span>00032 <span class="comment"> * Added function to get external router address, also did a bunch of documentation.</span>00033 <span class="comment"> *</span>00034 <span class="comment"> * Revision 1.6 2004/01/17 17:54:02 rjongbloed</span>00035 <span class="comment"> * Added function to get server name from STUN client.</span>00036 <span class="comment"> *</span>00037 <span class="comment"> * Revision 1.5 2003/10/05 00:56:25 rjongbloed</span>00038 <span class="comment"> * Rewrite of STUN to not to use imported code with undesirable license.</span>00039 <span class="comment"> *</span>00040 <span class="comment"> * Revision 1.4 2003/02/05 06:26:49 robertj</span>00041 <span class="comment"> * More work in making the STUN usable for Symmetric NAT systems.</span>00042 <span class="comment"> *</span>00043 <span class="comment"> * Revision 1.3 2003/02/04 07:01:02 robertj</span>00044 <span class="comment"> * Added ip/port version of constructor.</span>00045 <span class="comment"> *</span>00046 <span class="comment"> * Revision 1.2 2003/02/04 05:05:55 craigs</span>00047 <span class="comment"> * Added new functions</span>00048 <span class="comment"> *</span>00049 <span class="comment"> * Revision 1.1 2003/02/04 03:31:04 robertj</span>00050 <span class="comment"> * Added STUN</span>00051 <span class="comment"> *</span>00052 <span class="comment"> */</span>00053 00054 <span class="preprocessor">#ifndef _PSTUN_H</span>00055 <span class="preprocessor"></span><span class="preprocessor">#define _PSTUN_H</span>00056 <span class="preprocessor"></span>00057 <span class="preprocessor">#ifdef P_USE_PRAGMA</span>00058 <span class="preprocessor"></span><span class="preprocessor">#pragma interface</span>00059 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00060 <span class="preprocessor"></span>00061 <span class="preprocessor">#include <ptlib.h></span>00062 <span class="preprocessor">#include <<a class="code" href="sockets_8h.html">ptlib/sockets.h</a>></span>00063 00064 <a name="l00067"></a><a class="code" href="classPSTUNUDPSocket.html">00067</a> <span class="keyword">class </span><a class="code" href="classPSTUNUDPSocket.html">PSTUNUDPSocket</a> : <span class="keyword">public</span> <a class="code" href="classPUDPSocket.html">PUDPSocket</a>00068 {00069 <a class="code" href="object_8h.html#a27">PCLASSINFO</a>(<a class="code" href="classPSTUNUDPSocket.html">PSTUNUDPSocket</a>, <a class="code" href="classPUDPSocket.html">PUDPSocket</a>);00070 <span class="keyword">public</span>:00071 <a class="code" href="classPSTUNUDPSocket.html#a0">PSTUNUDPSocket</a>();00072 00073 <span class="keyword">virtual</span> BOOL <a class="code" href="classPSTUNUDPSocket.html#a1">GetLocalAddress</a>(00074 Address & addr 00075 );00076 <span class="keyword">virtual</span> BOOL <a class="code" href="classPSTUNUDPSocket.html#a1">GetLocalAddress</a>(00077 Address & addr, 00078 WORD & <a class="code" href="classPSocket.html#n0">port</a> 00079 );00080 00081 <span class="keyword">protected</span>:<a name="l00082"></a><a class="code" href="classPSTUNUDPSocket.html#n0">00082</a> <a class="code" href="classPIPSocket_1_1Address.html">PIPSocket::Address</a> <a class="code" href="classPSTUNUDPSocket.html#n0">externalIP</a>;00083 <a name="l00084"></a><a class="code" href="classPSTUNUDPSocket.html#l0">00084</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classPSTUNClient.html">PSTUNClient</a>;00085 };00086 00087 <a name="l00090"></a><a class="code" href="classPSTUNClient.html">00090</a> <span class="keyword">class </span><a class="code" href="classPSTUNClient.html">PSTUNClient</a> : <span class="keyword">public</span> <a class="code" href="classPObject.html">PObject</a>00091 {00092 <a class="code" href="object_8h.html#a27">PCLASSINFO</a>(<a class="code" href="classPSTUNClient.html">PSTUNClient</a>, <a class="code" href="classPObject.html">PObject</a>);00093 <span class="keyword">public</span>:00094 <span class="keyword">enum</span> {00095 <a class="code" href="classPSTUNClient.html#s11s0">DefaultPort</a> = 347800096 };00097 00098 <a class="code" href="classPSTUNClient.html#a0">PSTUNClient</a>(00099 <span class="keyword">const</span> <a class="code" href="classPString.html">PString</a> & server,00100 WORD portBase = 0,00101 WORD portMax = 0,00102 WORD portPairBase = 0,00103 WORD portPairMax = 000104 );00105 <a class="code" href="classPSTUNClient.html#a0">PSTUNClient</a>(00106 <span class="keyword">const</span> <a class="code" href="classPIPSocket_1_1Address.html">PIPSocket::Address</a> & <a class="code" href="classPSTUNClient.html#n0">serverAddress</a>,00107 WORD <a class="code" href="classPSTUNClient.html#n1">serverPort</a> = <a class="code" href="classPSTUNClient.html#s11s0">DefaultPort</a>,00108 WORD portBase = 0,00109 WORD portMax = 0,00110 WORD portPairBase = 0,00111 WORD portPairMax = 000112 );00113 00114 00117 <a class="code" href="classPString.html">PString</a> <a class="code" href="classPSTUNClient.html#a2">GetServer</a>() <span class="keyword">const</span>;00118 00125 BOOL <a class="code" href="classPSTUNClient.html#a3">SetServer</a>(00126 <span class="keyword">const</span> <a class="code" href="classPString.html">PString</a> & server00127 );00128 00132 BOOL <a class="code" href="classPSTUNClient.html#a3">SetServer</a>(00133 <span class="keyword">const</span> <a class="code" href="classPIPSocket_1_1Address.html">PIPSocket::Address</a> & serverAddress,00134 WORD <a class="code" href="classPSTUNClient.html#n1">serverPort</a> = 000135 );00136 00147 <span class="keywordtype">void</span> <a class="code" href="classPSTUNClient.html#a5">SetPortRanges</a>(00148 WORD portBase, 00149 WORD portMax = 0, 00150 WORD portPairBase = 0, 00151 WORD portPairMax = 0 00152 );00153 00154 <a name="l00155"></a><a class="code" href="classPSTUNClient.html#s12">00155</a> <span class="keyword">enum</span> <a class="code" href="classPSTUNClient.html#s12">NatTypes</a> {00156 <a class="code" href="classPSTUNClient.html#s12s1">UnknownNat</a>,00157 <a class="code" href="classPSTUNClient.html#s12s2">OpenNat</a>,00158 <a class="code" href="classPSTUNClient.html#s12s3">ConeNat</a>,00159 <a class="code" href="classPSTUNClient.html#s12s4">RestrictedNat</a>,00160 <a class="code" href="classPSTUNClient.html#s12s5">PortRestrictedNat</a>,00161 <a class="code" href="classPSTUNClient.html#s12s6">SymmetricNat</a>,00162 <a class="code" href="classPSTUNClient.html#s12s7">SymmetricFirewall</a>,00163 <a class="code" href="classPSTUNClient.html#s12s8">BlockedNat</a>,00164 <a class="code" href="classPSTUNClient.html#s12s9">PartialBlockedNat</a>,00165 <a class="code" href="classPSTUNClient.html#s12s10">NumNatTypes</a>00166 };00167 00172 <a class="code" href="classPSTUNClient.html#s12">NatTypes</a> <a class="code" href="classPSTUNClient.html#a6">GetNatType</a>(00173 BOOL force = FALSE 00174 );00175 00179 <a class="code" href="classPString.html">PString</a> <a class="code" href="classPSTUNClient.html#a7">GetNatTypeName</a>(00180 BOOL force = FALSE 00181 );00182 00190 BOOL <a class="code" href="classPSTUNClient.html#a8">GetExternalAddress</a>(00191 <a class="code" href="classPIPSocket_1_1Address.html">PIPSocket::Address</a> & externalAddress, <span class="comment">// External address of router</span>00192 <span class="keyword">const</span> <a class="code" href="classPTimeInterval.html">PTimeInterval</a> & maxAge = 1000 <span class="comment">// Maximum age for caching</span>00193 );00194 00207 BOOL <a class="code" href="classPSTUNClient.html#a9">CreateSocket</a>(00208 <a class="code" href="classPUDPSocket.html">PUDPSocket</a> * & socket00209 );00210 00224 BOOL <a class="code" href="classPSTUNClient.html#a10">CreateSocketPair</a>(00225 <a class="code" href="classPUDPSocket.html">PUDPSocket</a> * & socket1,00226 <a class="code" href="classPUDPSocket.html">PUDPSocket</a> * & socket200227 );00228 00229 <span class="keyword">protected</span>:00230 <span class="keywordtype">void</span> <a class="code" href="classPSTUNClient.html#b0">Construct</a>();00231 <a name="l00232"></a><a class="code" href="classPSTUNClient.html#n0">00232</a> <a class="code" href="classPIPSocket_1_1Address.html">PIPSocket::Address</a> serverAddress;<a name="l00233"></a><a class="code" href="classPSTUNClient.html#n1">00233</a> WORD <a class="code" href="classPSTUNClient.html#n1">serverPort</a>;00234 <a name="l00235"></a><a class="code" href="structPSTUNClient_1_1PortInfo.html">00235</a> <span class="keyword">struct </span><a class="code" href="structPSTUNClient_1_1PortInfo.html">PortInfo</a> {<a name="l00236"></a><a class="code" href="structPSTUNClient_1_1PortInfo.html#m0">00236</a> <a class="code" href="classPMutex.html">PMutex</a> <a class="code" href="structPSTUNClient_1_1PortInfo.html#m0">mutex</a>;<a name="l00237"></a><a class="code" href="structPSTUNClient_1_1PortInfo.html#m1">00237</a> WORD <a class="code" href="structPSTUNClient_1_1PortInfo.html#m1">basePort</a>;<a name="l00238"></a><a class="code" href="structPSTUNClient_1_1PortInfo.html#m2">00238</a> WORD <a class="code" href="structPSTUNClient_1_1PortInfo.html#m2">maxPort</a>;<a name="l00239"></a><a class="code" href="structPSTUNClient_1_1PortInfo.html#m3">00239</a> WORD <a class="code" href="structPSTUNClient_1_1PortInfo.html#m3">currentPort</a>;00240 } <a class="code" href="classPSTUNClient.html#n2">singlePortInfo</a>, <a class="code" href="classPSTUNClient.html#n3">pairedPortInfo</a>;00241 <span class="keywordtype">bool</span> <a class="code" href="classPSTUNClient.html#b1">OpenSocket</a>(<a class="code" href="classPUDPSocket.html">PUDPSocket</a> & socket, PortInfo & portInfo) <span class="keyword">const</span>;00242 <a name="l00243"></a><a class="code" href="classPSTUNClient.html#n4">00243</a> <span class="keywordtype">int</span> <a class="code" href="classPSTUNClient.html#n4">numSocketsForPairing</a>;00244 <a name="l00245"></a><a class="code" href="classPSTUNClient.html#n5">00245</a> <a class="code" href="classPSTUNClient.html#s12">NatTypes</a> <a class="code" href="classPSTUNClient.html#n5">natType</a>;<a name="l00246"></a><a class="code" href="classPSTUNClient.html#n6">00246</a> <a class="code" href="classPIPSocket_1_1Address.html">PIPSocket::Address</a> <a class="code" href="classPSTUNClient.html#n6">cachedExternalAddress</a>;<a name="l00247"></a><a class="code" href="classPSTUNClient.html#n7">00247</a> <a class="code" href="classPTime.html">PTime</a> <a class="code" href="classPSTUNClient.html#n7">timeAddressObtained</a>;00248 };00249 00250 00251 00252 <span class="preprocessor">#endif // _PSTUN_H</span>00253 <span class="preprocessor"></span>00254 00255 <span class="comment">// End of file ////////////////////////////////////////////////////////////////</span></pre></div><hr><address style="align: right;"><small>Generated on Wed Sep 29 22:44:11 2004 for PWLib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -