socket9 0.1.0-alpha.1

Extended untilities for the networking/unix sockets and raw network sockets
Documentation
#[cfg(target_os = "linux")]
use libc::{IPPROTO_MPTCP, SOCK_SEQPACKET};

use socket9::{AF_INET, AF_INET6, AF_UNIX, IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_SCTP, IPPROTO_TCP, IPPROTO_UDP, So9MsgFlags, SOCK_DGRAM, SOCK_RAW, SOCK_STREAM, So9SockType, So9SockDomain, So9SockProtocol};

#[test]
fn test_sock_domain()
{
    assert_eq!(So9SockDomain::IPV4.0, AF_INET);
    assert_eq!(So9SockDomain::IPV6.0, AF_INET6);
    assert_eq!(So9SockDomain::UNIX.0, AF_UNIX);
} 

#[test]
fn test_type()
{
    assert_eq!(So9SockType::STREAM.0, SOCK_STREAM);
    assert_eq!(So9SockType::DGRAM.0, SOCK_DGRAM);
    #[cfg(unix)]
    assert_eq!(So9SockType::SEQPACKET.0, SOCK_SEQPACKET);
    assert_eq!(So9SockType::RAW.0, SOCK_RAW);
}

#[test]
fn test_domain()
{
    assert_eq!(So9SockProtocol::NONE.0, 0);
    assert_eq!(So9SockProtocol::ICMPV4.0, IPPROTO_ICMP);
    assert_eq!(So9SockProtocol::ICMPV6.0, IPPROTO_ICMPV6);
    assert_eq!(So9SockProtocol::TCP.0, IPPROTO_TCP);
    assert_eq!(So9SockProtocol::UDP.0, IPPROTO_UDP);

     #[cfg(target_os = "linux")]
    assert_eq!(So9SockProtocol::MPTCP.0, IPPROTO_MPTCP);

    assert_eq!(So9SockProtocol::SCTP.0, IPPROTO_SCTP);

    #[cfg(target_os = "linux")]
    assert_eq!(So9SockProtocol::DCCP.0, libc::IPPROTO_DCCP);
    #[cfg(unix)]
    assert_eq!(So9SockProtocol::UDPLITE.0, libc::IPPROTO_UDPLITE);

    #[cfg( any(target_os = "freebsd", target_os = "openbsd"))]
    assert_eq!(So9SockProtocol::DIVERT.0, libc::IPPROTO_DIVERT);
}

#[test]
fn test_sock_type()
{
    fn test_sock_type_int(s: So9SockType)
    {
        let st = So9SockType::from(s);

        assert_eq!(st.0, s.0);
    }
    

    test_sock_type_int(So9SockType::STREAM);
    test_sock_type_int(So9SockType::DGRAM);
    #[cfg(unix)]
    test_sock_type_int(So9SockType::SEQPACKET);
    test_sock_type_int(So9SockType::RAW);
}

#[test]
fn test_msg_flags()
{
    let msg = So9MsgFlags::MSG_TRUNC;

    assert_eq!(msg.intersects(So9MsgFlags::MSG_TRUNC), true);
    assert_eq!(msg.intersects(So9MsgFlags::MSG_CTRUNC), false);
    assert_eq!(msg.intersects(So9MsgFlags::MSG_ERRQUEUE), false);

    let msg = So9MsgFlags::MSG_TRUNC | So9MsgFlags::MSG_ERRQUEUE;

    assert_eq!(msg.intersects(So9MsgFlags::MSG_TRUNC), true);
    assert_eq!(msg.intersects(So9MsgFlags::MSG_CTRUNC), false);
    assert_eq!(msg.intersects(So9MsgFlags::MSG_ERRQUEUE), true);
}