ferranet 0.1.0

A modern, async-first, zero-copy datalink-layer (L2) networking library
Documentation
//! Error and result types for `ferranet`.

use std::io;

/// The result type returned by fallible `ferranet` operations.
pub type Result<T> = std::result::Result<T, Error>;

/// Errors that can occur while opening or operating a datalink channel.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    /// The named network interface could not be found.
    #[error("network interface {0:?} not found")]
    InterfaceNotFound(String),

    /// Creating the underlying `AF_PACKET` socket failed.
    ///
    /// Commonly caused by missing `CAP_NET_RAW`; see the crate-level docs on permissions.
    #[error("failed to open packet socket: {0}")]
    Socket(#[source] io::Error),

    /// Binding the socket to an interface failed.
    #[error("failed to bind packet socket to interface: {0}")]
    Bind(#[source] io::Error),

    /// Setting a socket option failed.
    #[error("failed to set socket option {option}: {source}")]
    SetSockOpt {
        /// The name of the option that could not be set.
        option: &'static str,
        /// The underlying OS error.
        #[source]
        source: io::Error,
    },

    /// Mapping the `PACKET_MMAP` ring buffer failed.
    #[error("failed to mmap packet ring: {0}")]
    Mmap(#[source] io::Error),

    /// A frame submitted for transmission exceeds the configured frame size.
    #[error("frame of {len} bytes exceeds maximum frame size of {max} bytes")]
    FrameTooLarge {
        /// The length of the offending frame.
        len: usize,
        /// The maximum permitted frame length.
        max: usize,
    },

    /// The supplied channel/ring configuration is invalid.
    #[error("invalid channel configuration: {0}")]
    InvalidConfig(&'static str),

    /// A general I/O error not covered by a more specific variant.
    #[error(transparent)]
    Io(#[from] io::Error),
}