]> code.octet-stream.net Git - netwatcher/blobdiff - src/list_win.rs
Fix typo in README
[netwatcher] / src / list_win.rs
index 8f0b7833d5d1a2a57782d55bc38f3533dd9181d6..00b776987d015cc4c599dd9379554338f43273bc 100644 (file)
@@ -38,15 +38,15 @@ pub(crate) fn list_interfaces() -> Result<List, Error> {
             );
             match WIN32_ERROR(res) {
                 ERROR_SUCCESS => break,
             );
             match WIN32_ERROR(res) {
                 ERROR_SUCCESS => break,
-                ERROR_ADDRESS_NOT_ASSOCIATED => return Err(Error::Internal),
+                ERROR_ADDRESS_NOT_ASSOCIATED => return Err(Error::AddressNotAssociated),
                 ERROR_BUFFER_OVERFLOW => {
                     buf.resize(sizepointer as usize, 0);
                     continue;
                 }
                 ERROR_BUFFER_OVERFLOW => {
                     buf.resize(sizepointer as usize, 0);
                     continue;
                 }
-                ERROR_INVALID_PARAMETER => return Err(Error::Internal),
-                ERROR_NOT_ENOUGH_MEMORY => return Err(Error::Internal),
+                ERROR_INVALID_PARAMETER => return Err(Error::InvalidParameter),
+                ERROR_NOT_ENOUGH_MEMORY => return Err(Error::NotEnoughMemory),
                 ERROR_NO_DATA => return Ok(List(HashMap::new())), // there aren't any
                 ERROR_NO_DATA => return Ok(List(HashMap::new())), // there aren't any
-                _ => return Err(Error::Internal), // TODO: Use FormatMessage to get a string
+                _ => return Err(Error::UnexpectedWindowsResult(res)),
             }
         }
 
             }
         }
 
@@ -61,10 +61,10 @@ pub(crate) fn list_interfaces() -> Result<List, Error> {
             let mut hw_addr = String::with_capacity(adapter.PhysicalAddressLength as usize * 3);
             for i in 0..adapter.PhysicalAddressLength as usize {
                 if i != 0 {
             let mut hw_addr = String::with_capacity(adapter.PhysicalAddressLength as usize * 3);
             for i in 0..adapter.PhysicalAddressLength as usize {
                 if i != 0 {
-                    write!(hw_addr, ":").map_err(|_| Error::Internal)?;
+                    write!(hw_addr, ":").map_err(|_| Error::FormatMacAddress)?;
                 }
                 write!(hw_addr, "{:02X}", adapter.PhysicalAddress[i])
                 }
                 write!(hw_addr, "{:02X}", adapter.PhysicalAddress[i])
-                    .map_err(|_| Error::Internal)?;
+                    .map_err(|_| Error::FormatMacAddress)?;
             }
             let mut ips = vec![];
             let mut unicast_ptr = adapter.FirstUnicastAddress;
             }
             let mut ips = vec![];
             let mut unicast_ptr = adapter.FirstUnicastAddress;