socket9 0.1.0-alpha.1

Extended untilities for the networking/unix sockets and raw network sockets
Documentation
/// A socket `protocol`. Is optional on some OSes like
/// OSX. In this case it should be set to [SockProtocol::NONE].
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct So9SockProtocol(pub libc::c_int);

impl So9SockProtocol
{
    /// Unspecified or not available.
    pub const NONE: Self = Self(0);

    /// [libc::IPPROTO_ICMP] protocol
    pub const ICMPV4: Self = Self(libc::IPPROTO_ICMP);

    /// [libc::IPPROTO_ICMPV6] protocol
    pub const ICMPV6: Self = Self(libc::IPPROTO_ICMPV6);

    /// [libc::IPPROTO_TCP] protocol
    pub const TCP: Self = Self(libc::IPPROTO_TCP);

    /// [libc::IPPROTO_UDP] protocol
    pub const UDP: Self = Self(libc::IPPROTO_UDP);

    /// [libc::IPPROTO_MPTCP] protocol
    #[cfg(target_os = "linux")]
    pub const MPTCP: Self = Self(libc::IPPROTO_MPTCP);

    /// [libc::IPPROTO_SCTP] protocol
    pub const SCTP: Self = Self(libc::IPPROTO_SCTP);

    /// [libc::IPPROTO_DCCP] protocol
    #[cfg(target_os = "linux")]
    pub const DCCP: Self = Self(libc::IPPROTO_DCCP);

    /// [libc::IPPROTO_UDPLITE] protocol
    pub const UDPLITE: Self = Self(libc::IPPROTO_UDPLITE);

    /// [libc::IPPROTO_DIVERT] protocol
    #[cfg( any(target_os = "freebsd", target_os = "openbsd"))]
    pub const DIVERT: Self = Self(libc::IPPROTO_DIVERT);
}

#[cfg(target_family = "windows")]
impl From<WSAPROTOCOL_INFOW> for So9SockProtocol
{
    fn from(value: WSAPROTOCOL_INFOW) -> Self 
    {
        Self(value.iProtocol)
    }
}

#[cfg(target_family = "unix")]
impl From<libc::c_int> for So9SockProtocol
{
    fn from(value: libc::c_int) -> Self 
    {
        Self(value)
    }
}