2

我目前正在使用 C/C++ 和 Winsock2 在 Internet 上使用 P2P 网络。有了这个,我想用 UPNP 与路由器进行端口转发(我知道有些路由器没有 UPNP,我只需要用这种技术来做)。

我想创建一个简单的类,即“NATUPNP”来使用 UPNP 进行所有 NAT 遍历。我已经上了这门课,但它引起了很多错误,因为我不是很喜欢网络编程抱歉(仅限简单知识)。如果有人知道如何做到这一点,我将非常感谢您的努力。下面是我的课程,其中包含我想在那里工作的功能/方法。提前致谢。

#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
};
4

0 回答 0