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 (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 .into()
40 }
41}
42
43impl PartialEq<c_int> for SockType {
44 fn eq(&self, other: &c_int) -> bool {
45 let int: c_int = (*self).into();
46 *other == int
47 }
48}
49
50impl PartialEq<SockType> for c_int {
51 fn eq(&self, other: &SockType) -> bool {
52 let int: c_int = (*other).into();
53 *self == int
54 }
55}
56
57#[derive(Copy, Clone, Debug, PartialEq, Eq)]
62pub enum Protocol {
63 ICMP,
65 TCP,
67 UDP,
69}
70
71impl From<Protocol> for c_int {
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 .into()
79 }
80}
81
82impl PartialEq<c_int> for Protocol {
83 fn eq(&self, other: &c_int) -> bool {
84 let int: c_int = (*self).into();
85 *other == int
86 }
87}
88
89impl PartialEq<Protocol> for c_int {
90 fn eq(&self, other: &Protocol) -> bool {
91 let int: c_int = (*other).into();
92 *self == int
93 }
94}
95
96#[derive(Copy, Clone, Debug, PartialEq, Eq)]
101pub enum AddrFamily {
102 Unix,
104 Inet,
106 Inet6,
108}
109
110impl From<AddrFamily> for c_int {
111 fn from(sock: AddrFamily) -> c_int {
112 (match sock {
113 AddrFamily::Unix => c::AF_UNIX,
114 AddrFamily::Inet => c::AF_INET,
115 AddrFamily::Inet6 => c::AF_INET6,
116 })
117 .into()
118 }
119}
120
121impl PartialEq<c_int> for AddrFamily {
122 fn eq(&self, other: &c_int) -> bool {
123 let int: c_int = (*self).into();
124 *other == int
125 }
126}
127
128impl PartialEq<AddrFamily> for c_int {
129 fn eq(&self, other: &AddrFamily) -> bool {
130 let int: c_int = (*other).into();
131 *self == int
132 }
133}