PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSTUNClient Class Reference

STUN client. More...

#include <pstun.h>

Inheritance diagram for PSTUNClient:
Collaboration diagram for PSTUNClient:

Public Types

enum  { DefaultPriority = 40 }
 
- Public Types inherited from PSTUN
enum  { DefaultPort = 3478 }
 
enum  { MinChannelNumber = 0x4000, MaxChannelNumber = 0x7ffe }
 
enum  IceRole { NoIceRole, IceLite, IceControlled, IceControlling }
 

Public Member Functions

 PSTUNClient (unsigned priority=DefaultPriority)
 
 ~PSTUNClient ()
 
virtual PCaselessString GetMethodName () const
 
virtual void SetCredentials (const PString &username, const PString &password, const PString &realm)
 Set the authentication credentials. More...
 
bool SetServer (const PString &server)
 Set the STUN server to use. More...
 
virtual PString GetServer () const
 Get the current server address name. More...
 
virtual bool GetInterfaceAddress (PIPSocket::Address &internalAddress) const
 
virtual bool Open (const PIPSocket::Address &ifaceAddr)
 
virtual bool IsAvailable (const PIPSocket::Address &binding, PObject *userData)
 
virtual void Close ()
 
virtual bool CreateSocket (PUDPSocket *&socket, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny(), WORD localPort=0, PObject *context=NULL, Component component=eComponent_Unknown)
 Create a single socket. More...
 
virtual bool CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny(), PObject *context=NULL)
 Create a socket pair. More...
 
- Public Member Functions inherited from PSTUN
 PSTUN ()
 
virtual ~PSTUN ()
 
void DoRFC3489Discovery (PNatMethod::NatTypes &natType, PSTUNUDPSocket *socket, const PIPSocketAddressAndPort &serverAddress, PIPSocketAddressAndPort &baseAddressAndPort, PIPSocket::Address &externalAddress, bool externalAddressOnly)
 Determine the NAT type using RFC3489 discovery method. More...
 
void FinishRFC3489Discovery (PNatMethod::NatTypes &natType, PSTUNMessage &responseI, PSTUNUDPSocket *socket, PIPSocket::Address &externalAddress, bool externalAddressOnly)
 
virtual bool GetFromBindingResponse (const PSTUNMessage &response, PIPSocketAddressAndPort &externalAddress)
 
virtual const PTimeInterval GetTimeout () const
 Get the timeout for responses from STUN server. More...
 
virtual void SetTimeout (const PTimeInterval &timeout)
 Set the timeout for responses from STUN server. More...
 
virtual PINDEX GetRetries () const
 Get the number of retries for responses from STUN server. More...
 
virtual void SetRetries (PINDEX retries)
 Set the number of retries for responses from STUN server. More...
 
virtual void SetIceRole (IceRole role)
 

Static Public Member Functions

static const char * MethodName ()
 Get the NAT Method Name. More...
 

Protected Member Functions

virtual bool InternalGetServerAddress (PIPSocketAddressAndPort &externalAddressAndPort) const
 
virtual PNATUDPSocket * InternalCreateSocket (Component component, PObject *context)
 
virtual void InternalUpdate (bool externalAddressOnly)
 
bool InternalSetServer (const PString &server, const PIPSocketAddressAndPort &addr PTRACE_PARAM(, const char *source))
 

Protected Attributes

PSTUNUDPSocketm_socket
 
- Protected Attributes inherited from PSTUN
PINDEX m_pollRetries
 
PSASLString m_userName
 
PSASLString m_realm
 
PSASLString m_nonce
 
PBYTEArray m_password
 
PIPSocket::Address m_interface
 
PIPSocketAddressAndPort m_serverAddress
 
PTimeInterval m_replyTimeout
 
IceRole m_iceRole
 
uint64_t m_iceTieBreak
 

Detailed Description

STUN client.

Member Enumeration Documentation

anonymous enum
Enumerator
DefaultPriority 

Constructor & Destructor Documentation

PSTUNClient::PSTUNClient ( unsigned  priority = DefaultPriority)
PSTUNClient::~PSTUNClient ( )

Member Function Documentation

virtual void PSTUNClient::Close ( )
virtual
virtual bool PSTUNClient::CreateSocket ( PUDPSocket *&  socket,
const PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),
WORD  localPort = 0,
PObject context = NULL,
Component  component = eComponent_Unknown 
)
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.

virtual bool PSTUNClient::CreateSocketPair ( PUDPSocket *&  socket1,
PUDPSocket *&  socket2,
const PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),
PObject context = NULL 
)
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.

virtual bool PSTUNClient::GetInterfaceAddress ( PIPSocket::Address internalAddress) const
virtual
virtual PCaselessString PSTUNClient::GetMethodName ( ) const
virtual
virtual PString PSTUNClient::GetServer ( ) const
virtual

Get the current server address name.

Defaults to be "address:port" string form.

virtual PNATUDPSocket* PSTUNClient::InternalCreateSocket ( Component  component,
PObject context 
)
protectedvirtual
virtual bool PSTUNClient::InternalGetServerAddress ( PIPSocketAddressAndPort externalAddressAndPort) const
protectedvirtual
bool PSTUNClient::InternalSetServer ( const PString server,
const PIPSocketAddressAndPort &addr   PTRACE_PARAM, const char *source 
)
protected
virtual void PSTUNClient::InternalUpdate ( bool  externalAddressOnly)
protectedvirtual
virtual bool PSTUNClient::IsAvailable ( const PIPSocket::Address binding,
PObject userData 
)
virtual
static const char* PSTUNClient::MethodName ( )
static

Get the NAT Method Name.

virtual bool PSTUNClient::Open ( const PIPSocket::Address ifaceAddr)
virtual
virtual void PSTUNClient::SetCredentials ( const PString username,
const PString password,
const PString realm 
)
virtual

Set the authentication credentials.

Override of PNatMethod virtual.

Reimplemented from PSTUN.

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.

Member Data Documentation

PSTUNUDPSocket* PSTUNClient::m_socket
protected

The documentation for this class was generated from the following file: