Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cUPnPNAT Class Reference

#include <cUPnPNAT.h>

Public Member Functions

 cUPnPNAT (void)
 
 ~cUPnPNAT (void)
 
HRESULT AddNATPort (cUPnPNATPort &mapping, bool bTryRandom=false)
 
HRESULT RemoveNATPort (const cUPnPNATPort &mapping, bool bRemoveFromList=true)
 
void RemoveMappings ()
 
cString get_LastErrorStr () const
 
const cNetAddressget_LocalAddr ()
 
cStringA get_LocalAddrStr ()
 
cWinString get_LocalAddrBSTR ()
 
 UNITTEST_FRIEND (cUPnPNAT)
 

Detailed Description

UPNP to allow incoming ports NAT If we have multiple local addresses on multiple NICs we could have multiple uPnp interfaces ? ASSUME cComInit CoInitialize was called for this thread.

Constructor & Destructor Documentation

◆ cUPnPNAT()

GrayLib::cUPnPNAT::cUPnPNAT ( void  )

ASSUME cComInit CoInitialize was called for this thread.

◆ ~cUPnPNAT()

GrayLib::cUPnPNAT::~cUPnPNAT ( void  )

Member Function Documentation

◆ AddNATPort()

HRESULT GrayLib::cUPnPNAT::AddNATPort ( cUPnPNATPort mapping,
bool  bTryRandom = false 
)

Adds a NAT Port Mapping ASSUME cComInit CoInitialize was called for this thread.

  • mapping = Port Mapping Data
  • bTryRandom = If mapping.m_nExternalPort is in use, tries to find a free random external port.
Returns
S_OK = Successful. WSAEADDRINUSE= Error, you are trying to add a port mapping with an external port in use. ERROR_INCORRECT_ADDRESS = Error, you aren't in a LAN -> no router or firewall

◆ get_LastErrorStr()

cString GrayLib::cUPnPNAT::get_LastErrorStr ( ) const
inline

◆ get_LocalAddr()

const cNetAddress & GrayLib::cUPnPNAT::get_LocalAddr ( )
Returns
the Local IP

◆ get_LocalAddrBSTR()

cWinString GrayLib::cUPnPNAT::get_LocalAddrBSTR ( )

Returns a cWinString with the local IP in format 123.123.123.123

◆ get_LocalAddrStr()

cStringA GrayLib::cUPnPNAT::get_LocalAddrStr ( )

Returns a cString with the local IP in format 123.123.123.123

◆ RemoveMappings()

void GrayLib::cUPnPNAT::RemoveMappings ( )

◆ RemoveNATPort()

HRESULT GrayLib::cUPnPNAT::RemoveNATPort ( const cUPnPNATPort mapping,
bool  bRemoveFromList = true 
)

Removes a NAT Port Mapping

  • mapping = Port Mapping Data Should be the same struct passed to AddNATPort
  • bRemoveFromList = Remove the port mapping from the internal list Should by always true (default value if not passed). If you set it to false can cause an unexpected error.
Returns
S_OK=Successful. ERROR_UNKNOWN_PORT=Error, you are trying to remove a port mapping not owned by this class ERROR_INCORRECT_ADDRESS=Error, you aren't in a LAN -> no router or firewall

◆ UNITTEST_FRIEND()

GrayLib::cUPnPNAT::UNITTEST_FRIEND ( cUPnPNAT  )

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