Struct NlSocket

Source
pub struct NlSocket { /* private fields */ }
Expand description

Low level access to a netlink socket.

Implementations§

Source§

impl NlSocket

Source

pub fn new(proto: NlFamily) -> Result<Self, Error>

Wrapper around socket() syscall filling in the netlink-specific information.

Source

pub fn connect( proto: NlFamily, pid: Option<u32>, groups: &[u32], ) -> Result<Self, Error>

Equivalent of socket and bind calls.

Source

pub fn block(&self) -> Result<(), Error>

Set underlying socket file descriptor to be blocking.

Source

pub fn nonblock(&self) -> Result<(), Error>

Set underlying socket file descriptor to be non blocking.

Source

pub fn is_blocking(&self) -> Result<bool, Error>

Determines if underlying file descriptor is blocking.

Source

pub fn bind(&self, pid: Option<u32>, groups: &[u32]) -> Result<(), Error>

Use this function to bind to a netlink ID and subscribe to groups. See netlink(7) man pages for more information on netlink IDs and groups.

Source

pub fn add_mcast_membership(&self, groups: &[u32]) -> Result<(), Error>

Join multicast groups for a socket.

Source

pub fn drop_mcast_membership(&self, groups: &[u32]) -> Result<(), Error>

Leave multicast groups for a socket.

Source

pub fn list_mcast_membership(&self) -> Result<NetlinkBitArray, Error>

List joined groups for a socket.

Source

pub fn send<B>(&self, buf: B, flags: i32) -> Result<size_t, Error>
where B: AsRef<[u8]>,

Send message encoded as byte slice to the netlink ID specified in the netlink header Nlmsghdr.

Source

pub fn recv<B>(&self, buf: B, flags: i32) -> Result<size_t, Error>
where B: AsMut<[u8]>,

Receive message encoded as byte slice from the netlink socket.

Source

pub fn pid(&self) -> Result<u32, Error>

Get the PID for this socket.

Trait Implementations§

Source§

impl AsRawFd for NlSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Drop for NlSocket

Source§

fn drop(&mut self)

Closes underlying file descriptor to avoid file descriptor leaks.

Source§

impl From<NlSocketHandle> for NlSocket

Source§

fn from(s: NlSocketHandle) -> Self

Converts to this type from the input type.
Source§

impl FromRawFd for NlSocket

Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl IntoRawFd for NlSocket

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.