Skip to content

Commit 48ef00e

Browse files
committed
doc additions
1 parent 14d288f commit 48ef00e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

library/std/src/os/unix/net/datagram.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,25 @@ impl UnixDatagram {
838838
self.0.passcred()
839839
}
840840

841+
/// Set the id of the socket for network filtering purpose
842+
/// and is only a setter.
843+
///
844+
/// ```no_run
845+
/// #![feature(unix_set_mark)]
846+
/// use std::os::unix::net::UnixDatagram;
847+
///
848+
/// fn main() -> std::io::Result<()> {
849+
/// let sock = UnixDatagram::unbound()?;
850+
/// sock.set_mark(32 as u32).expect("set_mark function failed");
851+
/// Ok(())
852+
/// }
853+
/// ```
854+
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
855+
#[unstable(feature = "unix_set_mark", issue = "none")]
856+
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
857+
self.0.set_mark(mark)
858+
}
859+
841860
/// Returns the value of the `SO_ERROR` option.
842861
///
843862
/// # Examples

library/std/src/os/unix/net/stream.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,20 @@ impl UnixStream {
424424
self.0.passcred()
425425
}
426426

427-
#[cfg(any(doc, target_os = "linux", target_os = "freebsd",))]
427+
/// Set the id of the socket for network filtering purpose
428+
/// and is only a setter.
429+
///
430+
/// ```no_run
431+
/// #![feature(unix_set_mark)]
432+
/// use std::os::unix::net::UnixStream;
433+
///
434+
/// fn main() -> std::io::Result<()> {
435+
/// let sock = UnixStream::connect("/tmp/sock")?;
436+
/// sock.set_mark(32 as u32).expect("set_mark function failed");
437+
/// Ok(())
438+
/// }
439+
/// ```
440+
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
428441
#[unstable(feature = "unix_set_mark", issue = "none")]
429442
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
430443
self.0.set_mark(mark)

library/std/src/sys/unix/net.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ impl Socket {
437437
setsockopt(self, libc::SOL_SOCKET, libc::SO_USER_COOKIE, mark)
438438
}
439439

440+
#[cfg(target_os = "openbsd")]
441+
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
442+
setsockopt(self, libc::SOL_SOCKET, libc::SO_RTABLE, mark as libc::c_int)
443+
}
444+
440445
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
441446
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
442447
if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) }

0 commit comments

Comments
 (0)