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: trim Unexpected \0 in network interface name #111

Merged
merged 3 commits into from
Mar 12, 2023
Merged

fix: trim Unexpected \0 in network interface name #111

merged 3 commits into from
Mar 12, 2023

Conversation

bitcapybara
Copy link
Contributor

@bitcapybara bitcapybara commented Mar 9, 2023

fixes #110 :This pr tries to solve the problem raised by issue #110 ,all network interface names returned by the list_afinet_netifas() method contained an unexpected '\0', I try to use CStr to trim the '\0' of the suffix in this pr.

@LeoBorai LeoBorai changed the title fix issue #110: trim Unexpected '\0' in the network interface name. fix: trim Unexpected \0 in network interface name Mar 10, 2023
src/linux.rs Outdated
Comment on lines 368 to 378
fn parse_ifname(bytes: &[u8]) -> Result<String, Error> {
let ifname = CStr::from_bytes_with_nul(bytes)
.map_err(|_| {
Error::StrategyError(String::from(
"An error occurred convert interface name to string",
))
})?
.to_string_lossy()
.to_string();
Ok(ifname)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Looks good, can we have some unit tests on this please?
I believe by having:

  • Case where \0 instances are filtered
  • Case where text without \0 is not affected

Would be nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll add some more unit tests

@LeoBorai
Copy link
Owner

Thanks so much @bitcapybara!

@LeoBorai LeoBorai merged commit ffe73d0 into LeoBorai:main Mar 12, 2023
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.

Unexpected "\0" in the network interface name
2 participants