diff --git a/examples/bind-shell/backdoor/src/main.rs b/examples/bind-shell/backdoor/src/main.rs index 59e2780..ed39d6c 100644 --- a/examples/bind-shell/backdoor/src/main.rs +++ b/examples/bind-shell/backdoor/src/main.rs @@ -59,7 +59,7 @@ async fn handled_main() -> anyhow::Result<()> { let mut interfaces = pcap_sys::PcapDevIterator::new()?; let interface_name = interfaces - .find(|eth| eth.starts_with("eth")) + .find(|eth| eth.starts_with("eth") || eth.starts_with("en")) .ok_or(anyhow!("Could not get an ethernet interface"))?; log::info!("Attaching to interface {}", &interface_name); diff --git a/nl-sys/src/netlink.rs b/nl-sys/src/netlink.rs index 8754f4b..814fec3 100644 --- a/nl-sys/src/netlink.rs +++ b/nl-sys/src/netlink.rs @@ -178,16 +178,22 @@ impl> Iterator for CacheIter<'_, T> { type Item = T; fn next(&mut self) -> Option { - if self.index >= self.cache_size || self.obj.is_null() { - return None; + loop { + if self.index >= self.cache_size { + return None; + } + + self.index += 1; + + let obj = self.obj; + self.obj = unsafe { nl_cache_get_next(obj) }; + + if obj.is_null() { + continue; + } + + break Some(T::from(obj)); } - - self.index += 1; - - let obj = self.obj; - self.obj = unsafe { nl_cache_get_next(obj) }; - - Some(T::from(obj)) } fn size_hint(&self) -> (usize, Option) { diff --git a/nl-sys/src/route.rs b/nl-sys/src/route.rs index 5a65537..f973b53 100644 --- a/nl-sys/src/route.rs +++ b/nl-sys/src/route.rs @@ -73,6 +73,9 @@ impl Link { pub fn name(&self) -> String { unsafe { let name = rtnl_link_get_name(self.link); + if name.is_null() { + return "".to_string(); + } let name_rs = CStr::from_ptr(name); std::str::from_utf8(name_rs.to_bytes()).unwrap().to_owned() } @@ -96,7 +99,7 @@ impl Link { return None; } let ltype_rs = CStr::from_ptr(ltype); - Some(std::str::from_utf8(ltype_rs.to_bytes()).unwrap().to_owned()) + Some(std::str::from_utf8(ltype_rs.to_bytes()).ok()?.to_owned()) } } @@ -196,8 +199,6 @@ pub fn get_macs_and_src_for_ip( let link = netlink::get_link_by_index(links, link_ind)?; - let neighs_ = neighs.iter().collect::>(); - let neigh = neighs .iter() .find(|n| n.ifindex() == link.ifindex())