pub struct NlSocket { /* private fields */ }
Expand description
Low level access to a netlink socket.
Implementations§
Source§impl NlSocket
impl NlSocket
Sourcepub fn new(proto: NlFamily) -> Result<Self, Error>
pub fn new(proto: NlFamily) -> Result<Self, Error>
Wrapper around socket()
syscall filling in the
netlink-specific information.
Sourcepub fn connect(
proto: NlFamily,
pid: Option<u32>,
groups: Groups,
) -> Result<Self, Error>
pub fn connect( proto: NlFamily, pid: Option<u32>, groups: Groups, ) -> Result<Self, Error>
Equivalent of socket
and bind
calls.
Sourcepub fn nonblock(&self) -> Result<(), Error>
pub fn nonblock(&self) -> Result<(), Error>
Set underlying socket file descriptor to be non blocking.
Sourcepub fn is_blocking(&self) -> Result<bool, Error>
pub fn is_blocking(&self) -> Result<bool, Error>
Determines if underlying file descriptor is blocking.
Sourcepub fn bind(&self, pid: Option<u32>, groups: Groups) -> Result<(), Error>
pub fn bind(&self, pid: Option<u32>, groups: Groups) -> 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.
Sourcepub fn set_recv_buffer_size(&self, size: usize) -> Result<(), Error>
pub fn set_recv_buffer_size(&self, size: usize) -> Result<(), Error>
Set the size of the receive buffer for the socket.
This can be useful when communicating with a service that sends a high volume of messages (especially multicast), and your application cannot process them fast enough, leading to the kernel dropping messages. A larger buffer may help mitigate this.
The value passed is a hint to the kernel to set the size of the receive buffer.
The kernel will double the value provided to account for bookkeeping overhead.
The doubled value is capped by the value in /proc/sys/net/core/rmem_max
.
The default value is /proc/sys/net/core/rmem_default
See socket(7)
documentation for SO_RCVBUF
for more information.
Sourcepub fn add_mcast_membership(&self, groups: Groups) -> Result<(), Error>
pub fn add_mcast_membership(&self, groups: Groups) -> Result<(), Error>
Join multicast groups for a socket.
Sourcepub fn drop_mcast_membership(&self, groups: Groups) -> Result<(), Error>
pub fn drop_mcast_membership(&self, groups: Groups) -> Result<(), Error>
Leave multicast groups for a socket.
Sourcepub fn list_mcast_membership(&self) -> Result<NetlinkBitArray, Error>
pub fn list_mcast_membership(&self) -> Result<NetlinkBitArray, Error>
List joined groups for a socket.
Sourcepub fn send<B>(&self, buf: B, flags: Msg) -> Result<size_t, Error>
pub fn send<B>(&self, buf: B, flags: Msg) -> Result<size_t, Error>
Send message encoded as byte slice to the netlink ID
specified in the netlink header
Nlmsghdr
Sourcepub fn recv<B>(&self, buf: B, flags: Msg) -> Result<(size_t, Groups), Error>
pub fn recv<B>(&self, buf: B, flags: Msg) -> Result<(size_t, Groups), Error>
Receive message encoded as byte slice from the netlink socket.
Sourcepub fn get_ext_ack_enabled(&self) -> Result<bool, Error>
pub fn get_ext_ack_enabled(&self) -> Result<bool, Error>
Return true
if an extended ACK is enabled for this socket.