#[cfg(unix)]
use libc as c;
#[cfg(windows)]
use windows_sys::Win32::Networking::WinSock as c;
#[allow(non_camel_case_types)]
type c_int = i32;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum SockType {
Stream,
DGram,
#[cfg(not(target_os = "redox"))]
Raw,
#[cfg(not(target_os = "redox"))]
RDM,
}
impl From<SockType> for c_int {
fn from(sock: SockType) -> c_int {
(match sock {
SockType::Stream => c::SOCK_STREAM,
SockType::DGram => c::SOCK_DGRAM,
#[cfg(not(target_os = "redox"))]
SockType::Raw => c::SOCK_RAW,
#[cfg(not(target_os = "redox"))]
SockType::RDM => c::SOCK_RDM,
})
.into()
}
}
impl PartialEq<c_int> for SockType {
fn eq(&self, other: &c_int) -> bool {
let int: c_int = (*self).into();
*other == int
}
}
impl PartialEq<SockType> for c_int {
fn eq(&self, other: &SockType) -> bool {
let int: c_int = (*other).into();
*self == int
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Protocol {
ICMP,
TCP,
UDP,
}
impl From<Protocol> for c_int {
fn from(sock: Protocol) -> c_int {
(match sock {
Protocol::ICMP => c::IPPROTO_ICMP,
Protocol::TCP => c::IPPROTO_TCP,
Protocol::UDP => c::IPPROTO_UDP,
})
.into()
}
}
impl PartialEq<c_int> for Protocol {
fn eq(&self, other: &c_int) -> bool {
let int: c_int = (*self).into();
*other == int
}
}
impl PartialEq<Protocol> for c_int {
fn eq(&self, other: &Protocol) -> bool {
let int: c_int = (*other).into();
*self == int
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AddrFamily {
Unix,
Inet,
Inet6,
}
impl From<AddrFamily> for c_int {
fn from(sock: AddrFamily) -> c_int {
(match sock {
AddrFamily::Unix => c::AF_UNIX,
AddrFamily::Inet => c::AF_INET,
AddrFamily::Inet6 => c::AF_INET6,
})
.into()
}
}
impl PartialEq<c_int> for AddrFamily {
fn eq(&self, other: &c_int) -> bool {
let int: c_int = (*self).into();
*other == int
}
}
impl PartialEq<AddrFamily> for c_int {
fn eq(&self, other: &AddrFamily) -> bool {
let int: c_int = (*other).into();
*self == int
}
}