From ee40f7fafe373feca724f2078d0d54943d5a4ac5 Mon Sep 17 00:00:00 2001 From: Alex Krob Date: Fri, 2 Jul 2021 15:02:09 -0700 Subject: [PATCH] Fixes the issue referenced in https://github.com/EstebanBorai/local-ip-address/issues/10 This issue was causing the Linux flavor of local-ip-address to not compile due to a system value being cast to a *const i8 as opposed to a *const u8. A very helpful suggestion from @EstebanBorai both accomplishes compilation on raspberry pi and keeps other Linux flavors from breaking. --- src/linux.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index 0dcf5f8..f8e2ce4 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -195,10 +195,11 @@ pub fn list_afinet_netifas() -> Result, Error> { } /// Retrieves the name of a interface address -unsafe fn get_ifa_name(ifa: *mut *mut ifaddrs) -> Result { - let str = (*(*ifa)).ifa_name as *mut u8; - let len = strlen(str as *const i8); - let slice = std::slice::from_raw_parts(str, len); +fn get_ifa_name(ifa: *mut *mut ifaddrs) -> Result { + let str = unsafe { (*(*ifa)).ifa_name as *const libc::c_char }; + let len = unsafe { strlen(str) }; + let slice = unsafe { std::slice::from_raw_parts(str as *const u8, len) }; + match String::from_utf8(slice.to_vec()) { Ok(s) => Ok(s), Err(e) => Err(Error::StrategyError(format!(