View previous topic :: View next topic |
Author |
Message |
pbft
Joined: 21 Jan 2016 Posts: 7 Location: Vermont
|
Posted: Thu Jan 21, 2016 1:06 pm Post subject: Multiple router issue #1: finding the right one |
|
|
I've been using miniupnp for a while, but I'm new on this forum. I've searched a bit and I haven't found an answer to my problem. My apologies if my search skills are inadequate and this has already been solved.
Sometimes there are several routers on a network, and some of them are being used as hubs - they don't have a WAN connection. They'll still show up in upnpDiscover(), and they will sometimes be returned by UPNP_GetValidIGD().
I developed what seems to me to be a very crude hack, and I'm hoping there's a more elegant solution. I check the wan_address from each IGD against likely invalid external IPs and iterate through the IGDs returned by upnpDiscover() until I find something likely to be valid. Here's the code (blush of embarrassment) .
Code: | next = upnp_dev;
igdevs=0;
while (next){
printf("Device %s\n",next->descURL);
next = next->pNext;
igdevs++;
}
next = upnp_dev;
while(invalidIGD && igdevs > 0){
igdevs--;
invalidIGD = 0;
// Get ID of valid gateway device on network.
int status = UPNP_GetValidIGD(next, &upnp_urls, &upnp_data, lan_address, sizeof(lan_address));
printf("GetValidId returned %d for device at %s\n",status,upnp_urls.controlURL);
if(status == 1){
// get the external (WAN) IP address
UPNP_GetExternalIPAddress(upnp_urls.controlURL, upnp_data.first.servicetype, wan_address);
printf("External address (from function): %s\n",wan_address);
if(!strncmp(wan_address,"0.0.0.0",7)){
printf("Bad external address\n");
next = next->pNext;
invalidIGD = -1;
}
if(!strncmp(wan_address,"192.168",7)){
printf("Bad external address\n");
next = next->pNext;
invalidIGD = -1;
}
if(!strncmp(wan_address,"10.",3)){
printf("Bad external address\n");
next = next->pNext;
invalidIGD = -1;
}
}else{
invalidIGD = -1;
}
}
if(invalidIGD){
printf("Dismal failure in finding valid IGD\n");
}
|
|
|
Back to top |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Thu Jan 21, 2016 3:40 pm Post subject: |
|
|
Good Idea.
I should update UPNP_GetValidIGD() function to include checks on the WAN address.
anyway, that's bad configuration if your router is reporting it is connected when it's not... _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
|
pbft
Joined: 21 Jan 2016 Posts: 7 Location: Vermont
|
Posted: Thu Jan 21, 2016 3:49 pm Post subject: |
|
|
miniupnp wrote: | Good Idea.
I should update UPNP_GetValidIGD() function to include checks on the WAN address.
anyway, that's bad configuration if your router is reporting it is connected when it's not... |
Thanks - that would make things simpler.
By the way, it's not *my* router - my network is perfect
It's what we see when people plug our device into their networks. We just want our device to be able to set up ports in spite of at least the most common mistakes that people make in setting up their networks. |
|
Back to top |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Thu Jan 21, 2016 4:02 pm Post subject: |
|
|
what is "your device" ? only curious (you can answer my by private email _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
|
pbft
Joined: 21 Jan 2016 Posts: 7 Location: Vermont
|
Posted: Thu Jan 21, 2016 4:07 pm Post subject: |
|
|
miniupnp wrote: | what is "your device" ? only curious (you can answer my by private email |
It's not a secret - just not directly relevant to the question. Glad to share. We make the 'Vesta' - an open-source monitoring / datalogging / control system, usually installed to manage complex heating systems.
We have very little control over where and how these are installed, and most users would like external access. |
|
Back to top |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
|
Back to top |
|
|
pbft
Joined: 21 Jan 2016 Posts: 7 Location: Vermont
|
Posted: Fri Jan 22, 2016 2:37 pm Post subject: |
|
|
miniupnp wrote: | https://github.com/miniupnp/miniupnp/commit/99c7aeef4d5b25f7d5adb1edc6a23d9544cb6002 |
Awesome - thanks! |
|
Back to top |
|
|
pbft
Joined: 21 Jan 2016 Posts: 7 Location: Vermont
|
Posted: Sun Jan 24, 2016 12:05 pm Post subject: |
|
|
miniupnp wrote: | https://github.com/miniupnp/miniupnp/commit/99c7aeef4d5b25f7d5adb1edc6a23d9544cb6002 |
I also see routers used as hubs, with no WAN port connection. They'll return 0.0.0.0 as a WAN address. |
|
Back to top |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Sun Jan 24, 2016 4:14 pm Post subject: |
|
|
they should return the empty string, but...
I'm adding a check _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
|
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
|
Back to top |
|
|
|