Skip to content

Commit

Permalink
Fixes the issue referenced in #10
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexkrob authored and EstebanBorai committed Jul 7, 2021
1 parent 95f613d commit ee40f7f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ pub fn list_afinet_netifas() -> Result<Vec<(String, IpAddr)>, Error> {
}

/// Retrieves the name of a interface address
unsafe fn get_ifa_name(ifa: *mut *mut ifaddrs) -> Result<String, Error> {
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<String, Error> {
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!(
Expand Down

0 comments on commit ee40f7f

Please sign in to comment.