PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PSTUNClient Class Reference

STUN client. More...

`#include <pstun.h>`

Inheritance diagram for PSTUNClient:
[legend]
Collaboration diagram for PSTUNClient:
[legend]

## Public Member Functions
| PSTUNClient ()
| ~PSTUNClient ()
virtual PString | GetName () const
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 | GetServerAddress (PIPSocketAddressAndPort &serverAddressAndPort) const
virtual bool | GetExternalAddress (PIPSocket::Address &externalAddress, const PTimeInterval &maxAge=1000)
virtual bool | GetInterfaceAddress (PIPSocket::Address &internalAddress) const
virtual bool | Open (const PIPSocket::Address &ifaceAddr)
bool | IsAvailable (const PIPSocket::Address &binding)
virtual void | Close ()
NatTypes | FindNatType (const PIPSocket::Address &binding)
bool | CreateSocket (Component component, PUDPSocket *&socket, const PIPSocket::Address &=PIPSocket::GetDefaultIpAny(), WORD port=0)
| Create a single socket. More...
virtual bool | CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &=PIPSocket::GetDefaultIpAny())
| Create a socket pair. More...
bool | InternalOpenSocket (Component component, const PIPSocket::Address &binding, PSTUNUDPSocket &socket, PortInfo &portInfo)
Public Member Functions inherited from PSTUN
| PSTUN ()
virtual | ~PSTUN ()
virtual PNatMethod::NatTypes | DoRFC3489Discovery (PSTUNUDPSocket *socket, const PIPSocketAddressAndPort &serverAddress, PIPSocketAddressAndPort &baseAddressAndPort, PIPSocketAddressAndPort &externalAddressAndPort)
| Determine the NAT type using RFC3489 discovery method. More...
virtual PNatMethod::NatTypes | FinishRFC3489Discovery (PSTUNMessage &responseI, PSTUNUDPSocket *socket, PIPSocketAddressAndPort &externalAddressAndPort)
virtual int | MakeAuthenticatedRequest (PSTUNUDPSocket *socket, PSTUNMessage &request, PSTUNMessage &response)
virtual bool | GetFromBindingResponse (const PSTUNMessage &response, PIPSocketAddressAndPort &externalAddress)
virtual void | AppendMessageIntegrity (PSTUNMessage &message)
virtual void | SetCredentials (const PString &username, const PString &password, const PString &realm)
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...

## Static Public Member Functions
static PString | GetNatMethodName ()
| Get the NAT Method Name. More...

## Protected Member Functions
virtual NatTypes | InternalGetNatType (bool forced, const PTimeInterval &maxAge)

## Protected Attributes
PSTUNUDPSocket * | m_socket
PMutex | m_mutex

## Additional Inherited Members
Public Types inherited from PSTUN
enum | { DefaultPort = 3478 }
enum | { MinChannelNumber = 0x4000, MaxChannelNumber = 0x7ffe }
Public Attributes inherited from PSTUN
PNatMethod::NatTypes | m_natType
PINDEX | m_pollRetries
PTime | m_timeAddressObtained
PString | m_userName
PString | m_realm
PString | m_nonce
PBYTEArray | m_credentialsHash
PIPSocket::Address | m_interface
PIPSocketAddressAndPort | m_serverAddress
PTimeInterval | replyTimeout

## Detailed Description

STUN client.

## Constructor & Destructor Documentation

PSTUNClient::PSTUNClient | ( |  | ) |

PSTUNClient::~PSTUNClient | ( |  | ) |

## Member Function Documentation

virtual void PSTUNClient::Close | ( |  | ) |
| virtual

bool PSTUNClient::CreateSocket | ( | Component | component,
|  | PUDPSocket *& | socket,
|  | const PIPSocket::Address & | = `PIPSocket::GetDefaultIpAny()`,
|  | WORD | port = `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 & | = `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.

Reimplemented in PTURNClient.

NatTypes PSTUNClient::FindNatType | ( | const PIPSocket::Address & | binding | ) |

virtual bool PSTUNClient::GetExternalAddress | ( | PIPSocket::Address & | externalAddress,
|  | const PTimeInterval & | maxAge = `1000`
| ) |  |
| virtual

Parameters

  externalAddress | External address of router
  maxAge | Maximum age for caching

virtual bool PSTUNClient::GetInterfaceAddress | ( | PIPSocket::Address & | internalAddress | ) | const
| virtual

virtual PString PSTUNClient::GetName | ( |  | ) | const
| virtual

Reimplemented in PTURNClient.

static PString PSTUNClient::GetNatMethodName | ( |  | ) |
| static

Get the NAT Method Name.

virtual PString PSTUNClient::GetServer | ( |  | ) | const
| virtual

Get the current server address name.

Defaults to be "address:port" string form.

virtual bool PSTUNClient::GetServerAddress | ( | PIPSocketAddressAndPort & | serverAddressAndPort | ) | const
| virtual

virtual NatTypes PSTUNClient::InternalGetNatType | ( | bool | forced,
|  | const PTimeInterval & | maxAge
| ) |  |
| protected virtual

bool PSTUNClient::InternalOpenSocket | ( | Component | component,
|  | const PIPSocket::Address & | binding,
|  | PSTUNUDPSocket & | socket,
|  | PortInfo & | portInfo
| ) |  |

bool PSTUNClient::IsAvailable | ( | const PIPSocket::Address & | binding | ) |

virtual bool PSTUNClient::Open | ( | const PIPSocket::Address & | ifaceAddr | ) |
| virtual

Reimplemented in PTURNClient.

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

PMutex PSTUNClient::m_mutex
| protected

PSTUNUDPSocket* PSTUNClient::m_socket
| protected

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

- pstun.h