al086
Joined: 28 May 2012 Posts: 1 Location: France
|
Posted: Mon May 28, 2012 4:03 pm Post subject: Opening a port & doc |
|
|
Hello everyone,
Thanks for miniUPnP, it's exactly what I need for a project I'm working on. However, I have not found any documentation. Could you tell my where I might find any?
I'd like to open a router port, and by what I have understood I should use the function upnpDiscover and UPNP_AddPortMapping. Could someone show me how exactly to proceed to open a port? (code for example)
Thanks alot!
Here's the code :
Code: | struct UPNPDev *devices = upnpDiscover(10, NULL, NULL, 0,0,NULL);
if(devices)
{
struct IGDdatas *data = (struct IGDdatas *)malloc(sizeof(struct IGDdatas));
struct UPNPUrls *urls = (struct UPNPUrls *)malloc(sizeof(struct UPNPUrls));
if(data == NULL || urls == NULL)
{
free((void*)data);
free((void*)urls);
freeUPNPDevlist(devices);
WSACleanup();
}
else
{
int validDevices = UPNP_GetValidIGD(devices, urls, data, NULL, 0);
int Returns = 0;
if(validDevices > 0)
{
Returns = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, "7171", "7171", locIp, NULL, "TCP", NULL,"0");
}
free((void*)data);
free((void*)urls);
freeUPNPDevlist(devices);
}
} |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1589
|
Posted: Tue May 29, 2012 9:57 am Post subject: |
|
|
your code looks ok, except that you should pass a longer timeout value to upnpDiscover().
10 ms is very short, chances are small that your router will answer so fast
For more information, have a look at the upnpc.c sample program _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|