#include <pstun.h>
Inheritance diagram for PSTUNClient:
Public Types | |
enum | { DefaultPort = 3478 } |
enum | NatTypes { UnknownNat, OpenNat, ConeNat, RestrictedNat, PortRestrictedNat, SymmetricNat, SymmetricFirewall, BlockedNat, PartialBlockedNat, NumNatTypes } |
enum | RTPSupportTypes { RTPOK, RTPUnknown, RTPUnsupported, RTPIfSendMedia } |
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 PStringList | GetName () const |
PString | GetServer () const |
void | GetServer (PIPSocket::Address &address, WORD &port) const |
BOOL | SetServer (const PString &server) |
BOOL | SetServer (const PIPSocket::Address &serverAddress, WORD serverPort=0) |
NatTypes | GetNatType (BOOL force=FALSE) |
PString | GetNatTypeName (BOOL force=FALSE) |
RTPSupportTypes | IsSupportingRTP (BOOL force=FALSE) |
virtual BOOL | GetExternalAddress (PIPSocket::Address &externalAddress, const PTimeInterval &maxAge=1000) |
BOOL | CreateSocket (PUDPSocket *&socket, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny(), WORD localPort=0) |
virtual BOOL | CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny()) |
const PTimeInterval | GetTimeout () const |
void | SetTimeout (const PTimeInterval &timeout) |
PINDEX | GetRetries () const |
void | SetRetries (PINDEX retries) |
PINDEX | GetSocketsForPairing () const |
void | SetSocketsForPairing (PINDEX numSockets) |
virtual BOOL | IsAvailable () |
Static Public Member Functions | |
static PStringList | GetNatMethodName () |
static PString | GetNatTypeString (NatTypes type) |
Protected Member Functions | |
bool | OpenSocket (PUDPSocket &socket, PortInfo &portInfo, const PIPSocket::Address &binding) const |
Protected Attributes | |
PIPSocket::Address | serverAddress |
WORD | serverPort |
PTimeInterval | replyTimeout |
PINDEX | pollRetries |
PINDEX | numSocketsForPairing |
NatTypes | natType |
PIPSocket::Address | cachedExternalAddress |
PTime | timeAddressObtained |
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 | |||
) |
void PSTUNClient::Initialise | ( | const PString & | server, | |
WORD | portBase = 0 , |
|||
WORD | portMax = 0 , |
|||
WORD | portPairBase = 0 , |
|||
WORD | portPairMax = 0 | |||
) |
static PStringList PSTUNClient::GetNatMethodName | ( | ) | [inline, static] |
Get the NAT Method Name
Reimplemented from PNatMethod.
virtual PStringList PSTUNClient::GetName | ( | ) | const [inline, virtual] |
Reimplemented from PNatMethod.
PString PSTUNClient::GetServer | ( | ) | const |
Get the current STUN server address and port being used.
void PSTUNClient::GetServer | ( | PIPSocket::Address & | address, | |
WORD & | port | |||
) | const |
BOOL PSTUNClient::SetServer | ( | const PString & | server | ) |
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.
BOOL 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.
NatTypes PSTUNClient::GetNatType | ( | BOOL | force = FALSE |
) |
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 |
PString PSTUNClient::GetNatTypeName | ( | BOOL | force = FALSE |
) | [inline] |
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 |
Get NatTypes enumeration as an English string for the type.
type | NAT Type to get name of |
RTPSupportTypes PSTUNClient::IsSupportingRTP | ( | BOOL | force = FALSE |
) |
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 |
virtual BOOL PSTUNClient::GetExternalAddress | ( | PIPSocket::Address & | externalAddress, | |
const PTimeInterval & | maxAge = 1000 | |||
) | [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.
BOOL PSTUNClient::CreateSocket | ( | PUDPSocket *& | socket, | |
const PIPSocket::Address & | binding = PIPSocket::GetDefaultIpAny() , |
|||
WORD | localPort = 0 | |||
) |
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.
virtual BOOL PSTUNClient::CreateSocketPair | ( | PUDPSocket *& | socket1, | |
PUDPSocket *& | socket2, | |||
const PIPSocket::Address & | binding = PIPSocket::GetDefaultIpAny() | |||
) | [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.
const PTimeInterval PSTUNClient::GetTimeout | ( | ) | const [inline] |
Get the timeout for responses from STUN server.
void PSTUNClient::SetTimeout | ( | const PTimeInterval & | timeout | ) | [inline] |
Set the timeout for responses from STUN server.
timeout | New timeout in milliseconds |
PINDEX PSTUNClient::GetRetries | ( | ) | const [inline] |
Get the number of retries for responses from STUN server.
void PSTUNClient::SetRetries | ( | PINDEX | retries | ) | [inline] |
Set the number of retries for responses from STUN server.
retries | Number of retries |
PINDEX PSTUNClient::GetSocketsForPairing | ( | ) | const [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.
void PSTUNClient::SetSocketsForPairing | ( | PINDEX | numSockets | ) | [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 |
virtual BOOL PSTUNClient::IsAvailable | ( | ) | [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.
Reimplemented from PNatMethod.
bool PSTUNClient::OpenSocket | ( | PUDPSocket & | socket, | |
PortInfo & | portInfo, | |||
const PIPSocket::Address & | binding | |||
) | const [protected] |
PIPSocket::Address PSTUNClient::serverAddress [protected] |
WORD PSTUNClient::serverPort [protected] |
PTimeInterval PSTUNClient::replyTimeout [protected] |
PINDEX PSTUNClient::pollRetries [protected] |
PINDEX PSTUNClient::numSocketsForPairing [protected] |
NatTypes PSTUNClient::natType [protected] |
PIPSocket::Address PSTUNClient::cachedExternalAddress [protected] |
PTime PSTUNClient::timeAddressObtained [protected] |