diff --git a/ctru-rs/examples/wifi-info.rs b/ctru-rs/examples/wifi-info.rs index c518039..36ed860 100644 --- a/ctru-rs/examples/wifi-info.rs +++ b/ctru-rs/examples/wifi-info.rs @@ -37,6 +37,13 @@ fn print_network_info(ac: &Ac) -> ctru::Result<()> { if connected { println!("Wi-Fi SSID: {}", ac.get_wifi_ssid()?); println!("Wi-Fi security: {:?}", ac.get_wifi_security()?); + let proxied = ac.get_proxy_enabled()?; + println!("Proxy enabled: {}", proxied); + if proxied { + println!("Proxy port: {}", ac.get_proxy_port()?); + println!("Proxy username: {}", ac.get_proxy_username()?); + println!("Proxy password: {}", ac.get_proxy_password()?); + } } Ok(()) diff --git a/ctru-rs/src/services/ac.rs b/ctru-rs/src/services/ac.rs index 4b91340..2630629 100644 --- a/ctru-rs/src/services/ac.rs +++ b/ctru-rs/src/services/ac.rs @@ -140,12 +140,134 @@ impl Ac { let mut len = 0u32; ResultCode(ctru_sys::ACU_GetSSIDLength(&mut len))?; // we don't really need space for the terminator - let mut vec: Vec = vec![0u8; len as usize]; + let mut vec = vec![0u8; len as usize]; ResultCode(ctru_sys::ACU_GetSSID(vec.as_mut_ptr()))?; // how do i handle this error? Ok(String::from_utf8(vec).unwrap()) } } + + /// Returns whether the console is connected to a proxy. + /// + /// # Example + /// + /// ``` + /// # let _runner = test_runner::GdbRunner::default(); + /// # use std::error::Error; + /// # fn main() -> Result<(), Box> { + /// # + /// use ctru::services::ac::Ac; + /// + /// let ac = Ac::new()?; + /// + /// println!("Proxy enabled: {}", ac.get_proxy_enabled()?); + /// + /// # + /// # Ok(()) + /// # } + /// ``` + #[doc(alias = "ACU_GetProxyEnable")] + pub fn get_proxy_enabled(&self) -> crate::Result { + unsafe { + let mut ret = false; + ResultCode(ctru_sys::ACU_GetProxyEnable(&mut ret))?; + + Ok(ret) + } + } + + /// Returns the connected network's proxy port, if present. + /// + /// You can check if the console is using a proxy with [`Self::get_proxy_enabled()`] + /// + /// # Example + /// + /// ``` + /// # let _runner = test_runner::GdbRunner::default(); + /// # use std::error::Error; + /// # fn main() -> Result<(), Box> { + /// # + /// use ctru::services::ac::Ac; + /// + /// let ac = Ac::new()?; + /// + /// println!("Proxy port: {}", ac.get_proxy_port()?); + /// # + /// # Ok(()) + /// # } + /// ``` + #[doc(alias = "ACU_GetProxyPort")] + pub fn get_proxy_port(&self) -> crate::Result { + unsafe { + let mut ret = 0u32; + ResultCode(ctru_sys::ACU_GetProxyPort(&mut ret))?; + + Ok(ret) + } + } + + /// Returns the connected network's proxy username, if present. + /// + /// You can check if the console is using a proxy with [`Self::get_proxy_enabled()`] + /// + /// # Example + /// + /// ``` + /// # let _runner = test_runner::GdbRunner::default(); + /// # use std::error::Error; + /// # fn main() -> Result<(), Box> { + /// # + /// use ctru::services::ac::Ac; + /// + /// let ac = Ac::new()?; + /// + /// println!("Proxy username: {}", ac.get_proxy_username()?); + /// + /// # + /// # Ok(()) + /// # } + /// ``` + #[doc(alias = "ACU_GetProxyUserName")] + pub fn get_proxy_username(&self) -> crate::Result { + unsafe { + let mut vec = vec![0u8; 0x20]; + ResultCode(ctru_sys::ACU_GetProxyUserName(vec.as_mut_ptr()))?; + + // how do i handle this error? + Ok(String::from_utf8(vec).unwrap()) + } + } + + /// Returns the connected network's proxy password, if present. + /// + /// You can check if the console is using a proxy with [`Self::get_proxy_enabled()`] + /// + /// # Example + /// + /// ``` + /// # let _runner = test_runner::GdbRunner::default(); + /// # use std::error::Error; + /// # fn main() -> Result<(), Box> { + /// # + /// use ctru::services::ac::Ac; + /// + /// let ac = Ac::new()?; + /// + /// println!("Proxy password: {}", ac.get_proxy_password()?); + /// # + /// # Ok(()) + /// # } + /// ``` + #[doc(alias = "ACU_GetProxyPassword")] + pub fn get_proxy_password(&self) -> crate::Result { + unsafe { + let mut vec = vec![0u8; 0x20]; + ResultCode(ctru_sys::ACU_GetProxyPassword(vec.as_mut_ptr()))?; + + // how do i handle this error? + Ok(String::from_utf8(vec).unwrap()) + } + } } impl Drop for Ac {