#![no_std]
#![deny(missing_docs)]
extern crate alloc;
mod xsk;
pub use xsk::{
BufIdx, CompletionQueue, DeviceQueue, FillQueue, IfInfo, ReadComplete, ReadRx, RingCons,
RingProd, RingRx, RingTx, Socket, SocketConfig, Umem, UmemChunk, UmemConfig, User, WriteFill,
WriteTx,
};
pub mod xdp;
pub(crate) struct LastErrno;
#[allow(clippy::new_without_default)]
pub struct Errno(libc::c_int);
impl From<LastErrno> for Errno {
fn from(LastErrno: LastErrno) -> Self {
Errno::last_os_error()
}
}
impl Errno {
#[deprecated = "use the more descriptive name `Errno::last_os_error`"]
#[doc(hidden)]
pub fn new() -> Self {
Self::last_os_error()
}
pub fn last_os_error() -> Self {
Errno(unsafe { *libc::__errno_location() })
}
pub fn get_raw(&self) -> libc::c_int {
self.0
}
}
impl core::fmt::Display for Errno {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let st = unsafe { libc::strerror(self.0) };
let cstr = unsafe { core::ffi::CStr::from_ptr(st) };
write!(f, "{}", cstr.to_string_lossy())
}
}
impl core::fmt::Debug for Errno {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Errno({}: {})", self.0, self)
}
}