Skip to content

Commit

Permalink
Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux.
Browse files Browse the repository at this point in the history
This was an oversight from nix-rust#1684.

Fixes nix-rust#1728
  • Loading branch information
asomers committed May 31, 2022
1 parent 7e8757f commit 1520d7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(#[1713](https://github.com/nix-rust/nix/pull/1713))

### Fixed

- Enabled `SockaddrStorage::{as_link_addr, as_link_addr_mut}` for Linux-like
operating systems.
(#[1729](https://github.com/nix-rust/nix/pull/1729))

### Removed

- Removed support for resubmitting partially complete `lio_listio` operations.
Expand Down
27 changes: 27 additions & 0 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,14 @@ impl SockaddrStorage {
accessors!{as_alg_addr, as_alg_addr_mut, AlgAddr,
AddressFamily::Alg, libc::sockaddr_alg, alg}

#[cfg(any(target_os = "android",
target_os = "fuchsia",
target_os = "linux"))]
#[cfg(feature = "net")]
accessors!{
as_link_addr, as_link_addr_mut, LinkAddr,
AddressFamily::Packet, libc::sockaddr_ll, dl}

#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
Expand Down Expand Up @@ -2682,6 +2690,25 @@ mod tests {
format!("{}", la);
}

#[cfg(all(
any(target_os = "android",
target_os = "fuchsia",
target_os = "linux"),
target_endian = "little"
))]
#[test]
fn linux_loopback() {
let bytes = [17u8, 0, 0, 0, 1, 0, 0, 0, 4, 3, 0, 6, 1, 2, 3, 4, 5, 6, 0, 0];
let sa = bytes.as_ptr() as *const libc::sockaddr;
let len = None;
let sock_addr = unsafe { SockaddrStorage::from_raw(sa, len) }.unwrap();
assert_eq!(sock_addr.family(), Some(AddressFamily::Packet));
match sock_addr.as_link_addr() {
Some(dl) => assert_eq!(dl.addr(), Some([1, 2, 3, 4, 5, 6])),
None => panic!("Can't unwrap sockaddr storage")
}
}

#[cfg(any(target_os = "ios",
target_os = "macos"
))]
Expand Down

0 comments on commit 1520d7b

Please sign in to comment.