pub struct MnlSocket { /* private fields */ }Implementations§
Source§impl MnlSocket
impl MnlSocket
Sourcepub fn mnl_socket_open(bus: i32) -> NtflRes<Self>
pub fn mnl_socket_open(bus: i32) -> NtflRes<Self>
mnl_socket_open - open a netlink socket
§Arguments
bus- bus the netlink socket bus ID (see NETLINK_* constants)
§Returns
A Result is retuened which has alias NtflRes.
-
Result::Ok is returned with valid instance.
-
Result::Err is returned with error description.
pub fn mnl_socket_bind(&mut self, groups: u32, pid: pid_t) -> NtflRes<()>
Sourcepub fn mnl_socket_get_portid(&self) -> u32
pub fn mnl_socket_get_portid(&self) -> u32
mnl_socket_get_portid - obtain Netlink PortID from netlink socket
Copypaste from libmnl: This function returns the Netlink PortID of a given netlink socket. It’s a common mistake to assume that this PortID equals the process ID which is not always true. This is the case if you open more than one socket that is binded to the same Netlink subsystem from the same process.
Sourcepub fn mnl_socket_sendto(&self, buf: &[u8], len: usize) -> NtflRes<isize>
pub fn mnl_socket_sendto(&self, buf: &[u8], len: usize) -> NtflRes<isize>
mnl_socket_sendto - send a netlink message of a certain size
§Arguments
buf- buffer containing the netlink message to be sentlen- number of bytes in the buffer that you want to send
§Result
A Result is retuened which has alias NtflRes.
-
Result::Ok is returned a number of written bytes
-
Result::Err is returned with error description.
Sourcepub fn mnl_socket_recvfrom(&self, bufsiz: usize) -> NtflRes<Vec<u8>>
pub fn mnl_socket_recvfrom(&self, bufsiz: usize) -> NtflRes<Vec<u8>>
mnl_socket_recvfrom - receive a netlink message \param nl netlink socket obtained via mnl_socket_open() \param buf buffer that you want to use to store the netlink message \param bufsiz size of the buffer passed to store the netlink message
On error, it returns -1 and errno is appropriately set. If errno is set to ENOSPC, it means that the buffer that you have passed to store the netlink message is too small, so you have received a truncated message. To avoid this, you have to allocate a buffer of MNL_SOCKET_BUFFER_SIZE (which is 8KB, see linux/netlink.h for more information). Using this buffer size ensures that your buffer is big enough to store the netlink message without truncating it.