PTLib
Version 2.10.11
|
STUN client. More...
#include <pstun.h>
Public Types | |
enum | { DefaultPort = 3478 } |
enum | NatTypes { UnknownNat, OpenNat, ConeNat, RestrictedNat, PortRestrictedNat, SymmetricNat, SymmetricFirewall, BlockedNat, PartialBlockedNat, NumNatTypes } |
![]() | |
enum | RTPSupportTypes { RTPSupported, RTPIfSendMedia, RTPUnsupported, RTPUnknown, NumRTPSupportTypes } |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
Public Member Functions | |
PSTUNClient () | |
PSTUNClient (const PString &server, WORD portBase=0, WORD portMax=0, WORD portPairBase=0, WORD portPairMax=0) | |
PSTUNClient (const PIPSocket::Address &serverAddress, WORD serverPort=DefaultPort, WORD portBase=0, WORD portMax=0, WORD portPairBase=0, WORD portPairMax=0) | |
void | Initialise (const PString &server, WORD portBase=0, WORD portMax=0, WORD portPairBase=0, WORD portPairMax=0) |
virtual PString | GetName () const |
Get the NAT traversal method name. More... | |
virtual bool | GetServerAddress (PIPSocket::Address &address, WORD &port) const |
Get the current server address and port being used. More... | |
PBoolean | SetServer (const PString &server) |
Set the STUN server to use. More... | |
PBoolean | SetServer (const PIPSocket::Address &serverAddress, WORD serverPort=0) |
Set the STUN server to use by IP address and port. More... | |
NatTypes | GetNatType (PBoolean force=false) |
Determine via the STUN protocol the NAT type for the router. More... | |
PString | GetNatTypeName (PBoolean force=false) |
Determine via the STUN protocol the NAT type for the router. More... | |
RTPSupportTypes | GetRTPSupport (PBoolean force=false) |
Return an indication if the current STUN type supports RTP Use the force variable to guarantee an up to date test. More... | |
virtual PBoolean | GetExternalAddress (PIPSocket::Address &externalAddress, const PTimeInterval &maxAge=1000) |
Determine the external router address. More... | |
virtual bool | GetInterfaceAddress (PIPSocket::Address &internalAddress) const |
Return the interface NAT router is using. More... | |
void | InvalidateCache () |
Invalidates the cached addresses and modes. More... | |
PBoolean | CreateSocket (PUDPSocket *&socket, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny(), WORD localPort=0) |
Create a single socket. More... | |
virtual PBoolean | CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny()) |
Create a socket pair. More... | |
const PTimeInterval | GetTimeout () const |
Get the timeout for responses from STUN server. More... | |
void | SetTimeout (const PTimeInterval &timeout) |
Set the timeout for responses from STUN server. More... | |
PINDEX | GetRetries () const |
Get the number of retries for responses from STUN server. More... | |
void | SetRetries (PINDEX retries) |
Set the number of retries for responses from STUN server. More... | |
PINDEX | GetSocketsForPairing () const |
Get the number of sockets to create in attempt to get a port pair. More... | |
void | SetSocketsForPairing (PINDEX numSockets) |
Set the number of sockets to create in attempt to get a port pair. More... | |
virtual bool | IsAvailable (const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny()) |
Returns whether the Nat Method is ready and available in assisting in NAT Traversal. More... | |
![]() | |
PNatMethod () | |
Default Contructor. More... | |
~PNatMethod () | |
Deconstructor. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual PString | GetServer () const |
Get the current server address name. More... | |
virtual PBoolean | CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &binding, void *userData) |
Create a socket pair. More... | |
virtual void | Activate (bool active) |
Acrivate Activate/DeActivate the NAT Method on a call by call basis Default does notthing. More... | |
virtual void | SetAlternateAddresses (const PStringArray &addresses, void *userData=NULL) |
Set Alternate Candidate (ICE) or probe (H.460.24A) addresses. More... | |
virtual void | SetPortRanges (WORD portBase, WORD portMax=0, WORD portPairBase=0, WORD portPairMax=0) |
Set the port ranges to be used on local machine. More... | |
![]() | |
virtual | ~PObject () |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual const char * | GetClass (unsigned ancestor=0) const |
Get the current dynamic type of the object instance. More... | |
PBoolean | IsClass (const char *cls) const |
virtual PBoolean | InternalIsDescendant (const char *clsName) const |
Determine if the dynamic type of the current instance is a descendent of the specified class. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Compare the two objects and return their relative rank. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Static Public Member Functions | |
static PStringList | GetNatMethodName () |
Get the NAT Method Name. More... | |
static PString | GetNatTypeString (NatTypes type) |
Get NatTypes enumeration as an English string for the type. More... | |
![]() | |
static PNatMethod * | Create (const PString &name, PPluginManager *pluginMgr=NULL) |
Factory Create. More... | |
![]() | |
static const char * | Class () |
Get the name of the class as a C string. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
Protected Member Functions | |
bool | OpenSocket (PUDPSocket &socket, PortInfo &portInfo, const PIPSocket::Address &binding) |
![]() | |
WORD | RandomPortPair (unsigned int start, unsigned int end) |
RandomPortPair This function returns a random port pair base number in the specified range for the creation of the RTP port pairs (this used to avoid issues with multiple NATed devices opening the same local ports and experiencing issues with the behaviour of the NAT device Refer: draft-jennings-behave-test-results-04 sect 3. More... | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Protected Attributes | |
PString | serverHost |
WORD | serverPort |
PTimeInterval | replyTimeout |
PINDEX | pollRetries |
PINDEX | numSocketsForPairing |
NatTypes | natType |
PIPSocket::Address | cachedServerAddress |
PIPSocket::Address | cachedExternalAddress |
PIPSocket::Address | interfaceAddress |
PTime | timeAddressObtained |
![]() | |
struct PNatMethod::PortInfo | singlePortInfo |
struct PNatMethod::PortInfo | pairedPortInfo |
STUN client.
PSTUNClient::PSTUNClient | ( | ) |
PSTUNClient::PSTUNClient | ( | const PString & | server, |
WORD | portBase = 0 , |
||
WORD | portMax = 0 , |
||
WORD | portPairBase = 0 , |
||
WORD | portPairMax = 0 |
||
) |
PSTUNClient::PSTUNClient | ( | const PIPSocket::Address & | serverAddress, |
WORD | serverPort = DefaultPort , |
||
WORD | portBase = 0 , |
||
WORD | portMax = 0 , |
||
WORD | portPairBase = 0 , |
||
WORD | portPairMax = 0 |
||
) |
|
virtual |
Create a single socket.
The STUN protocol is used to create a socket for which the external IP address and port numbers are known. A PUDPSocket descendant is returned which will, in response to GetLocalAddress() return the externally visible IP and port rather than the local machines IP and socket.
The will create a new socket pointer. It is up to the caller to make sure the socket is deleted to avoid memory leaks.
The socket pointer is set to NULL if the function fails and returns false.
Implements PNatMethod.
|
virtual |
Create a socket pair.
The STUN protocol is used to create a pair of sockets with adjacent port numbers for which the external IP address and port numbers are known. PUDPSocket descendants are returned which will, in response to GetLocalAddress() return the externally visible IP and port rather than the local machines IP and socket.
The will create new socket pointers. It is up to the caller to make sure the sockets are deleted to avoid memory leaks.
The socket pointers are set to NULL if the function fails and returns false.
Implements PNatMethod.
|
virtual |
Determine the external router address.
This will send UDP packets out using the STUN protocol to determine the intervening routers external IP address.
A cached address is returned provided it is no older than the time specified.
externalAddress | External address of router |
maxAge | Maximum age for caching |
Implements PNatMethod.
|
virtual |
Return the interface NAT router is using.
Implements PNatMethod.
|
inlinevirtual |
Get the NAT traversal method name.
Implements PNatMethod.
|
inlinestatic |
Get the NAT Method Name.
Determine via the STUN protocol the NAT type for the router.
This will cache the last determine NAT type. Use the force variable to guarantee an up to date value.
force | Force a new check |
Referenced by GetNatTypeName().
Determine via the STUN protocol the NAT type for the router.
As for GetNatType() but returns an English string for the type.
force | Force a new check |
References GetNatType(), and GetNatTypeString().
Get NatTypes enumeration as an English string for the type.
type | NAT Type to get name of |
Referenced by GetNatTypeName(), and operator<<().
|
inline |
Get the number of retries for responses from STUN server.
References pollRetries.
|
virtual |
Return an indication if the current STUN type supports RTP Use the force variable to guarantee an up to date test.
force | Force a new check |
Implements PNatMethod.
|
virtual |
Get the current server address and port being used.
address | Address of server |
port | Port server is using. |
Implements PNatMethod.
|
inline |
Get the number of sockets to create in attempt to get a port pair.
RTP requires a pair of consecutive ports. To get this several sockets must be opened and fired through the NAT firewall to get a pair. The busier the firewall the more sockets will be required.
References numSocketsForPairing.
|
inline |
Get the timeout for responses from STUN server.
References replyTimeout.
void PSTUNClient::Initialise | ( | const PString & | server, |
WORD | portBase = 0 , |
||
WORD | portMax = 0 , |
||
WORD | portPairBase = 0 , |
||
WORD | portPairMax = 0 |
||
) |
void PSTUNClient::InvalidateCache | ( | ) |
Invalidates the cached addresses and modes.
This allows to lazily update the external address cache at the next attempt to get the external address.
|
virtual |
Returns whether the Nat Method is ready and available in assisting in NAT Traversal.
The principal is this function is to allow the EP to detect various methods and if a method is detected then this method is available for NAT traversal. The availablity of the STUN Method is dependant on the Type of NAT being used.
binding | Interface to see if NAT is available on |
Implements PNatMethod.
|
protected |
|
inline |
Set the number of retries for responses from STUN server.
retries | Number of retries |
References pollRetries.
Set the STUN server to use.
The server string may be of the form host:port. If :port is absent then the default port 3478 is used. The substring port can also be a service name as found in /etc/services. The host substring may be a DNS name or explicit IP address.
PBoolean PSTUNClient::SetServer | ( | const PIPSocket::Address & | serverAddress, |
WORD | serverPort = 0 |
||
) |
Set the STUN server to use by IP address and port.
If serverPort is zero then the default port of 3478 is used.
|
inline |
Set the number of sockets to create in attempt to get a port pair.
RTP requires a pair of consecutive ports. To get this several sockets must be opened and fired through the NAT firewall to get a pair. The busier the firewall the more sockets will be required.
numSockets | Number opf sockets to create |
References numSocketsForPairing.
|
inline |
Set the timeout for responses from STUN server.
timeout | New timeout in milliseconds |
References replyTimeout.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by GetSocketsForPairing(), and SetSocketsForPairing().
|
protected |
Referenced by GetRetries(), and SetRetries().
|
protected |
Referenced by GetTimeout(), and SetTimeout().
|
protected |
|
protected |
|
protected |