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