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

No way to obtain a LinkAddr on Linux #1728

Closed
rotty opened this issue May 31, 2022 · 1 comment · Fixed by #1729
Closed

No way to obtain a LinkAddr on Linux #1728

rotty opened this issue May 31, 2022 · 1 comment · Fixed by #1729

Comments

@rotty
Copy link

rotty commented May 31, 2022

On Linux, there is no method SockaddrStorage::as_link_addr, so it is not possible to obtain a MAC address for an interface using safe Rust. I cooked up the following, which seems to work, but it feels like this should be possible using only safe code:

fn sockaddr_link(sockaddr: &SockaddrStorage) -> Option<LinkAddr> {
    if let Some(AddressFamily::Packet) = sockaddr.family() {
        // Safety: Checked the address family
        unsafe { LinkAddr::from_raw(sockaddr.as_ptr(), None) }
    } else {
        None
    }
}
@asomers
Copy link
Member

asomers commented May 31, 2022

That's an oversight. Thanks for pointing it out.

asomers added a commit to asomers/nix that referenced this issue May 31, 2022
bors bot added a commit that referenced this issue May 31, 2022
1729: Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux. r=rtzoeller a=asomers

This was an oversight from #1684.

Fixes #1728

Co-authored-by: Alan Somers <asomers@gmail.com>
@bors bors bot closed this as completed in 1520d7b Jun 1, 2022
rtzoeller pushed a commit to rtzoeller/nix that referenced this issue Jul 17, 2022
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 a pull request may close this issue.

2 participants