miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Opening a port & doc

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation
View previous topic :: View next topic  
Author Message
al086



Joined: 28 May 2012
Posts: 1
Location: France

PostPosted: Mon May 28, 2012 4:03 pm    Post subject: Opening a port & doc Reply with quote

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);
        }
    }
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1448

PostPosted: Tue May 29, 2012 9:57 am    Post subject: Reply with quote

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 Smile

For more information, have a look at the upnpc.c sample program
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.