PNatMethod Class Referenceabstract

PNatMethod Base Network Address Traversal Method class All NAT Traversal Methods are derived off this class. More...

`#include <pnat.h>`

Inheritance diagram for PNatMethod:

## Classes

struct | PortInfo

## Public Member Functions

Construction
| PNatMethod ()
| Default Contructor. More...
| ~PNatMethod ()
| Deconstructor. More...
Overrides from PObject
virtual void | PrintOn (ostream &strm) const
| Output the contents of the object to the stream. More...
Public Member Functions inherited from PObject
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 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 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 void | ReadFrom (istream &strm)
| Input the contents of the object from the stream. More...

## Protected Member Functions

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...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## Protected Attributes

struct PNatMethod::PortInfo | singlePortInfo
struct PNatMethod::PortInfo | pairedPortInfo

## General Functions

enum | RTPSupportTypes { RTPSupported, RTPIfSendMedia, RTPUnsupported, RTPUnknown, NumRTPSupportTypes }
virtual PString | GetName () const =0
| Get the NAT traversal method Name. More...
virtual PString | GetServer () const
| Get the current server address name. More...
virtual bool | GetServerAddress (PIPSocket::Address &address, WORD &port) const =0
| Get the current server address and port being used. More...
virtual PBoolean | GetExternalAddress (PIPSocket::Address &externalAddress, const PTimeInterval &maxAge=1000)=0
| Get the acquired External IP Address. More...
virtual bool | GetInterfaceAddress (PIPSocket::Address &internalAddress) const =0
| Return the interface NAT router is using. More...
virtual PBoolean | CreateSocket (PUDPSocket *&socket, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny(), WORD localPort=0)=0
| Create a single socket. More...
virtual PBoolean | CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny())=0
| Create a socket pair. More...
virtual PBoolean | CreateSocketPair (PUDPSocket *&socket1, PUDPSocket *&socket2, const PIPSocket::Address &binding, void *userData)
| Create a socket pair. More...
virtual bool | IsAvailable (const PIPSocket::Address &binding=PIPSocket::GetDefaultIpAny())=0
| Returns whether the Nat Method is ready and available in assisting in NAT Traversal. 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 RTPSupportTypes | GetRTPSupport (PBoolean force=false)=0
| Return an indication if the current STUN type supports RTP Use the force variable to guarantee an up to date test. 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...
static PNatMethod * | Create (const PString &name, PPluginManager *pluginMgr=NULL)
| Factory Create. More...

## Additional Inherited Members

Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...
Static Public Member Functions inherited from PObject
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
| Internal function caled from CompareObjectMemoryDirect() More...
static const char * | Class ()
| Get the name of the class as a C string. More...

## Detailed Description

PNatMethod Base Network Address Traversal Method class All NAT Traversal Methods are derived off this class.

There are quite a few methods of NAT Traversal. The only purpose of this class is to provide a common interface. It is intentionally minimalistic.

## Member Enumeration Documentation

## RTPSupportTypes

enum PNatMethod::RTPSupportTypes

Enumerator
RTPSupported |
RTPIfSendMedia |
RTPUnsupported |
RTPUnknown |
NumRTPSupportTypes |

## Constructor & Destructor Documentation

## PNatMethod()

PNatMethod::PNatMethod | ( |  | ) |

Default Contructor.

## ~PNatMethod()

PNatMethod::~PNatMethod | ( |  | ) |

Deconstructor.

## Member Function Documentation

## Activate()

virtual void PNatMethod::Activate | ( | bool | active | ) |

virtual

Acrivate Activate/DeActivate the NAT Method on a call by call basis Default does notthing.

## Create()

static PNatMethod* PNatMethod::Create | ( | const PString & | name,
|  | PPluginManager * | pluginMgr = `NULL`
| ) |  |

static

Factory Create.

Parameters

  name | Feature Name Expression
  pluginMgr | Plugin Manager

## CreateSocket()

virtual PBoolean PNatMethod::CreateSocket | ( | PUDPSocket *& | socket,
|  | const PIPSocket::Address & | binding = `PIPSocket::GetDefaultIpAny()`,
|  | WORD | localPort = `0`
| ) |  |

