Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cUPnPNAT.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cUPnPNAT_H
7 #define _INC_cUPnPNAT_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cWinString.h"
13 #include "../Net/cNetSocket.h"
14 #include "../Net/cNetAddrName.h"
17 
18 namespace GrayLib
19 {
21 
23  {
26 
27  public:
32  bool m_bEnabled;
33 
34  public:
35  cUPnPNATPort(NET_PORT_t nExternalPort = k_NET_PORT_INVALID, NET_PORT_t nInternalPort = k_NET_PORT_INVALID, IPPROTO_TYPE nProtocolType = IPPROTO_TCP, cString sDescription = "")
36  : m_nExternalPort(nExternalPort)
37  , m_nInternalPort(nInternalPort)
38  , m_nProtocolType(nProtocolType)
39  , m_sDescription(sDescription)
40  , m_bEnabled(true)
41  {
42  }
43  void CheckDefaults();
44  const GChar_t* get_ProtocolName() const noexcept
45  {
46  if (m_nProtocolType == IPPROTO_UDP)
47  return _GT("UDP");
48  return _GT("TCP");
49  }
50  cStringA getDescFull() const;
51  };
52 
53  class GRAYLIB_LINK cUPnPNAT // : public cSingleton<cUPnPNAT>
54  {
59 
60  private:
61  cArrayStruct<cUPnPNATPort> m_Mappings;
62  cString m_sLastError;
63 
64  cStringA m_sLocalAddr;
65  cNetAddress m_LocalAddr;
66 
67  private:
68  bool InitLocalAddr();
69  HRESULT RetError(HRESULT hRes, const char* pszDefaultString);
70 
71  public:
72  cUPnPNAT(void);
73  ~cUPnPNAT(void);
74 
75  HRESULT AddNATPort(cUPnPNATPort& mapping, bool bTryRandom = false);
76  HRESULT RemoveNATPort(const cUPnPNATPort& mapping, bool bRemoveFromList = true);
77  void RemoveMappings();
78 
80  {
81  return m_sLastError;
82  }
83 
84  const cNetAddress& get_LocalAddr();
85  cStringA get_LocalAddrStr();
86  cWinString get_LocalAddrBSTR();
87 
89  };
90 }
91 
92 #endif // _INC_cUPnPNAT_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define _GT(x)
like _T(x) macro for static text.
Definition: StrConst.h:27
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cNetAddr.h:31
Definition: cUPnPNAT.h:23
const GChar_t * get_ProtocolName() const noexcept
Definition: cUPnPNAT.h:44
cString m_sDescription
Arbitrary Port mapping description. (default = AppName)
Definition: cUPnPNAT.h:31
NET_PORT_t m_nExternalPort
Port mapping external port. What the outside world will see.
Definition: cUPnPNAT.h:28
bool m_bEnabled
Definition: cUPnPNAT.h:32
NET_PORT_t m_nInternalPort
Port mapping internal port. actual port should be irrelevant. (default = m_nExternalPort)
Definition: cUPnPNAT.h:29
cUPnPNATPort(NET_PORT_t nExternalPort=k_NET_PORT_INVALID, NET_PORT_t nInternalPort=k_NET_PORT_INVALID, IPPROTO_TYPE nProtocolType=IPPROTO_TCP, cString sDescription="")
Definition: cUPnPNAT.h:35
IPPROTO_TYPE m_nProtocolType
IPPROTO_TCP,IPPROTO_UDP (default = IPPROTO_TCP)
Definition: cUPnPNAT.h:30
Definition: cUPnPNAT.h:54
cString get_LastErrorStr() const
Definition: cUPnPNAT.h:79
UNITTEST_FRIEND(cUPnPNAT)
Definition: cArray.h:932
Definition: cMesh.h:22
WORD NET_PORT_t
WinINet calls ports NET_PORT_t INTERNET_PORT = a service.
Definition: cNetPort.h:21
UNITTEST2_PREDEF(cQuadtree)
int IPPROTO_TYPE
enum of IPPROTO_TCP,IPPROTO_UDP, etc. getprotobyname() and getprotobynumber()
Definition: cNetSocket.h:34
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26