Skip to content

Conversation

@mokeyish
Copy link

closes #36

@mokeyish mokeyish marked this pull request as draft July 10, 2025 16:49
@mokeyish mokeyish force-pushed the mac_addr branch 2 times, most recently from 8ad20c7 to e43c94b Compare July 11, 2025 11:15
@mokeyish mokeyish marked this pull request as ready for review July 11, 2025 11:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces custom string-based MAC address handling with the MacAddr type from the pnet_base crate.

  • Swapped out the hex module and HexSlice formatting for MacAddr::from conversions.
  • Updated Windows, Unix, and Linux target code to produce Option<MacAddr> rather than Option<String>.
  • Changed NetworkInterface.mac_addr to use Option<MacAddr> and re-exported MacAddr in lib.rs.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/utils/mod.rs Removed hex module import—no longer needed for MAC formatting
src/utils/hex.rs Deleted custom HexSlice formatter module
src/target/windows.rs Switched Windows MAC parsing to MacAddr, removed HexSlice
src/target/unix/mod.rs Updated Unix MAC parsing to return MacAddr instead of String
src/target/linux.rs Updated Linux MAC parsing to return MacAddr instead of String
src/lib.rs Re-exported MacAddr from the public API
src/interface.rs Changed mac_addr field and builder method to Option<MacAddr>
Cargo.toml Added mac_addr dependency (from pnet_base) and feature flags
Comments suppressed due to low confidence (4)

src/target/unix/mod.rs:123

  • [nitpick] The function name make_mac_addrs implies multiple addresses but returns a single MacAddr. Consider renaming it to make_mac_addr for clarity.
fn make_mac_addrs(netifa: &libc::ifaddrs) -> MacAddr {

src/target/linux.rs:123

  • [nitpick] The function name make_mac_addrs suggests multiple addresses but returns a single MacAddr; renaming to make_mac_addr would better reflect its purpose.
fn make_mac_addrs(netifa: &libc::ifaddrs) -> MacAddr {

src/target/unix/mod.rs:123

  • There aren’t any unit tests for the Unix make_mac_addrs conversion. Adding tests for this function would help ensure the MacAddr output remains correct across platforms.
fn make_mac_addrs(netifa: &libc::ifaddrs) -> MacAddr {

Cargo.toml:18

  • [nitpick] Consider marking the mac_addr dependency as optional (e.g., optional = true) or documenting its feature flag usage to avoid enlarging the default dependency footprint for consumers who don’t need it.
mac_addr = { package = "pnet_base", version = "0.35.0"} # It only contains the code for MacAddr.


/// Creates MacAddress from AdapterAddress
fn make_mac_address(adapter_address: &AdapterAddress) -> MacAddress {
fn make_mac_address(adapter_address: &AdapterAddress) -> Option<MacAddr> {
Copy link

Copilot AI Jul 13, 2025

Choose a reason for hiding this comment

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

The byte-to-MacAddr conversion logic is duplicated across Windows, Unix, and Linux modules. Consider extracting this into a shared utility function to reduce code duplication.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

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

@mokeyish what do you think about this? Do you believe we could centralize this utility?

@LeoBorai
Copy link
Owner

Hi @mokeyish! Thank you so much for your PR!

Copy link
Owner

@LeoBorai LeoBorai left a comment

Choose a reason for hiding this comment

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

Hi @mokeyish,

Overall the changes seems good, Im just wondering if we could have pnet_base being imported explicitly instead of using the package option. Im unsure if theres a benefit on importing crates like that.

Other than that the suggestion from Copilot seems ok to me, perhaps we could follow it and centralize the utility function?

Thank you in advance.

[dependencies]
serde = { version = "1.0.183", features = ["derive"], optional = true}
thiserror = "1.0"
mac_addr = { package = "pnet_base", version = "0.35.0"} # It only contains the code for MacAddr.
Copy link
Owner

Choose a reason for hiding this comment

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

@mokeyish I wonder how this differs from importing the crate as:

Suggested change
mac_addr = { package = "pnet_base", version = "0.35.0"} # It only contains the code for MacAddr.
pnet_base = "0.35"

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.

mac_addr should have its own type, instead of String

2 participants