Skip to content
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

fix(linux): can't get local ip address with libc::ENETUNREACH error #136

Merged
merged 4 commits into from
Feb 25, 2024

Conversation

jsydliuqing
Copy link
Contributor

Fix(linux): can not get local ip address when the network namespace without default route
#135

src/linux.rs Outdated
@@ -158,6 +158,16 @@ fn local_ip_impl(family: RtAddrFamily) -> Result<IpAddr, Error> {
let mut netlink_socket = NlSocketHandle::connect(NlFamily::Route, None, &[])
.map_err(|err| Error::StrategyError(err.to_string()))?;

match local_ip_impl_route(family, &mut netlink_socket) {
Ok(ip_addr) => Ok(ip_addr),
Err(_error) => local_ip_impl_addr(family, &mut netlink_socket),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check here for the error to be "LocalIpAddressNotFound"? That way we have a controlled flow for the fallback, allowing us to reduce ambiguity.

Suggested change
Err(_error) => local_ip_impl_addr(family, &mut netlink_socket),
Err(error) if error == Error::LocalIpAddressNotFound => local_ip_impl_addr(family, &mut netlink_socket),
Err(e) => Err(e)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's better!

Copy link
Owner

@EstebanBorai EstebanBorai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work @jsydliuqing!

@EstebanBorai
Copy link
Owner

@jsydliuqing can you please run cargo clippy to fix fmt issues please?

Copy link
Owner

@EstebanBorai EstebanBorai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @jsydliuqing! Thanks so much!

@EstebanBorai EstebanBorai merged commit 56bd1bf into EstebanBorai:main Feb 25, 2024
25 checks passed
@jsydliuqing
Copy link
Contributor Author

Hi @EstebanBorai !
When will the next new version be released? I will use it in my project.

@EstebanBorai
Copy link
Owner

Hi @EstebanBorai !

When will the next new version be released? I will use it in my project.

Hey @jsydliuqing! I can do it in a couple hours!

@EstebanBorai
Copy link
Owner

EstebanBorai commented Feb 25, 2024

Hi @jsydliuqing! Here is the version containing your PR changes: https://crates.io/crates/local-ip-address/0.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants