PTLib
Version 2.10.10
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
pstun.h
Go to the documentation of this file.
1
/*
2
* pstun.h
3
*
4
* STUN client
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 2003 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 24177 $
27
* $Author: rjongbloed $
28
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
29
*/
30
31
#ifndef PTLIB_PSTUN_H
32
#define PTLIB_PSTUN_H
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
38
39
#include <
ptclib/pnat.h
>
40
#include <
ptlib/sockets.h
>
41
42
45
class
PSTUNUDPSocket
:
public
PUDPSocket
46
{
47
PCLASSINFO(
PSTUNUDPSocket
,
PUDPSocket
);
48
public
:
49
PSTUNUDPSocket
();
50
51
virtual
PBoolean
GetLocalAddress
(
52
Address
& addr
53
);
54
virtual
PBoolean
GetLocalAddress
(
55
Address
& addr,
56
WORD &
port
57
);
58
59
protected
:
60
PIPSocket::Address
externalIP
;
61
62
friend
class
PSTUNClient
;
63
};
64
65
68
class
PSTUNClient
:
public
PNatMethod
69
{
70
PCLASSINFO(
PSTUNClient
,
PNatMethod
);
71
public
:
72
enum
{
73
DefaultPort
= 3478
74
};
75
76
PSTUNClient
();
77
78
PSTUNClient
(
79
const
PString
& server,
80
WORD portBase = 0,
81
WORD portMax = 0,
82
WORD portPairBase = 0,
83
WORD portPairMax = 0
84
);
85
PSTUNClient
(
86
const
PIPSocket::Address
& serverAddress,
87
WORD
serverPort
=
DefaultPort
,
88
WORD portBase = 0,
89
WORD portMax = 0,
90
WORD portPairBase = 0,
91
WORD portPairMax = 0
92
);
93
94
95
void
Initialise
(
96
const
PString
& server,
97
WORD portBase = 0,
98
WORD portMax = 0,
99
WORD portPairBase = 0,
100
WORD portPairMax = 0
101
);
102
105
static
PStringList
GetNatMethodName
() {
return
PStringList
(
"STUN"
); }
106
109
virtual
PString
GetName
()
const
{
return
"STUN"
; }
110
113
virtual
bool
GetServerAddress
(
114
PIPSocket::Address
& address,
115
WORD & port
116
)
const
;
117
124
PBoolean
SetServer
(
125
const
PString
& server
126
);
127
131
PBoolean
SetServer
(
132
const
PIPSocket::Address
& serverAddress,
133
WORD
serverPort
= 0
134
);
135
136
enum
NatTypes
{
137
UnknownNat
,
138
OpenNat
,
139
ConeNat
,
140
RestrictedNat
,
141
PortRestrictedNat
,
142
SymmetricNat
,
143
SymmetricFirewall
,
144
BlockedNat
,
145
PartialBlockedNat
,
146
NumNatTypes
147
};
148
153
NatTypes
GetNatType
(
154
PBoolean
force =
false
155
);
156
160
PString
GetNatTypeName
(
161
PBoolean
force =
false
162
) {
return
GetNatTypeString
(
GetNatType
(force)); }
163
166
static
PString
GetNatTypeString
(
167
NatTypes
type
168
);
169
173
RTPSupportTypes
GetRTPSupport
(
174
PBoolean
force =
false
175
);
176
184
virtual
PBoolean
GetExternalAddress
(
185
PIPSocket::Address
& externalAddress,
186
const
PTimeInterval
& maxAge = 1000
187
);
188
191
virtual
bool
GetInterfaceAddress
(
192
PIPSocket::Address
& internalAddress
193
)
const
;
194
199
void
InvalidateCache
();
200
213
PBoolean
CreateSocket
(
214
PUDPSocket
* & socket,
215
const
PIPSocket::Address
& binding =
PIPSocket::GetDefaultIpAny
(),
216
WORD localPort = 0
217
);
218
232
virtual
PBoolean
CreateSocketPair
(
233
PUDPSocket
* & socket1,
234
PUDPSocket
* & socket2,
235
const
PIPSocket::Address
& binding =
PIPSocket::GetDefaultIpAny
()
236
);
237
240
const
PTimeInterval
GetTimeout
()
const
{
return
replyTimeout
; }
241
244
void
SetTimeout
(
245
const
PTimeInterval
& timeout
246
) {
replyTimeout
= timeout; }
247
250
PINDEX
GetRetries
()
const
{
return
pollRetries
; }
251
254
void
SetRetries
(
255
PINDEX retries
256
) {
pollRetries
= retries; }
257
263
PINDEX
GetSocketsForPairing
()
const
{
return
numSocketsForPairing
; }
264
270
void
SetSocketsForPairing
(
271
PINDEX numSockets
272
) {
numSocketsForPairing
= numSockets; }
273
281
virtual
bool
IsAvailable
(
282
const
PIPSocket::Address
& binding =
PIPSocket::GetDefaultIpAny
()
283
);
284
285
protected
:
286
PString
serverHost
;
287
WORD
serverPort
;
288
PTimeInterval
replyTimeout
;
289
PINDEX
pollRetries
;
290
PINDEX
numSocketsForPairing
;
291
292
bool
OpenSocket
(
PUDPSocket
& socket,
PortInfo
& portInfo,
const
PIPSocket::Address
& binding);
293
294
NatTypes
natType
;
295
PIPSocket::Address
cachedServerAddress
;
296
PIPSocket::Address
cachedExternalAddress
;
297
PIPSocket::Address
interfaceAddress
;
298
PTime
timeAddressObtained
;
299
};
300
301
302
inline
ostream &
operator<<
(ostream & strm,
PSTUNClient::NatTypes
type) {
return
strm <<
PSTUNClient::GetNatTypeString
(type); }
303
304
305
#endif // PTLIB_PSTUN_H
306
307
308
// End of file ////////////////////////////////////////////////////////////////
include
ptclib
pstun.h
Generated on Tue May 7 2013 17:25:45 for PTLib by
1.8.3.1