manage [remote host]

This commit is contained in:
jlayec 2019-07-13 12:39:33 +02:00
parent 343bb320b8
commit e1ff22b20d
1 changed files with 13 additions and 10 deletions

View File

@ -250,6 +250,7 @@ static int SetRedirectAndTest(struct UPNPUrls * urls,
const char * eport,
const char * proto,
const char * leaseDuration,
const char * remoteHost,
const char * description,
int addAny)
{
@ -283,7 +284,7 @@ static int SetRedirectAndTest(struct UPNPUrls * urls,
if (addAny) {
r = UPNP_AddAnyPortMapping(urls->controlURL, data->first.servicetype,
eport, iport, iaddr, description,
proto, 0, leaseDuration, reservedPort);
proto, remoteHost, leaseDuration, reservedPort);
if(r==UPNPCOMMAND_SUCCESS)
eport = reservedPort;
else
@ -292,7 +293,7 @@ static int SetRedirectAndTest(struct UPNPUrls * urls,
} else {
r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype,
eport, iport, iaddr, description,
proto, 0, leaseDuration);
proto, remoteHost, leaseDuration);
if(r!=UPNPCOMMAND_SUCCESS) {
printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
eport, iport, iaddr, r, strupnperror(r));
@ -302,7 +303,7 @@ static int SetRedirectAndTest(struct UPNPUrls * urls,
r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
data->first.servicetype,
eport, proto, NULL/*remoteHost*/,
eport, proto, remoteHost,
intClient, intPort, NULL/*desc*/,
NULL/*enabled*/, duration);
if(r!=UPNPCOMMAND_SUCCESS) {
@ -642,12 +643,12 @@ int main(int argc, char ** argv)
|| (command == 'U' && commandargc<2)
|| (command == 'D' && commandargc<1))
{
fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol [duration]\n\t\tAdd port redirection\n", argv[0]);
fprintf(stderr, " \t%s [options] -d external_port protocol <remote host>\n\t\tDelete port redirection\n", argv[0]);
fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol [duration] [remote host]\n\t\tAdd port redirection\n", argv[0]);
fprintf(stderr, " \t%s [options] -d external_port protocol [remote host]\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] -L\n\t\tList redirections (using GetListOfPortMappings (for IGD:2 only)\n", argv[0]);
fprintf(stderr, " \t%s [options] -n ip port external_port protocol [duration]\n\t\tAdd (any) port redirection allowing IGD to use alternative external_port (for IGD:2 only)\n", argv[0]);
fprintf(stderr, " \t%s [options] -n ip port external_port protocol [duration] [remote host]\n\t\tAdd (any) port redirection allowing IGD to use alternative external_port (for IGD:2 only)\n", argv[0]);
fprintf(stderr, " \t%s [options] -N external_port_start external_port_end protocol [manage]\n\t\tDelete range of port redirections (for IGD:2 only)\n", argv[0]);
fprintf(stderr, " \t%s [options] -r port1 [external_port1] protocol1 [port2 [external_port2] protocol2] [...]\n\t\tAdd all redirections to the current host\n", argv[0]);
fprintf(stderr, " \t%s [options] -A remote_ip remote_port internal_ip internal_port protocol lease_time\n\t\tAdd Pinhole (for IGD:2 only)\n", argv[0]);
@ -734,7 +735,8 @@ int main(int argc, char ** argv)
if (SetRedirectAndTest(&urls, &data,
commandargv[0], commandargv[1],
commandargv[2], commandargv[3],
(commandargc > 4)?commandargv[4]:"0",
(commandargc > 4)&is_int(commandargv[4])?commandargv[4]:"0",
(commandargc > 4)&!is_int(commandargv[4])?commandargv[4]:(commandargc > 5)?commandargv[5]:NULL,
description, 0) < 0)
retcode = 2;
break;
@ -747,7 +749,8 @@ int main(int argc, char ** argv)
if (SetRedirectAndTest(&urls, &data,
commandargv[0], commandargv[1],
commandargv[2], commandargv[3],
(commandargc > 4)?commandargv[4]:"0",
(commandargc > 4)&is_int(commandargv[4])?commandargv[4]:"0",
(commandargc > 4)&!is_int(commandargv[4])?commandargv[4]:(commandargc > 5)?commandargv[5]:NULL,
description, 1) < 0)
retcode = 2;
break;
@ -775,7 +778,7 @@ int main(int argc, char ** argv)
/* 2nd parameter is an integer : <port> <external_port> <protocol> */
if (SetRedirectAndTest(&urls, &data,
lanaddr, commandargv[i],
commandargv[i+1], commandargv[i+2], "0",
commandargv[i+1], commandargv[i+2], "0", NULL,
description, 0) < 0)
retcode = 2;
i+=3; /* 3 parameters parsed */
@ -783,7 +786,7 @@ int main(int argc, char ** argv)
/* 2nd parameter not an integer : <port> <protocol> */
if (SetRedirectAndTest(&urls, &data,
lanaddr, commandargv[i],
commandargv[i], commandargv[i+1], "0",
commandargv[i], commandargv[i+1], "0", NULL,
description, 0) < 0)
retcode = 2;
i+=2; /* 2 parameters parsed */