Merge pull request #723 from bozheng1988/master

upnpc: Add -f option to delete multiple port redirections
This commit is contained in:
Thomas BERNARD 2024-05-08 15:57:54 +02:00 committed by GitHub
commit ecb25c3bbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 0 deletions

View File

@ -567,6 +567,7 @@ static void usage(FILE * out, const char * argv0) {
fprintf(out, " %s [options] -a ip port external_port protocol [duration] [remote host]\n Add port mapping\n", argv0);
fprintf(out, " %s [options] -r port1 [external_port1] protocol1 [port2 [external_port2] protocol2] [...]\n Add multiple port mappings to the current host\n", argv0);
fprintf(out, " %s [options] -d external_port protocol [remote host]\n Delete port redirection\n", argv0);
fprintf(out, " %s [options] -f external_port1 protocol1 [external_port2 protocol2] [...]\n Delete multiple port redirections\n", argv0);
fprintf(out, " %s [options] -s\n Get Connection status\n", argv0);
fprintf(out, " %s [options] -l\n List redirections\n", argv0);
fprintf(out, " %s [options] -L\n List redirections (using GetListOfPortMappings (for IGD:2 only)\n", argv0);
@ -834,6 +835,29 @@ int main(int argc, char ** argv)
}
}
break;
case 'f':
i = 0;
while(i<commandargc)
{
if(!is_int(commandargv[i])) {
/* 1st parameter not an integer : error */
fprintf(stderr, "command -f : %s is not an port number\n", commandargv[i]);
retcode = 1;
break;
} else if(i+1 == commandargc){
/* too few arguments */
fprintf(stderr, "command -f : too few arguments\n");
retcode = 2;
break;
} else {
/* <port> <protocol> */
if (RemoveRedirect(&urls, &data,
commandargv[i], commandargv[i+1], NULL) < 0)
retcode = 3;
i+=2; /* 2 parameters parsed */
}
}
break;
case 'A':
SetPinholeAndTest(&urls, &data,
commandargv[0], commandargv[1],