Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

PSTUNClient Class Reference

#include <pstun.h>

Inheritance diagram for PSTUNClient:

PObject List of all members.

Public Types

enum  { DefaultPort = 3478 }
enum  NatTypes {
  UnknownNat, OpenNat, ConeNat, RestrictedNat,
  PortRestrictedNat, SymmetricNat, SymmetricFirewall, BlockedNat,
  PartialBlockedNat, NumNatTypes
}

Public Methods

 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)
PString GetServer () const
BOOL SetServer (const PString &server)
BOOL SetServer (const PIPSocket::Address &serverAddress, WORD serverPort=0)
void SetPortRanges (WORD portBase, WORD portMax=0, WORD portPairBase=0, WORD portPairMax=0)
NatTypes GetNatType (BOOL force=FALSE)
PString GetNatTypeName (BOOL force=FALSE)
BOOL GetExternalAddress (PIPSocket::Address &externalAddress, const PTimeInterval &maxAge=1000)
BOOL CreateSocket (PUDPSocket *&socket)
BOOL CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2)

Protected Methods

void Construct ()
bool OpenSocket (PUDPSocket &socket, PortInfo &portInfo) const

Protected Attributes

PIPSocket::Address serverAddress
WORD serverPort
PSTUNClient::PortInfo singlePortInfo
PSTUNClient::PortInfo pairedPortInfo
int numSocketsForPairing
NatTypes natType
PIPSocket::Address cachedExternalAddress
PTime timeAddressObtained

Detailed Description

STUN client.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
DefaultPort 

enum PSTUNClient::NatTypes
 

Enumeration values:
UnknownNat 
OpenNat 
ConeNat 
RestrictedNat 
PortRestrictedNat 
SymmetricNat 
SymmetricFirewall 
BlockedNat 
PartialBlockedNat 
NumNatTypes 


Constructor & Destructor Documentation

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
 


Member Function Documentation

void PSTUNClient::Construct   [protected]
 

BOOL PSTUNClient::CreateSocket PUDPSocket *&    socket
 

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.

BOOL PSTUNClient::CreateSocketPair PUDPSocket *&    socket1,
PUDPSocket *&    socket2
 

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.

BOOL PSTUNClient::GetExternalAddress PIPSocket::Address   externalAddress,
const PTimeInterval   maxAge = 1000
 

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.

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.

Parameters:
force  Force a new check

PString PSTUNClient::GetNatTypeName BOOL    force = FALSE
 

Determine via the STUN protocol the NAT type for the router. As for GetNatType() but returns an English string for the type.

Parameters:
force  Force a new check

PString PSTUNClient::GetServer  
 

Get the current STUN server address and port being used.

bool PSTUNClient::OpenSocket PUDPSocket   socket,
PortInfo   portInfo
const [protected]
 

void PSTUNClient::SetPortRanges WORD    portBase,
WORD    portMax = 0,
WORD    portPairBase = 0,
WORD    portPairMax = 0
 

Set the port ranges to be used on local machine. Note that the ports used on the NAT router may not be the same unless some form of port forwarding is present.

If the port base is zero then standard operating system port allocation method is used.

If the max port is zero then it will be automatically set to the port base + 99.

Parameters:
portMax  Single socket port number base
portPairBase  Single socket port number max
portPairMax  Socket pair port number base Socket pair port number max

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.

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

PIPSocket::Address PSTUNClient::cachedExternalAddress [protected]
 

NatTypes PSTUNClient::natType [protected]
 

int PSTUNClient::numSocketsForPairing [protected]
 

struct PSTUNClient::PortInfo PSTUNClient::pairedPortInfo [protected]
 

PIPSocket::Address PSTUNClient::serverAddress [protected]
 

WORD PSTUNClient::serverPort [protected]
 

struct PSTUNClient::PortInfo PSTUNClient::singlePortInfo [protected]
 

PTime PSTUNClient::timeAddressObtained [protected]
 


The documentation for this class was generated from the following file:
Generated on Fri Aug 13 15:50:10 2004 for PWLib by doxygen1.2.18