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

Add support for SockAddr::Link when receiving packets #1344

Merged
merged 1 commit into from Jan 31, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- i686-apple-darwin has been demoted to Tier 2 support, because it's deprecated
by Xcode.
(#[1350](https://github.com/nix-rust/nix/pull/1350))
- Fixed calling `recvfrom` on an `AddrFamily::Packet` socket
(#[1344](https://github.com/nix-rust/nix/pull/1344))

### Removed

Expand Down
9 changes: 9 additions & 0 deletions src/sys/socket/mod.rs
Expand Up @@ -1702,6 +1702,15 @@ pub fn sockaddr_storage_to_addr(
Ok(SockAddr::Unix(UnixAddr(sun, pathlen)))
}
#[cfg(any(target_os = "android", target_os = "linux"))]
Copy link
Member

Choose a reason for hiding this comment

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

You can add fuchsia here.

Copy link
Member

Choose a reason for hiding this comment

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

Err, wait on that. Fuchsia support hasn't merged yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the Fuchsia's libc (being a based on a Musl fork) has the defines and structures, I don't think it actually supports raw packet sockets (based on a cursory glance of it's own API) and that they're really just relics of the fork. But given that it's in their libc might be enough of a reason to support it.

libc::AF_PACKET => {
use libc::sockaddr_ll;
assert_eq!(len as usize, mem::size_of::<sockaddr_ll>());
let sll = unsafe {
*(addr as *const _ as *const sockaddr_ll)
};
Ok(SockAddr::Link(LinkAddr(sll)))
}
#[cfg(any(target_os = "android", target_os = "linux"))]
libc::AF_NETLINK => {
use libc::sockaddr_nl;
let snl = unsafe {
Expand Down