-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportmanager.cpp
45 lines (40 loc) · 1.27 KB
/
portmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "portmanager.h"
PortManager::PortManager(QObject *parent) : QObject(parent)
{
#ifdef Q_OS_WIN
nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
#endif
}
void PortManager::discover() {
int errorCode;
#if MINIUPNPC_API_VERSION>=14
devlist = upnpDiscover(timeout, multicastif, minissdpdpath,
localport, ipv6, ttl, &error);
#else
devlist = upnpDiscover(timeout, multicastif, minissdpdpath,
localport, ipv6, &error);
#endif
errorCode = UPNP_GetValidIGD(devlist, &urls, &data,
lanaddr, sizeof(lanaddr));
emit discoveryFinished(errorCode);
}
void PortManager::openPort() {
int errorCode;
errorCode = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
port, port, lanaddr, description,
protocol, 0, 0);
emit openingFinished(errorCode);
}
void PortManager::closePort() {
int errorCode;
errorCode = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype,
port, protocol, 0);
emit closingFinished(errorCode);
}
PortManager::~PortManager(){
closePort();
FreeUPNPUrls(&urls);
#ifdef Q_OS_WIN
nResult = WSACleanup();
#endif
}