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 

A few patches to miniupnpc

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Bugs
View previous topic :: View next topic  
Author Message
GilesBathgate



Joined: 13 May 2009
Posts: 2

PostPosted: Wed May 13, 2009 3:27 pm    Post subject: A few patches to miniupnpc Reply with quote

Here are a few patches that can be applied (in sequence) to miniupnpc-1.3

*Ability to delete multiple mappings in one command
Code:


diff --git a/upnpc.c b/upnpc.c
index 2c5debe..b115a38 100644
--- a/upnpc.c
+++ b/upnpc.c
@@ -336,7 +336,11 @@ int main(int argc, char ** argv)
                                                   commandargv[2], commandargv[3]);
                                break;
                        case 'd':
-                               RemoveRedirect(&urls, &data, commandargv[0], commandargv[1]);
+                               for(i=0; i<commandargc; i+=2)
+                               {
+                                       RemoveRedirect(&urls, &data,
+                                                               commandargv[i], commandargv[i+1]);
+                               }
                                break;
                        case 's':
                                GetConnectionStatus(&urls, &data);




*Usage message only printed when user specifies -h, banner only printed when no parameters given
Code:

diff --git a/upnpc.c b/upnpc.c
index b115a38..7cb5358 100644
--- a/upnpc.c
+++ b/upnpc.c
@@ -209,6 +209,21 @@ RemoveRedirect(struct UPNPUrls * urls,
        printf("UPNP_DeletePortMapping() returned : %d\n", r);
 }

+void usage(char* name)
+{
+
+               fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol\n\t\tAdd port redirection\n", name);
+               fprintf(stderr, "       \t%s [options] -d external_port protocol [external_port2 protocol2] [...]\n\t\tDelete port redirections\n", name);
+               fprintf(stderr, "       \t%s [options] -s\n\t\tGet Connection status\n", name);
+               fprintf(stderr, "       \t%s [options] -l\n\t\tList redirections\n", name);
+               fprintf(stderr, "       \t%s [options] -r port1 protocol1 [port2 protocol2] [...]\n\t\tAdd all redirections to the current host\n", name);
+               fprintf(stderr, "\nprotocol is UDP or TCP\n");
+               fprintf(stderr, "Options:\n");
+               fprintf(stderr, "  -u url : bypass discovery process by providing the XML root description url.\n");
+               fprintf(stderr, "  -m address : provide ip address of the interface to use for sending SSDP multicast packets.\n");
+               fprintf(stderr, "  -p path : use this path for MiniSSDPd socket.\n");
+}
+

 /* sample upnp client program */
 int main(int argc, char ** argv)
@@ -232,9 +247,6 @@ int main(int argc, char ** argv)
                return -1;
        }
 #endif
