miniupnpc: By default skip invalid, disconnected and non-IGD devices

Allow to use such IGD devices by new -i option.
This commit is contained in:
Pali Rohár 2020-10-05 22:06:03 +02:00
parent 11c479fb2a
commit fb9d162a9c
1 changed files with 9 additions and 0 deletions

View File

@ -571,6 +571,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;
int ignore = 0;
unsigned char ttl = 2; /* defaulting to 2 */ unsigned char ttl = 2; /* defaulting to 2 */
const char * description = 0; const char * description = 0;
@ -624,6 +625,8 @@ int main(int argc, char ** argv)
description = argv[++i]; description = argv[++i];
else if(argv[i][1] == 't') else if(argv[i][1] == 't')
ttl = (unsigned char)atoi(argv[++i]); ttl = (unsigned char)atoi(argv[++i]);
else if(argv[i][1] == 'i')
ignore = 1;
else else
{ {
command = argv[i][1]; command = argv[i][1];
@ -672,6 +675,7 @@ int main(int argc, char ** argv)
fprintf(stderr, " -z localport : SSDP packets local (source) port (1024-65535).\n"); fprintf(stderr, " -z localport : SSDP packets local (source) port (1024-65535).\n");
fprintf(stderr, " -p path : use this path for MiniSSDPd socket.\n"); fprintf(stderr, " -p path : use this path for MiniSSDPd socket.\n");
fprintf(stderr, " -t ttl : set multicast TTL. Default value is 2.\n"); fprintf(stderr, " -t ttl : set multicast TTL. Default value is 2.\n");
fprintf(stderr, " -i : ignore errors and try to use also disconnected IGD or non-IGD device.\n");
return 1; return 1;
} }
@ -705,15 +709,19 @@ int main(int argc, char ** argv)
break; break;
case 2: case 2:
printf("Found a (not connected?) IGD : %s\n", urls.controlURL); printf("Found a (not connected?) IGD : %s\n", urls.controlURL);
if (!ignore) goto invalid;
printf("Trying to continue anyway\n"); printf("Trying to continue anyway\n");
break; break;
case 3: case 3:
printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL); printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL);
if (!ignore) goto invalid;
printf("Trying to continue anyway\n"); printf("Trying to continue anyway\n");
break; break;
default: default:
printf("Found device (igd ?) : %s\n", urls.controlURL); printf("Found device (igd ?) : %s\n", urls.controlURL);
if (!ignore) goto invalid;
printf("Trying to continue anyway\n"); printf("Trying to continue anyway\n");
break;
} }
printf("Local LAN ip address : %s\n", lanaddr); printf("Local LAN ip address : %s\n", lanaddr);
#if 0 #if 0
@ -847,6 +855,7 @@ int main(int argc, char ** argv)
} }
else else
{ {
invalid:
fprintf(stderr, "No valid UPNP Internet Gateway Device found.\n"); fprintf(stderr, "No valid UPNP Internet Gateway Device found.\n");
retcode = 1; retcode = 1;
} }