Skip to content

fix(unix): prevent mobile data interface #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn local_ip() -> Result<IpAddr, Error> {

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
Expand Down Expand Up @@ -196,7 +196,7 @@ pub fn local_ipv6() -> Result<IpAddr, Error> {

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
Expand Down
7 changes: 7 additions & 0 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<AfInetInfo>, Error> {
Expand Down