miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multiple router issue #1: finding the right one

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation
View previous topic :: View next topic  
Author Message
pbft



Joined: 21 Jan 2016
Posts: 7
Location: Vermont

PostPosted: Thu Jan 21, 2016 1:06 pm    Post subject: Multiple router issue #1: finding the right one Reply with quote

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
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Thu Jan 21, 2016 3:40 pm    Post subject: Reply with quote

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.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
pbft



Joined: 21 Jan 2016
Posts: 7
Location: Vermont

PostPosted: Thu Jan 21, 2016 3:49 pm    Post subject: Reply with quote

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 Wink

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
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Thu Jan 21, 2016 4:02 pm    Post subject: Reply with quote

what is "your device" ? only curious (you can answer my by private email Smile
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
pbft



Joined: 21 Jan 2016
Posts: 7
Location: Vermont

PostPosted: Thu Jan 21, 2016 4:07 pm    Post subject: Reply with quote

miniupnp wrote:
what is "your device" ? only curious (you can answer my by private email Smile


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
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Fri Jan 22, 2016 2:22 pm    Post subject: Reply with quote

https://github.com/miniupnp/miniupnp/commit/99c7aeef4d5b25f7d5adb1edc6a23d9544cb6002
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
pbft



Joined: 21 Jan 2016
Posts: 7
Location: Vermont

PostPosted: Fri Jan 22, 2016 2:37 pm    Post subject: Reply with quote

miniupnp wrote:
https://github.com/miniupnp/miniupnp/commit/99c7aeef4d5b25f7d5adb1edc6a23d9544cb6002


Awesome - thanks!
Back to top
View user's profile Send private message
pbft



Joined: 21 Jan 2016
Posts: 7
Location: Vermont

PostPosted: Sun Jan 24, 2016 12:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Sun Jan 24, 2016 4:14 pm    Post subject: Reply with quote

they should return the empty string, but...
I'm adding a check Smile
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Sun Jan 24, 2016 4:34 pm    Post subject: Reply with quote

https://github.com/miniupnp/miniupnp/commit/1c61d33f2c5fe9b8010342c1c067dede7a98acb1
* edit *
sorry :
https://github.com/miniupnp/miniupnp/commit/d274456d0730a4543ef6039396f476f0b1142ff4
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.