summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--src/sys/socket/addr.rs27
2 files changed, 32 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89f2b268..9f40e408 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 6d38f26c..8de501a4 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -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",
@@ -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"
))]