| 1 |
#[cfg(unix)] |
| 2 |
use libc::c_int; |
| 3 |
#[cfg(unix)] |
| 4 |
use libc as c; |
| 5 |
|
| 6 |
#[cfg(windows)] |
| 7 |
use winapi::ctypes::c_int; |
| 8 |
#[cfg(windows)] |
| 9 |
use winapi::shared::ws2def as c; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#[derive(Copy, Clone, Debug, PartialEq)] |
| 16 |
pub enum SockType { |
| 17 |
|
| 18 |
Stream, |
| 19 |
|
| 20 |
DGram, |
| 21 |
|
| 22 |
#[cfg(not(target_os = "redox"))] |
| 23 |
Raw, |
| 24 |
|
| 25 |
#[cfg(not(target_os = "redox"))] |
| 26 |
RDM, |
| 27 |
} |
| 28 |
|
| 29 |
impl From<SockType> for c_int { |
| 30 |
fn from(sock: SockType) -> c_int { |
| 31 |
match sock { |
| 32 |
SockType::Stream => c::SOCK_STREAM, |
| 33 |
SockType::DGram => c::SOCK_DGRAM, |
| 34 |
#[cfg(not(target_os = "redox"))] |
| 35 |
SockType::Raw => c::SOCK_RAW, |
| 36 |
#[cfg(not(target_os = "redox"))] |
| 37 |
SockType::RDM => c::SOCK_RDM, |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
impl PartialEq<c_int> for SockType { |
| 43 |
fn eq(&self, other: &c_int) -> bool { |
| 44 |
let int: c_int = (*self).into(); |
| 45 |
*other == int |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
impl PartialEq<SockType> for c_int { |
| 50 |
fn eq(&self, other: &SockType) -> bool { |
| 51 |
let int: c_int = (*other).into(); |
| 52 |
*self == int |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
#[derive(Copy, Clone, Debug, PartialEq)] |
| 61 |
pub enum Protocol { |
| 62 |
|
| 63 |
ICMP, |
| 64 |
|
| 65 |
TCP, |
| 66 |
|
| 67 |
UDP, |
| 68 |
} |
| 69 |
|
| 70 |
impl From<Protocol> for c_int { |
| 71 |
#[cfg(unix)] |
| 72 |
fn from(sock: Protocol) -> c_int { |
| 73 |
match sock { |
| 74 |
Protocol::ICMP => c::IPPROTO_ICMP, |
| 75 |
Protocol::TCP => c::IPPROTO_TCP, |
| 76 |
Protocol::UDP => c::IPPROTO_UDP, |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
#[cfg(windows)] |
| 81 |
fn from(sock: Protocol) -> c_int { |
| 82 |
match sock { |
| 83 |
Protocol::ICMP => c::IPPROTO_ICMP as c_int, |
| 84 |
Protocol::TCP => c::IPPROTO_TCP as c_int, |
| 85 |
Protocol::UDP => c::IPPROTO_UDP as c_int, |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
impl PartialEq<c_int> for Protocol { |
| 91 |
fn eq(&self, other: &c_int) -> bool { |
| 92 |
let int: c_int = (*self).into(); |
| 93 |
*other == int |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
impl PartialEq<Protocol> for c_int { |
| 98 |
fn eq(&self, other: &Protocol) -> bool { |
| 99 |
let int: c_int = (*other).into(); |
| 100 |
*self == int |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
#[derive(Copy, Clone, Debug, PartialEq)] |
| 109 |
pub enum AddrFamily { |
| 110 |
|
| 111 |
Unix, |
| 112 |
|
| 113 |
Inet, |
| 114 |
|
| 115 |
Inet6 |
| 116 |
} |
| 117 |
|
| 118 |
impl From<AddrFamily> for c_int { |
| 119 |
fn from(sock: AddrFamily) -> c_int { |
| 120 |
match sock { |
| 121 |
AddrFamily::Unix => c::AF_UNIX, |
| 122 |
AddrFamily::Inet => c::AF_INET, |
| 123 |
AddrFamily::Inet6 => c::AF_INET6, |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
impl PartialEq<c_int> for AddrFamily { |
| 129 |
fn eq(&self, other: &c_int) -> bool { |
| 130 |
let int: c_int = (*self).into(); |
| 131 |
*other == int |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
impl PartialEq<AddrFamily> for c_int { |
| 136 |
fn eq(&self, other: &AddrFamily) -> bool { |
| 137 |
let int: c_int = (*other).into(); |
| 138 |
*self == int |
| 139 |
} |
| 140 |
} |