]> git.proxmox.com Git - rustc.git/blame - vendor/rustix-0.37.22/src/backend/linux_raw/net/types.rs
New upstream version 1.73.0+dfsg1
[rustc.git] / vendor / rustix-0.37.22 / src / backend / linux_raw / net / types.rs
CommitLineData
064997fb
FG
1use super::super::c;
2use bitflags::bitflags;
3
4/// A type for holding raw integer socket types.
5#[doc(hidden)]
6pub type RawSocketType = u32;
7
8/// `SOCK_*` constants for use with [`socket`].
9///
10/// [`socket`]: crate::net::socket
11#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
12#[repr(transparent)]
13pub struct SocketType(pub(crate) RawSocketType);
14
15#[rustfmt::skip]
16impl SocketType {
17 /// `SOCK_STREAM`
18 pub const STREAM: Self = Self(c::SOCK_STREAM);
19
20 /// `SOCK_DGRAM`
21 pub const DGRAM: Self = Self(c::SOCK_DGRAM);
22
23 /// `SOCK_SEQPACKET`
24 pub const SEQPACKET: Self = Self(c::SOCK_SEQPACKET);
25
26 /// `SOCK_RAW`
27 pub const RAW: Self = Self(c::SOCK_RAW);
28
29 /// `SOCK_RDM`
30 pub const RDM: Self = Self(c::SOCK_RDM);
31
32 /// Constructs a `SocketType` from a raw integer.
33 #[inline]
34 pub const fn from_raw(raw: RawSocketType) -> Self {
35 Self(raw)
36 }
37
38 /// Returns the raw integer for this `SocketType`.
39 #[inline]
40 pub const fn as_raw(self) -> RawSocketType {
41 self.0
42 }
43}
44
45/// A type for holding raw integer address families.
46#[doc(hidden)]
47pub type RawAddressFamily = c::sa_family_t;
48
49/// `AF_*` constants.
50#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
51#[repr(transparent)]
52pub struct AddressFamily(pub(crate) RawAddressFamily);
53
54#[rustfmt::skip]
49aad941 55#[allow(non_upper_case_globals)]
064997fb
FG
56impl AddressFamily {
57 /// `AF_UNSPEC`
58 pub const UNSPEC: Self = Self(c::AF_UNSPEC as _);
59 /// `AF_INET`
60 pub const INET: Self = Self(c::AF_INET as _);
61 /// `AF_INET6`
62 pub const INET6: Self = Self(c::AF_INET6 as _);
63 /// `AF_NETLINK`
64 pub const NETLINK: Self = Self(c::AF_NETLINK as _);
65 /// `AF_UNIX`, aka `AF_LOCAL`
66 #[doc(alias = "LOCAL")]
67 pub const UNIX: Self = Self(c::AF_UNIX as _);
68 /// `AF_AX25`
69 pub const AX25: Self = Self(c::AF_AX25 as _);
70 /// `AF_IPX`
71 pub const IPX: Self = Self(c::AF_IPX as _);
72 /// `AF_APPLETALK`
73 pub const APPLETALK: Self = Self(c::AF_APPLETALK as _);
74 /// `AF_NETROM`
75 pub const NETROM: Self = Self(c::AF_NETROM as _);
76 /// `AF_BRIDGE`
77 pub const BRIDGE: Self = Self(c::AF_BRIDGE as _);
78 /// `AF_ATMPVC`
79 pub const ATMPVC: Self = Self(c::AF_ATMPVC as _);
80 /// `AF_X25`
81 pub const X25: Self = Self(c::AF_X25 as _);
82 /// `AF_ROSE`
83 pub const ROSE: Self = Self(c::AF_ROSE as _);
84 /// `AF_DECnet`
064997fb
FG
85 pub const DECnet: Self = Self(c::AF_DECnet as _);
86 /// `AF_NETBEUI`
87 pub const NETBEUI: Self = Self(c::AF_NETBEUI as _);
88 /// `AF_SECURITY`
89 pub const SECURITY: Self = Self(c::AF_SECURITY as _);
90 /// `AF_KEY`
91 pub const KEY: Self = Self(c::AF_KEY as _);
92 /// `AF_PACKET`
93 pub const PACKET: Self = Self(c::AF_PACKET as _);
94 /// `AF_ASH`
95 pub const ASH: Self = Self(c::AF_ASH as _);
96 /// `AF_ECONET`
97 pub const ECONET: Self = Self(c::AF_ECONET as _);
98 /// `AF_ATMSVC`
99 pub const ATMSVC: Self = Self(c::AF_ATMSVC as _);
100 /// `AF_RDS`
101 pub const RDS: Self = Self(c::AF_RDS as _);
102 /// `AF_SNA`
103 pub const SNA: Self = Self(c::AF_SNA as _);
104 /// `AF_IRDA`
105 pub const IRDA: Self = Self(c::AF_IRDA as _);
106 /// `AF_PPPOX`
107 pub const PPPOX: Self = Self(c::AF_PPPOX as _);
108 /// `AF_WANPIPE`
109 pub const WANPIPE: Self = Self(c::AF_WANPIPE as _);
110 /// `AF_LLC`
111 pub const LLC: Self = Self(c::AF_LLC as _);
112 /// `AF_CAN`
113 pub const CAN: Self = Self(c::AF_CAN as _);
114 /// `AF_TIPC`
115 pub const TIPC: Self = Self(c::AF_TIPC as _);
116 /// `AF_BLUETOOTH`
117 pub const BLUETOOTH: Self = Self(c::AF_BLUETOOTH as _);
118 /// `AF_IUCV`
119 pub const IUCV: Self = Self(c::AF_IUCV as _);
120 /// `AF_RXRPC`
121 pub const RXRPC: Self = Self(c::AF_RXRPC as _);
122 /// `AF_ISDN`
123 pub const ISDN: Self = Self(c::AF_ISDN as _);
124 /// `AF_PHONET`
125 pub const PHONET: Self = Self(c::AF_PHONET as _);
126 /// `AF_IEEE802154`
127 pub const IEEE802154: Self = Self(c::AF_IEEE802154 as _);
128
129 /// Constructs a `AddressFamily` from a raw integer.
130 #[inline]
131 pub const fn from_raw(raw: RawAddressFamily) -> Self {
132 Self(raw)
133 }
134
135 /// Returns the raw integer for this `AddressFamily`.
136 #[inline]
137 pub const fn as_raw(self) -> RawAddressFamily {
138 self.0
139 }
140}
141
142/// A type for holding raw integer protocols.
143#[doc(hidden)]
144pub type RawProtocol = u32;
145
49aad941
FG
146/// `IPPROTO_*` constants for use with [`socket`] and [`socket_with`].
147///
148/// [`socket`]: crate::net::socket
149/// [`socket_with`]: crate::net::socket_with
064997fb
FG
150#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
151#[repr(transparent)]
152pub struct Protocol(pub(crate) RawProtocol);
153
154#[rustfmt::skip]
155impl Protocol {
156 /// `IPPROTO_IP`
157 pub const IP: Self = Self(c::IPPROTO_IP as _);
158 /// `IPPROTO_ICMP`
159 pub const ICMP: Self = Self(c::IPPROTO_ICMP as _);
160 /// `IPPROTO_IGMP`
161 pub const IGMP: Self = Self(c::IPPROTO_IGMP as _);
162 /// `IPPROTO_IPIP`
163 pub const IPIP: Self = Self(c::IPPROTO_IPIP as _);
164 /// `IPPROTO_TCP`
165 pub const TCP: Self = Self(c::IPPROTO_TCP as _);
166 /// `IPPROTO_EGP`
167 pub const EGP: Self = Self(c::IPPROTO_EGP as _);
168 /// `IPPROTO_PUP`
169 pub const PUP: Self = Self(c::IPPROTO_PUP as _);
170 /// `IPPROTO_UDP`
171 pub const UDP: Self = Self(c::IPPROTO_UDP as _);
172 /// `IPPROTO_IDP`
173 pub const IDP: Self = Self(c::IPPROTO_IDP as _);
174 /// `IPPROTO_TP`
175 pub const TP: Self = Self(c::IPPROTO_TP as _);
176 /// `IPPROTO_DCCP`
177 pub const DCCP: Self = Self(c::IPPROTO_DCCP as _);
178 /// `IPPROTO_IPV6`
179 pub const IPV6: Self = Self(c::IPPROTO_IPV6 as _);
180 /// `IPPROTO_RSVP`
181 pub const RSVP: Self = Self(c::IPPROTO_RSVP as _);
182 /// `IPPROTO_GRE`
183 pub const GRE: Self = Self(c::IPPROTO_GRE as _);
184 /// `IPPROTO_ESP`
185 pub const ESP: Self = Self(c::IPPROTO_ESP as _);
186 /// `IPPROTO_AH`
187 pub const AH: Self = Self(c::IPPROTO_AH as _);
188 /// `IPPROTO_MTP`
189 pub const MTP: Self = Self(c::IPPROTO_MTP as _);
190 /// `IPPROTO_BEETPH`
191 pub const BEETPH: Self = Self(c::IPPROTO_BEETPH as _);
192 /// `IPPROTO_ENCAP`
193 pub const ENCAP: Self = Self(c::IPPROTO_ENCAP as _);
194 /// `IPPROTO_PIM`
195 pub const PIM: Self = Self(c::IPPROTO_PIM as _);
196 /// `IPPROTO_COMP`
197 pub const COMP: Self = Self(c::IPPROTO_COMP as _);
198 /// `IPPROTO_SCTP`
199 pub const SCTP: Self = Self(c::IPPROTO_SCTP as _);
200 /// `IPPROTO_UDPLITE`
201 pub const UDPLITE: Self = Self(c::IPPROTO_UDPLITE as _);
202 /// `IPPROTO_MPLS`
203 pub const MPLS: Self = Self(c::IPPROTO_MPLS as _);
204 /// `IPPROTO_ETHERNET`
205 pub const ETHERNET: Self = Self(c::IPPROTO_ETHERNET as _);
206 /// `IPPROTO_RAW`
207 pub const RAW: Self = Self(c::IPPROTO_RAW as _);
208 /// `IPPROTO_MPTCP`
209 pub const MPTCP: Self = Self(c::IPPROTO_MPTCP as _);
210 /// `IPPROTO_FRAGMENT`
211 pub const FRAGMENT: Self = Self(c::IPPROTO_FRAGMENT as _);
212 /// `IPPROTO_ICMPV6`
213 pub const ICMPV6: Self = Self(c::IPPROTO_ICMPV6 as _);
214 /// `IPPROTO_MH`
215 pub const MH: Self = Self(c::IPPROTO_MH as _);
216 /// `IPPROTO_ROUTING`
217 pub const ROUTING: Self = Self(c::IPPROTO_ROUTING as _);
218
219 /// Constructs a `Protocol` from a raw integer.
220 #[inline]
221 pub const fn from_raw(raw: RawProtocol) -> Self {
222 Self(raw)
223 }
224
225 /// Returns the raw integer for this `Protocol`.
226 #[inline]
227 pub const fn as_raw(self) -> RawProtocol {
228 self.0
229 }
230}
231
232/// `SHUT_*` constants for use with [`shutdown`].
233///
234/// [`shutdown`]: crate::net::shutdown
235#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
236#[repr(u32)]
237pub enum Shutdown {
49aad941 238 /// `SHUT_RD`—Disable further read operations.
064997fb
FG
239 Read = c::SHUT_RD,
240 /// `SHUT_WR`—Disable further write operations.
241 Write = c::SHUT_WR,
242 /// `SHUT_RDWR`—Disable further read and write operations.
243 ReadWrite = c::SHUT_RDWR,
244}
245
246bitflags! {
49aad941
FG
247 /// `SOCK_*` constants for use with [`socket_with`], [`accept_with`] and
248 /// [`acceptfrom_with`].
064997fb 249 ///
49aad941 250 /// [`socket_with`]: crate::net::socket_with
064997fb
FG
251 /// [`accept_with`]: crate::net::accept_with
252 /// [`acceptfrom_with`]: crate::net::acceptfrom_with
064997fb
FG
253 pub struct SocketFlags: c::c_uint {
254 /// `SOCK_NONBLOCK`
255 const NONBLOCK = c::O_NONBLOCK;
256
257 /// `SOCK_CLOEXEC`
258 const CLOEXEC = c::O_CLOEXEC;
259 }
260}
261
262/// Timeout identifier for use with [`set_socket_timeout`] and
263/// [`get_socket_timeout`].
264///
265/// [`set_socket_timeout`]: crate::net::sockopt::set_socket_timeout.
266/// [`get_socket_timeout`]: crate::net::sockopt::get_socket_timeout.
267#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
268#[repr(u32)]
269pub enum Timeout {
270 /// `SO_RCVTIMEO`—Timeout for receiving.
271 Recv = c::SO_RCVTIMEO_NEW,
272
273 /// `SO_SNDTIMEO`—Timeout for sending.
274 Send = c::SO_SNDTIMEO_NEW,
275}