socket set_mark addition.
to be able to set a marker/id on the socket for network filtering (iptables/ipfw here) purpose.
This commit is contained in:
parent
5fb8a39266
commit
14d288fe12
2 changed files with 16 additions and 0 deletions
|
|
@ -424,6 +424,12 @@ impl UnixStream {
|
|||
self.0.passcred()
|
||||
}
|
||||
|
||||
#[cfg(any(doc, target_os = "linux", target_os = "freebsd",))]
|
||||
#[unstable(feature = "unix_set_mark", issue = "none")]
|
||||
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
|
||||
self.0.set_mark(mark)
|
||||
}
|
||||
|
||||
/// Returns the value of the `SO_ERROR` option.
|
||||
///
|
||||
/// # Examples
|
||||
|
|
|
|||
|
|
@ -427,6 +427,16 @@ impl Socket {
|
|||
self.0.set_nonblocking(nonblocking)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
|
||||
setsockopt(self, libc::SOL_SOCKET, libc::SO_MARK, mark as libc::c_int)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
|
||||
setsockopt(self, libc::SOL_SOCKET, libc::SO_USER_COOKIE, mark)
|
||||
}
|
||||
|
||||
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
||||
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
|
||||
if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue