diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/sys/socket/sockopt.rs | 22 |
2 files changed, 24 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 058384f8..7c7b9d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- Added `SO_MARK` on Linux. +- ([#873](https://github.com/nix-rust/nix/pull/873)) - Added `getsid` in `::nix::unistd` ([#850](https://github.com/nix-rust/nix/pull/850)) - Added `alarm`. ([#830](https://github.com/nix-rust/nix/pull/830)) diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 424d7557..cbfd9249 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -253,6 +253,8 @@ sockopt_impl!(Both, IpTransparent, libc::SOL_IP, libc::IP_TRANSPARENT, bool); sockopt_impl!(Both, BindAny, libc::SOL_SOCKET, libc::SO_BINDANY, bool); #[cfg(target_os = "freebsd")] sockopt_impl!(Both, BindAny, libc::IPPROTO_IP, libc::IP_BINDANY, bool); +#[cfg(target_os = "linux")] +sockopt_impl!(Both, Mark, libc::SOL_SOCKET, libc::SO_MARK, u32); /* * @@ -527,4 +529,24 @@ mod test { assert!(s_listening2); close(s).unwrap(); } + + #[cfg(target_os = "linux")] + #[test] + fn is_so_mark_functional() { + use super::super::*; + use ::unistd::Uid; + use ::std::io::{self, Write}; + + if !Uid::current().is_root() { + let stderr = io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "SO_MARK requires root privileges. Skipping test.").unwrap(); + return; + } + + let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), None).unwrap(); + setsockopt(s, super::Mark, &1337).unwrap(); + let mark = getsockopt(s, super::Mark).unwrap(); + assert_eq!(mark, 1337); + } } |