diff --git a/src/lib.rs b/src/lib.rs index 2327e20..7f071c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,7 +124,7 @@ pub fn local_ip() -> Result { ifas.into_iter() .find_map(|ifa| { - if !ifa.is_loopback && ifa.addr.is_ipv4() { + if !ifa.is_loopback && ifa.addr.is_ipv4() && !ifa.is_mobile_data() { Some(ifa.addr) } else { None @@ -196,7 +196,7 @@ pub fn local_ipv6() -> Result { ifas.into_iter() .find_map(|ifa| { - if !ifa.is_loopback && ifa.addr.is_ipv6() { + if !ifa.is_loopback && ifa.addr.is_ipv6() && !ifa.is_mobile_data() { Some(ifa.addr) } else { None diff --git a/src/unix.rs b/src/unix.rs index 109895c..4cc72ff 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -45,6 +45,13 @@ pub(crate) struct AfInetInfo { pub is_loopback: bool, } +impl AfInetInfo { + /// Determines if an interface is used for mobile_data + pub(crate) fn is_mobile_data(&self) -> bool { + self.iname.contains("rmnet_data") + } +} + // Internal method to list AF_INET info in a struct. This method is used by // list_afiinet_netifas and local_ip, pub(crate) fn list_afinet_netifas_info() -> Result, Error> {