pure virtual

Create a single socket.

The NAT traversal 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.

Implemented in PSTUNClient.

## CreateSocketPair() [1/2]

virtual PBoolean PNatMethod::CreateSocketPair | ( | PUDPSocket *& | socket1,
|  | PUDPSocket *& | socket2,
|  | const PIPSocket::Address & | binding = `PIPSocket::GetDefaultIpAny()`
| ) |  |

pure virtual

Create a socket pair.

The NAT traversal 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.

Implemented in PSTUNClient.

## CreateSocketPair() [2/2]

virtual PBoolean PNatMethod::CreateSocketPair | ( | PUDPSocket *& | socket1,
|  | PUDPSocket *& | socket2,
|  | const PIPSocket::Address & | binding,
|  | void * | userData
| ) |  |

virtual

Create a socket pair.

The NAT traversal 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.

## GetExternalAddress()

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

pure virtual

Get the acquired External IP Address.

Parameters

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

Implemented in PSTUNClient.

## GetInterfaceAddress()

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

pure virtual

Return the interface NAT router is using.

Parameters

  internalAddress | NAT router internal address returned.

Implemented in PSTUNClient.

## GetName()

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

pure virtual

Get the NAT traversal method Name.

Implemented in PSTUNClient.

## GetRTPSupport()

virtual RTPSupportTypes PNatMethod::GetRTPSupport | ( | PBoolean | force = `false` | ) |

pure virtual

Return an indication if the current STUN type supports RTP Use the force variable to guarantee an up to date test.

Parameters

  force | Force a new check

Implemented in PSTUNClient.

## GetServer()

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

virtual

Get the current server address name.

Defaults to be "address:port" string form.

## GetServerAddress()

virtual bool PNatMethod::GetServerAddress | ( | PIPSocket::Address & | address,
|  | WORD & | port
| ) |  | const

pure virtual

Get the current server address and port being used.

Parameters

  address | Address of server
  port | Port server is using.

Implemented in PSTUNClient.

## IsAvailable()

virtual bool PNatMethod::IsAvailable | ( | const PIPSocket::Address & | binding = `PIPSocket::GetDefaultIpAny()` | ) |

pure virtual

Returns whether the Nat Method is ready and available in assisting in NAT Traversal.

The principal is 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 Order of adding to the PNstStrategy determines which method is used

Parameters

  binding | Interface to see if NAT is available on

Implemented in PSTUNClient.

## PrintOn()

virtual void PNatMethod::PrintOn | ( | ostream & | strm | ) | const

virtual

Output the contents of the object to the stream.

The exact output is dependent on the exact semantics of the descendent class. This is primarily used by the standard `operator<<` function.

The default behaviour is to print the class name.

Reimplemented from PObject.

## RandomPortPair()

WORD PNatMethod::RandomPortPair | ( | unsigned int | start,
|  | unsigned int | end
| ) |  |

protected

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.

## SetAlternateAddresses()

virtual void PNatMethod::SetAlternateAddresses | ( | const PStringArray & | addresses,
|  | void * | userData = `NULL`
| ) |  |

virtual

Set Alternate Candidate (ICE) or probe (H.460.24A) addresses.

Default does nothing.

Parameters

  addresses | List of probe/candidates
  userData | User data to link to NAT handler.

## SetPortRanges()

virtual void PNatMethod::SetPortRanges | ( | WORD | portBase,
|  | WORD | portMax = `0`,
|  | WORD | portPairBase = `0`,
|  | WORD | portPairMax = `0`
| ) |  |

virtual

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

  portBase | Single socket port number base
  portMax | Single socket port number max
  portPairBase | Socket pair port number base
  portPairMax | Socket pair port number max

## Member Data Documentation

## pairedPortInfo

struct PNatMethod::PortInfo PNatMethod::pairedPortInfo

protected

## singlePortInfo

struct PNatMethod::PortInfo PNatMethod::singlePortInfo

protected

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

- pnat.h