Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

search_gateway(), IO error: Resource temporarily unavailable (os error 11) #38

Closed
CDuPlooy opened this issue Jul 17, 2019 · 2 comments
Closed

Comments

@CDuPlooy
Copy link
Contributor

CDuPlooy commented Jul 17, 2019

I'm not sure if I'm just doing something stupid or if my router is completely and utterly broken but I get the above error when executing any of the example code.

extern crate igd;
use igd::*;
use std::time::Duration;
use std::net::{SocketAddr};

fn main() {
    let opt = SearchOptions{
        bind_addr: "0.0.0.0:0".parse::<SocketAddr>().unwrap(),
        broadcast_address: "239.255.255.250:1900".parse::<SocketAddr>().unwrap(),
        timeout: Some(Duration::from_secs(5)),
    };

    match igd::search_gateway(opt) {
        Err(ref err) => println!("Error: {}", err),
        Ok(gateway) => {
            match gateway.get_external_ip() {
                Err(ref err) => {
                    println!("There was an error! {}", err);
                },
                Ok(ext_addr) => {
                    println!("Local gateway: {}, External ip address: {}", gateway, ext_addr);
                },
            }
        },
    }
}

It is worth noting that I tested this on a few friend's routers which also had upnp enabled but got the same error, I decreased the timeout on the SearchOptions just to be able to test a little quicker but it fails regardless.

EDIT:

I've managed to find out that the code is complaining about an invalid response in particular:

<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://10.0.0.2:5431/</URLBase>
<device>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
<presentationURL>http://10.0.0.2:80/</presentationURL>
<friendlyName>Broadcom xDSL Router</friendlyName>
<manufacturer>D-Link</manufacturer>
<manufacturerURL>http://www.broadcom.com/</manufacturerURL>
<modelDescription>DSL-G225</modelDescription>
<modelName>DSL-G225</modelName>
<modelNumber>1.0</modelNumber>
<modelURL>http://www.broadcom.com/</modelURL>
<UDN>uuid:10bef592-a26d-6da2-92f5-be10be926d0000</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
<serviceId>urn:upnp-org:serviceId:Layer3Forwarding.1</serviceId>
<controlURL>/uuid:10bef592-a26d-6da2-92f5-be10be926d0000/Layer3Forwarding:1</controlURL>
<eventSubURL>/uuid:10bef592-a26d-6da2-92f5-be10be926d0000/Layer3Forwarding:1</eventSubURL>
<SCPDURL>/dynsvc/Layer3Forwarding:1.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>WANDevice.1</friendlyName>
<manufacturer>D-Link</manufacturer>
<manufacturerURL>http://www.broadcom.com/</manufacturerURL>
<modelDescription>DSL-G225</modelDescription>
<modelName>DSL-G225</modelName>
<modelNumber>1.0</modelNumber>
<modelURL>http://www.broadcom.com/</modelURL>
<UDN>uuid:10bef592-a26d-6da2-92f5-be10be926d0001</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig.1</serviceId>
<controlURL>/uuid:10bef592-a26d-6da2-92f5-be10be926d0001/WANCommonInterfaceConfig:1</controlURL>
<eventSubURL>/uuid:10bef592-a26d-6da2-92f5-be10be926d0001/WANCommonInterfaceConfig:1</eventSubURL>
<SCPDURL>/dynsvc/WANCommonInterfaceConfig:1.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WanConnectionDevice.1</friendlyName>
<manufacturer>D-Link</manufacturer>
<manufacturerURL>http://www.broadcom.com/</manufacturerURL>
<modelDescription>DSL-G225</modelDescription>
<modelName>DSL-G225</modelName>
<modelNumber>1.0</modelNumber>
<modelURL>http://www.broadcom.com/</modelURL>
<UDN>uuid:10bef592-a26d-6da2-92f5-be10be926d0002</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANPPPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANPPPConnection.1</serviceId>
<controlURL>/uuid:10bef592-a26d-6da2-92f5-be10be926d0002/WANPPPConnection:1</controlURL>
<eventSubURL>/uuid:10bef592-a26d-6da2-92f5-be10be926d0002/WANPPPConnection:1</eventSubURL>
<SCPDURL>/dynsvc/WANPPPConnection:1.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>
@CDuPlooy
Copy link
Contributor Author

CDuPlooy commented Jul 17, 2019

In the code, specifically parsing.rs on line 53 a check is made for urn:schemas-upnp-org:service:WANIPConnection:1, the closest thing I have in my xml is urn:schemas-upnp-org:service:WANPPPConnection1 and changing it to that gets the example to run. I don't really have much experience with networking but all routers in South Africa use PPP as far as I know, perhaps I could open a pull request to check for either of the above and use the appropriate one?

@CDuPlooy
Copy link
Contributor Author

Added some code to #40 that could possibly make the search_gateway() function a little more versatile, thanks @sbstp for merging! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant