2

I'm currently working with P2P Network over the Internet using C/C++ and Winsock2. With that, I want to do port forwarding with the router using UPNP (I know some router does not have UPNP, I just need to do this with this technology).

I want to make a simple class namely "NATUPNP" to do all NAT Traversal using UPNP. I already made this class but it caused a lot of bugs since I'm not really into network programming sorry (simple knowledge only). If someone know how to do this I would really appreciate your effort. Below is my class with the functions/methods that I would like to be there and working. Thanks in advance.

#include <Winsock2.h>
#include <Ws2tcpip.h>

class NATUPNP
{
    public:
    string getPublicIP(); //return the Public IP Address of the Network

    bool isUPNPEnabled(); //return true if router can do UPNP NAT Traversal, if not return false

    bool isPortForwarded(int port); //return true if port is forwarded by the router, if not return false

    bool addPortForward(int externalPort, int internalPort, string ipAddress); //ask router to forward this port to this local ipAddress

    bool removePortForward(int externalPort, int internalPort, string ipAddress); //ask router to remove port forward to this local ipAddress
};
Techreator
  • 83
  • 8
  • [this link](https://www.codeproject.com/Articles/13285/Using-UPnP-for-Programmatic-Port-Forwardings-and-N) could probably help. – dvhh Jan 22 '19 at 08:19
  • Thanks for replying but I already tried that one but the code is not working anymore. The post is way back 2006. – Techreator Jan 22 '19 at 08:25
  • other search reveal a NuGet package [Open.Nat](https://github.com/lontivero/Open.NAT/tree/master/Open.Nat) which is written in C# but could be converted in C++ – dvhh Jan 23 '19 at 03:58
  • What do you mean convert? C# to C++? Open.Nat composed of different files. – Techreator Jan 25 '19 at 03:42

0 Answers0