Add -e option to upnpc program (set description for port mappings)

This commit is contained in:
Thomas Bernard 2012-08-30 12:38:27 +02:00
parent d148904d2b
commit 18ea17b95e
2 changed files with 17 additions and 6 deletions

View File

@ -1,6 +1,9 @@
$Id: Changelog.txt,v 1.177 2012/08/29 07:51:29 nanard Exp $ $Id: Changelog.txt,v 1.178 2012/08/30 10:37:18 nanard Exp $
miniUPnP client Changelog. miniUPnP client Changelog.
2012/08/30:
Added -e option to upnpc program (set description for port mappings)
2012/08/29: 2012/08/29:
Python 3 support (thanks to Christopher Foo) Python 3 support (thanks to Christopher Foo)

View File

@ -1,4 +1,4 @@
/* $Id: upnpc.c,v 1.97 2012/06/23 23:16:00 nanard Exp $ */ /* $Id: upnpc.c,v 1.98 2012/08/30 10:37:18 nanard Exp $ */
/* Project : miniupnp /* Project : miniupnp
* Author : Thomas Bernard * Author : Thomas Bernard
* Copyright (c) 2005-2012 Thomas Bernard * Copyright (c) 2005-2012 Thomas Bernard
@ -228,7 +228,8 @@ static void SetRedirectAndTest(struct UPNPUrls * urls,
const char * iport, const char * iport,
const char * eport, const char * eport,
const char * proto, const char * proto,
const char * leaseDuration) const char * leaseDuration,
const char * description)
{ {
char externalIPAddress[40]; char externalIPAddress[40];
char intClient[40]; char intClient[40];
@ -257,7 +258,8 @@ static void SetRedirectAndTest(struct UPNPUrls * urls,
printf("GetExternalIPAddress failed.\n"); printf("GetExternalIPAddress failed.\n");
r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype,
eport, iport, iaddr, 0, proto, 0, leaseDuration); eport, iport, iaddr, description,
proto, 0, leaseDuration);
if(r!=UPNPCOMMAND_SUCCESS) if(r!=UPNPCOMMAND_SUCCESS)
printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
eport, iport, iaddr, r, strupnperror(r)); eport, iport, iaddr, r, strupnperror(r));
@ -487,6 +489,7 @@ int main(int argc, char ** argv)
int retcode = 0; int retcode = 0;
int error = 0; int error = 0;
int ipv6 = 0; int ipv6 = 0;
const char * description = 0;
#ifdef _WIN32 #ifdef _WIN32
WSADATA wsaData; WSADATA wsaData;
@ -513,6 +516,8 @@ int main(int argc, char ** argv)
minissdpdpath = argv[++i]; minissdpdpath = argv[++i];
else if(argv[i][1] == '6') else if(argv[i][1] == '6')
ipv6 = 1; ipv6 = 1;
else if(argv[i][1] == 'e')
description = argv[++i];
else else
{ {
command = argv[i][1]; command = argv[i][1];
@ -551,6 +556,7 @@ int main(int argc, char ** argv)
fprintf(stderr, " \t%s [options] -P\n\t\tGet Presentation url\n", argv[0]); fprintf(stderr, " \t%s [options] -P\n\t\tGet Presentation url\n", argv[0]);
fprintf(stderr, "\nprotocol is UDP or TCP\n"); fprintf(stderr, "\nprotocol is UDP or TCP\n");
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
fprintf(stderr, " -e description : set description for port mapping.\n");
fprintf(stderr, " -6 : use ip v6 instead of ip v4.\n"); fprintf(stderr, " -6 : use ip v6 instead of ip v4.\n");
fprintf(stderr, " -u url : bypass discovery process by providing the XML root description url.\n"); fprintf(stderr, " -u url : bypass discovery process by providing the XML root description url.\n");
fprintf(stderr, " -m address/interface : provide ip address (ip v4) or interface name (ip v4 or v6) to use for sending SSDP multicast packets.\n"); fprintf(stderr, " -m address/interface : provide ip address (ip v4) or interface name (ip v4 or v6) to use for sending SSDP multicast packets.\n");
@ -622,7 +628,8 @@ int main(int argc, char ** argv)
SetRedirectAndTest(&urls, &data, SetRedirectAndTest(&urls, &data,
commandargv[0], commandargv[1], commandargv[0], commandargv[1],
commandargv[2], commandargv[3], commandargv[2], commandargv[3],
(commandargc > 4)?commandargv[4]:"0"); (commandargc > 4)?commandargv[4]:"0",
description);
break; break;
case 'd': case 'd':
for(i=0; i<commandargc; i+=2) for(i=0; i<commandargc; i+=2)
@ -639,7 +646,8 @@ int main(int argc, char ** argv)
/*printf("port %s protocol %s\n", argv[i], argv[i+1]);*/ /*printf("port %s protocol %s\n", argv[i], argv[i+1]);*/
SetRedirectAndTest(&urls, &data, SetRedirectAndTest(&urls, &data,
lanaddr, commandargv[i], lanaddr, commandargv[i],
commandargv[i], commandargv[i+1], "0"); commandargv[i], commandargv[i+1], "0",
description);
} }
break; break;
case 'A': case 'A':