Struct neli::socket::NlSocketHandle
source · pub struct NlSocketHandle { /* private fields */ }
Expand description
Higher level handle for socket operations.
Implementations§
source§impl NlSocketHandle
impl NlSocketHandle
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: &[u32]
) -> Result<Self, Error>
pub fn connect(
proto: NlFamily,
pid: Option<u32>,
groups: &[u32]
) -> 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: &[u32]) -> Result<(), Error>
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.
sourcepub fn add_mcast_membership(&self, groups: &[u32]) -> Result<(), Error>
pub fn add_mcast_membership(&self, groups: &[u32]) -> Result<(), Error>
Join multicast groups for a socket.
sourcepub fn drop_mcast_membership(&self, groups: &[u32]) -> Result<(), Error>
pub fn drop_mcast_membership(&self, groups: &[u32]) -> 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 resolve_genl_family(
&mut self,
family_name: &str
) -> Result<u16, NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>>
pub fn resolve_genl_family(
&mut self,
family_name: &str
) -> Result<u16, NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>>
Convenience function for resolving a str
containing the
generic netlink family name to a numeric generic netlink ID.
sourcepub fn resolve_nl_mcast_group(
&mut self,
family_name: &str,
mcast_name: &str
) -> Result<u32, NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>>
pub fn resolve_nl_mcast_group(
&mut self,
family_name: &str,
mcast_name: &str
) -> Result<u32, NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>>
Convenience function for resolving a str
containing the
multicast group name to a numeric multicast group ID.
sourcepub fn lookup_id(
&mut self,
id: u32
) -> Result<(String, String), NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>>
pub fn lookup_id(
&mut self,
id: u32
) -> Result<(String, String), NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>>
Look up netlink family and multicast group name by ID.
sourcepub fn send<T, P>(&mut self, msg: Nlmsghdr<T, P>) -> Result<(), SerError>where
T: NlType + Debug,
P: ToBytes + Debug,
pub fn send<T, P>(&mut self, msg: Nlmsghdr<T, P>) -> Result<(), SerError>where
T: NlType + Debug,
P: ToBytes + Debug,
Convenience function to send an Nlmsghdr
struct
sourcepub fn recv<'a, T, P>(
&'a mut self
) -> Result<Option<Nlmsghdr<T, P>>, NlError<T, P>>where
T: NlType + Debug,
P: FromBytesWithInput<'a, Input = usize> + Debug,
pub fn recv<'a, T, P>(
&'a mut self
) -> Result<Option<Nlmsghdr<T, P>>, NlError<T, P>>where
T: NlType + Debug,
P: FromBytesWithInput<'a, Input = usize> + Debug,
Convenience function to read a stream of
Nlmsghdr
structs one by one.
Use NlSocketHandle::iter
instead for easy iteration over
returned packets.
Returns None
only in non-blocking contexts if no
message can be immediately returned or if the socket
has been closed.
sourcepub fn recv_all<'a, T, P>(&'a mut self) -> Result<NlBuffer<T, P>, NlError>where
T: NlType + Debug,
P: FromBytesWithInput<'a, Input = usize> + Debug,
pub fn recv_all<'a, T, P>(&'a mut self) -> Result<NlBuffer<T, P>, NlError>where
T: NlType + Debug,
P: FromBytesWithInput<'a, Input = usize> + Debug,
Parse all Nlmsghdr
structs sent in
one network packet and return them all in a list.
Failure to parse any packet will cause the entire operation
to fail. If an error is detected at the application level,
this method will discard any non-error
Nlmsghdr
structs and only return the
error. This method checks for ACKs. For a more granular
approach, use either NlSocketHandle::recv
or
NlSocketHandle::iter
.
sourcepub fn iter<'a, T, P>(
&'a mut self,
iter_indefinitely: bool
) -> NlMessageIter<'a, T, P> ⓘwhere
T: NlType + Debug,
P: FromBytesWithInput<'a, Input = usize> + Debug,
pub fn iter<'a, T, P>(
&'a mut self,
iter_indefinitely: bool
) -> NlMessageIter<'a, T, P> ⓘwhere
T: NlType + Debug,
P: FromBytesWithInput<'a, Input = usize> + Debug,
Return an iterator object
The argument iterate_indefinitely
is documented
in more detail in NlMessageIter
Trait Implementations§
source§impl AsRawFd for NlSocketHandle
impl AsRawFd for NlSocketHandle
source§impl From<NlSocketHandle> for NlSocket
impl From<NlSocketHandle> for NlSocket
source§fn from(s: NlSocketHandle) -> Self
fn from(s: NlSocketHandle) -> Self
source§impl FromRawFd for NlSocketHandle
impl FromRawFd for NlSocketHandle
source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self
from the given raw file
descriptor. Read more