-    printf("upnpc : miniupnpc library test client. (c) 2006-2008 Thomas Bernard\n");
-    printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n"
-              "for more information.\n");
        /* command line processing */
        for(i=1; i<argc; i++)
        {
@@ -246,6 +258,11 @@ int main(int argc, char ** argv)
                                multicastif = argv[++i];
                        else if(argv[i][1] == 'p')
                                minissdpdpath = argv[++i];
+                       else if(argv[i][1] == 'h')
+                       {
+                               usage(argv[0]);
+                               return 0;
+                       }
                        else
                        {
                                command = argv[i][1];
@@ -265,16 +282,8 @@ int main(int argc, char ** argv)
           || (command == 'd' && argc<2)
           || (command == 'r' && argc<2))
        {
-               fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol\n\t\tAdd port redirection\n", argv[0]);
-               fprintf(stderr, "       \t%s [options] -d external_port protocol\n\t\tDelete port redirection\n", argv[0]);
-               fprintf(stderr, "       \t%s [options] -s\n\t\tGet Connection status\n", argv[0]);
-               fprintf(stderr, "       \t%s [options] -l\n\t\tList redirections\n", argv[0]);
-               fprintf(stderr, "       \t%s [options] -r port1 protocol1 [port2 protocol2] [...]\n\t\tAdd all redirections to the current host\n", argv[0]);
-               fprintf(stderr, "\nprotocol is UDP or TCP\n");
-               fprintf(stderr, "Options:\n");
-               fprintf(stderr, "  -u url : bypass discovery process by providing the XML root description url.\n");
-               fprintf(stderr, "  -m address : provide ip address of the interface to use for sending SSDP multicast packets.\n");
-               fprintf(stderr, "  -p path : use this path for MiniSSDPd socket.\n");
+               fprintf(stderr, "%s : miniupnpc library test client. (c) 2006-2008 Thomas Bernard\n",argv[0]);
+               fprintf(stderr, "Try `%s -h' for more information.\n",argv[0]);
                return 1;
        }




*Switched off some verbose messages by default, re-enabled using command line argument -v
Code:


diff --git a/upnpc.c b/upnpc.c
index 7cb5358..e5b6356 100644
--- a/upnpc.c
+++ b/upnpc.c
@@ -237,6 +237,7 @@ int main(int argc, char ** argv)
        const char * rootdescurl = 0;
        const char * multicastif = 0;
        const char * minissdpdpath = 0;
+       int verbose = 0; //verbosity level

 #ifdef WIN32
        WSADATA wsaData;
@@ -258,6 +259,8 @@ int main(int argc, char ** argv)
                                multicastif = argv[++i];
                        else if(argv[i][1] == 'p')
                                minissdpdpath = argv[++i];
+                       else if(argv[i][1] == 'v')
+                               verbose++;
                        else if(argv[i][1] == 'h')
                        {
                                usage(argv[0]);
@@ -295,34 +298,41 @@ int main(int argc, char ** argv)
                struct IGDdatas data;
                if(devlist)
                {
-                       printf("List of UPNP devices found on the network :\n");
-                       for(device = devlist; device; device = device->pNext)
+                       if(verbose>0)
                        {
-                               printf(" desc: %s\n st: %s\n\n",
+                               printf("List of UPNP devices found on the network :\n");
+                               for(device = devlist; device; device = device->pNext)
+                               {
+                                       printf(" desc: %s\n st: %s\n\n",
                                           device->descURL, device->st);
+                               }
                        }
                }
                i = 1;
                if( (rootdescurl && UPNP_GetIGDFromUrl(rootdescurl, &urls, &data, lanaddr, sizeof(lanaddr)))
                  || (i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr))))
                {
-                       switch(i) {
-                       case 1:
-                               printf("Found valid IGD : %s\n", urls.controlURL);
-                               break;
-                       case 2:
-                               printf("Found a (not connected?) IGD : %s\n", urls.controlURL);
-                               printf("Trying to continue anyway\n");
-                               break;
-                       case 3:
-                               printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL);
-                               printf("Trying to continue anyway\n");
-                               break;
-                       default:
-                               printf("Found device (igd ?) : %s\n", urls.controlURL);
-                               printf("Trying to continue anyway\n");
+                       if(verbose>0)
+                       {
+                               switch(i) {
+                               case 1:
+                                       printf("Found valid IGD : %s\n", urls.controlURL);
+                                       break;
+                               case 2:
+                                       printf("Found a (not connected?) IGD : %s\n", urls.controlURL);
+                                       printf("Trying to continue anyway\n");
+                                       break;
+                               case 3:
+                                       printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL);
+                                       printf("Trying to continue anyway\n");
+                                       break;
+                               default:
+                                       printf("Found device (igd ?) : %s\n", urls.controlURL);
+                                       printf("Trying to continue anyway\n");
+                               }
+
+                               printf("Local LAN ip address : %s\n", lanaddr);
                        }
-                       printf("Local LAN ip address : %s\n", lanaddr);
                        #if 0
                        printf("getting \"%s\"\n", urls.ipcondescURL);
                        descXML = miniwget(urls.ipcondescURL, &descXMLsize);


Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1525

PostPosted: Wed May 13, 2009 8:16 pm    Post subject: Reply with quote

thank you
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
GilesBathgate



Joined: 13 May 2009
Posts: 2

PostPosted: Wed May 13, 2009 9:55 pm    Post subject: Reply with quote

No worries, pull my git repo if you want:
Code:

git clone http://gilesbathgate.homeip.net/miniupnpc.git
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Bugs 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.