1 | //! `getsockopt` and `setsockopt` functions. |
2 | //! |
3 | //! In the rustix API, there is a separate function for each option, so that it |
4 | //! can be given an option-specific type signature. |
5 | //! |
6 | //! # References for all `get_*` functions: |
7 | //! |
8 | //! - [POSIX `getsockopt`] |
9 | //! - [Linux `getsockopt`] |
10 | //! - [Winsock `getsockopt`] |
11 | //! - [Apple `getsockopt`] |
12 | //! - [FreeBSD `getsockopt`] |
13 | //! - [NetBSD `getsockopt`] |
14 | //! - [OpenBSD `getsockopt`] |
15 | //! - [DragonFly BSD `getsockopt`] |
16 | //! - [illumos `getsockopt`] |
17 | //! - [glibc `getsockopt`] |
18 | //! |
19 | //! [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html |
20 | //! [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html |
21 | //! [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt |
22 | //! [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html |
23 | //! [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 |
24 | //! [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 |
25 | //! [OpenBSD `getsockopt`]: https://man.openbsd.org/getsockopt.2 |
26 | //! [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 |
27 | //! [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt |
28 | //! [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html |
29 | //! |
30 | //! # References for all `set_*` functions: |
31 | //! |
32 | //! - [POSIX `setsockopt`] |
33 | //! - [Linux `setsockopt`] |
34 | //! - [Winsock `setsockopt`] |
35 | //! - [Apple `setsockopt`] |
36 | //! - [FreeBSD `setsockopt`] |
37 | //! - [NetBSD `setsockopt`] |
38 | //! - [OpenBSD `setsockopt`] |
39 | //! - [DragonFly BSD `setsockopt`] |
40 | //! - [illumos `setsockopt`] |
41 | //! - [glibc `setsockopt`] |
42 | //! |
43 | //! [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html |
44 | //! [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html |
45 | //! [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt |
46 | //! [Apple `setsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setsockopt.2.html |
47 | //! [FreeBSD `setsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2 |
48 | //! [NetBSD `setsockopt`]: https://man.netbsd.org/setsockopt.2 |
49 | //! [OpenBSD `setsockopt`]: https://man.openbsd.org/setsockopt.2 |
50 | //! [DragonFly BSD `setsockopt`]: https://man.dragonflybsd.org/?command=setsockopt§ion=2 |
51 | //! [illumos `setsockopt`]: https://illumos.org/man/3SOCKET/setsockopt |
52 | //! [glibc `setsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html |
53 | //! |
54 | //! # References for `get_socket_*` and `set_socket_*` functions: |
55 | //! |
56 | //! - [References for all `get_*` functions] |
57 | //! - [References for all `set_*` functions] |
58 | //! - [POSIX `sys/socket.h`] |
59 | //! - [Linux `socket`] |
60 | //! - [Winsock `SOL_SOCKET` options] |
61 | //! - [glibc `SOL_SOCKET` Options] |
62 | //! |
63 | //! [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html |
64 | //! [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html |
65 | //! [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options |
66 | //! [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html |
67 | //! |
68 | //! # References for `get_ip_*` and `set_ip_*` functions: |
69 | //! |
70 | //! - [References for all `get_*` functions] |
71 | //! - [References for all `set_*` functions] |
72 | //! - [POSIX `netinet/in.h`] |
73 | //! - [Linux `ip`] |
74 | //! - [Winsock `IPPROTO_IP` options] |
75 | //! - [Apple `ip`] |
76 | //! - [FreeBSD `ip`] |
77 | //! - [NetBSD `ip`] |
78 | //! - [OpenBSD `ip`] |
79 | //! - [DragonFly BSD `ip`] |
80 | //! - [illumos `ip`] |
81 | //! |
82 | //! [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html |
83 | //! [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html |
84 | //! [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options |
85 | //! [Apple `ip`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/ip.4.auto.html |
86 | //! [FreeBSD `ip`]: https://man.freebsd.org/cgi/man.cgi?query=ip&sektion=4 |
87 | //! [NetBSD `ip`]: https://man.netbsd.org/ip.4 |
88 | //! [OpenBSD `ip`]: https://man.openbsd.org/ip.4 |
89 | //! [DragonFly BSD `ip`]: https://man.dragonflybsd.org/?command=ip§ion=4 |
90 | //! [illumos `ip`]: https://illumos.org/man/4P/ip |
91 | //! |
92 | //! # References for `get_ipv6_*` and `set_ipv6_*` functions: |
93 | //! |
94 | //! - [References for all `get_*` functions] |
95 | //! - [References for all `set_*` functions] |
96 | //! - [POSIX `netinet/in.h`] |
97 | //! - [Linux `ipv6`] |
98 | //! - [Winsock `IPPROTO_IPV6` options] |
99 | //! - [Apple `ip6`] |
100 | //! - [FreeBSD `ip6`] |
101 | //! - [NetBSD `ip6`] |
102 | //! - [OpenBSD `ip6`] |
103 | //! - [DragonFly BSD `ip6`] |
104 | //! - [illumos `ip6`] |
105 | //! |
106 | //! [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html |
107 | //! [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html |
108 | //! [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options |
109 | //! [Apple `ip6`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/ip6.4.auto.html |
110 | //! [FreeBSD `ip6`]: https://man.freebsd.org/cgi/man.cgi?query=ip6&sektion=4 |
111 | //! [NetBSD `ip6`]: https://man.netbsd.org/ip6.4 |
112 | //! [OpenBSD `ip6`]: https://man.openbsd.org/ip6.4 |
113 | //! [DragonFly BSD `ip6`]: https://man.dragonflybsd.org/?command=ip6§ion=4 |
114 | //! [illumos `ip6`]: https://illumos.org/man/4P/ip6 |
115 | //! |
116 | //! # References for `get_tcp_*` and `set_tcp_*` functions: |
117 | //! |
118 | //! - [References for all `get_*` functions] |
119 | //! - [References for all `set_*` functions] |
120 | //! - [POSIX `netinet/tcp.h`] |
121 | //! - [Linux `tcp`] |
122 | //! - [Winsock `IPPROTO_TCP` options] |
123 | //! - [Apple `tcp`] |
124 | //! - [FreeBSD `tcp`] |
125 | //! - [NetBSD `tcp`] |
126 | //! - [OpenBSD `tcp`] |
127 | //! - [DragonFly BSD `tcp`] |
128 | //! - [illumos `tcp`] |
129 | //! |
130 | //! [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html |
131 | //! [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html |
132 | //! [Winsock `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options |
133 | //! [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html |
134 | //! [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 |
135 | //! [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 |
136 | //! [OpenBSD `tcp`]: https://man.openbsd.org/tcp.4 |
137 | //! [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 |
138 | //! [illumos `tcp`]: https://illumos.org/man/4P/tcp |
139 | //! |
140 | //! [References for all `get_*` functions]: #references-for-all-get_-functions |
141 | //! [References for all `set_*` functions]: #references-for-all-set_-functions |
142 | |
143 | #![doc (alias = "getsockopt" )] |
144 | #![doc (alias = "setsockopt" )] |
145 | |
146 | #[cfg (target_os = "linux" )] |
147 | use crate::net::xdp::{XdpMmapOffsets, XdpOptionsFlags, XdpStatistics, XdpUmemReg}; |
148 | #[cfg (not(any( |
149 | apple, |
150 | windows, |
151 | target_os = "aix" , |
152 | target_os = "dragonfly" , |
153 | target_os = "emscripten" , |
154 | target_os = "espidf" , |
155 | target_os = "haiku" , |
156 | target_os = "netbsd" , |
157 | target_os = "nto" , |
158 | target_os = "vita" , |
159 | )))] |
160 | use crate::net::AddressFamily; |
161 | #[cfg (any( |
162 | linux_kernel, |
163 | target_os = "freebsd" , |
164 | target_os = "fuchsia" , |
165 | target_os = "openbsd" , |
166 | target_os = "redox" , |
167 | target_env = "newlib" |
168 | ))] |
169 | use crate::net::Protocol; |
170 | #[cfg (any(linux_kernel, target_os = "fuchsia" ))] |
171 | use crate::net::SocketAddrV4; |
172 | #[cfg (linux_kernel)] |
173 | use crate::net::SocketAddrV6; |
174 | use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; |
175 | use crate::{backend, io}; |
176 | #[cfg (feature = "alloc" )] |
177 | #[cfg (any( |
178 | linux_like, |
179 | target_os = "freebsd" , |
180 | target_os = "fuchsia" , |
181 | target_os = "illumos" |
182 | ))] |
183 | use alloc::string::String; |
184 | use backend::c; |
185 | use backend::fd::AsFd; |
186 | use core::time::Duration; |
187 | |
188 | /// Timeout identifier for use with [`set_socket_timeout`] and |
189 | /// [`get_socket_timeout`]. |
190 | #[derive (Debug, Clone, Copy, Eq, PartialEq, Hash)] |
191 | #[repr (u32)] |
192 | pub enum Timeout { |
193 | /// `SO_RCVTIMEO`—Timeout for receiving. |
194 | Recv = c::SO_RCVTIMEO as _, |
195 | |
196 | /// `SO_SNDTIMEO`—Timeout for sending. |
197 | Send = c::SO_SNDTIMEO as _, |
198 | } |
199 | |
200 | /// `getsockopt(fd, SOL_SOCKET, SO_TYPE)`—Returns the type of a socket. |
201 | /// |
202 | /// See the [module-level documentation] for more. |
203 | /// |
204 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
205 | #[inline ] |
206 | #[doc (alias = "SO_TYPE" )] |
207 | pub fn get_socket_type<Fd: AsFd>(fd: Fd) -> io::Result<SocketType> { |
208 | backend::net::sockopt::get_socket_type(fd.as_fd()) |
209 | } |
210 | |
211 | /// `setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, value)`—Set whether local |
212 | /// addresses may be reused in `bind`. |
213 | /// |
214 | /// See the [module-level documentation] for more. |
215 | /// |
216 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
217 | #[inline ] |
218 | #[doc (alias = "SO_REUSEADDR" )] |
219 | pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
220 | backend::net::sockopt::set_socket_reuseaddr(fd.as_fd(), reuseaddr:value) |
221 | } |
222 | |
223 | /// `getsockopt(fd, SOL_SOCKET, SO_REUSEADDR)` |
224 | /// |
225 | /// See the [module-level documentation] for more. |
226 | /// |
227 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
228 | #[inline ] |
229 | #[doc (alias = "SO_REUSEADDR" )] |
230 | pub fn get_socket_reuseaddr<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
231 | backend::net::sockopt::get_socket_reuseaddr(fd.as_fd()) |
232 | } |
233 | |
234 | /// `setsockopt(fd, SOL_SOCKET, SO_BROADCAST, value)` |
235 | /// |
236 | /// See the [module-level documentation] for more. |
237 | /// |
238 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
239 | #[inline ] |
240 | #[doc (alias = "SO_BROADCAST" )] |
241 | pub fn set_socket_broadcast<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
242 | backend::net::sockopt::set_socket_broadcast(fd.as_fd(), broadcast:value) |
243 | } |
244 | |
245 | /// `getsockopt(fd, SOL_SOCKET, SO_BROADCAST)` |
246 | /// |
247 | /// See the [module-level documentation] for more. |
248 | /// |
249 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
250 | #[inline ] |
251 | #[doc (alias = "SO_BROADCAST" )] |
252 | pub fn get_socket_broadcast<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
253 | backend::net::sockopt::get_socket_broadcast(fd.as_fd()) |
254 | } |
255 | |
256 | /// `setsockopt(fd, SOL_SOCKET, SO_LINGER, value)` |
257 | /// |
258 | /// See the [module-level documentation] for more. |
259 | /// |
260 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
261 | #[inline ] |
262 | #[doc (alias = "SO_LINGER" )] |
263 | pub fn set_socket_linger<Fd: AsFd>(fd: Fd, value: Option<Duration>) -> io::Result<()> { |
264 | backend::net::sockopt::set_socket_linger(fd.as_fd(), linger:value) |
265 | } |
266 | |
267 | /// `getsockopt(fd, SOL_SOCKET, SO_LINGER)` |
268 | /// |
269 | /// See the [module-level documentation] for more. |
270 | /// |
271 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
272 | #[inline ] |
273 | #[doc (alias = "SO_LINGER" )] |
274 | pub fn get_socket_linger<Fd: AsFd>(fd: Fd) -> io::Result<Option<Duration>> { |
275 | backend::net::sockopt::get_socket_linger(fd.as_fd()) |
276 | } |
277 | |
278 | /// `setsockopt(fd, SOL_SOCKET, SO_PASSCRED, value)` |
279 | /// |
280 | /// See the [module-level documentation] for more. |
281 | /// |
282 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
283 | #[cfg (linux_kernel)] |
284 | #[inline ] |
285 | #[doc (alias = "SO_PASSCRED" )] |
286 | pub fn set_socket_passcred<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
287 | backend::net::sockopt::set_socket_passcred(fd.as_fd(), passcred:value) |
288 | } |
289 | |
290 | /// `getsockopt(fd, SOL_SOCKET, SO_PASSCRED)` |
291 | /// |
292 | /// See the [module-level documentation] for more. |
293 | /// |
294 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
295 | #[cfg (linux_kernel)] |
296 | #[inline ] |
297 | #[doc (alias = "SO_PASSCRED" )] |
298 | pub fn get_socket_passcred<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
299 | backend::net::sockopt::get_socket_passcred(fd.as_fd()) |
300 | } |
301 | |
302 | /// `setsockopt(fd, SOL_SOCKET, id, value)`—Set the sending or receiving |
303 | /// timeout. |
304 | /// |
305 | /// See the [module-level documentation] for more. |
306 | /// |
307 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
308 | #[inline ] |
309 | #[doc (alias = "SO_RCVTIMEO" )] |
310 | #[doc (alias = "SO_SNDTIMEO" )] |
311 | pub fn set_socket_timeout<Fd: AsFd>( |
312 | fd: Fd, |
313 | id: Timeout, |
314 | value: Option<Duration>, |
315 | ) -> io::Result<()> { |
316 | backend::net::sockopt::set_socket_timeout(fd.as_fd(), id, timeout:value) |
317 | } |
318 | |
319 | /// `getsockopt(fd, SOL_SOCKET, id)`—Get the sending or receiving timeout. |
320 | /// |
321 | /// See the [module-level documentation] for more. |
322 | /// |
323 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
324 | #[inline ] |
325 | #[doc (alias = "SO_RCVTIMEO" )] |
326 | #[doc (alias = "SO_SNDTIMEO" )] |
327 | pub fn get_socket_timeout<Fd: AsFd>(fd: Fd, id: Timeout) -> io::Result<Option<Duration>> { |
328 | backend::net::sockopt::get_socket_timeout(fd.as_fd(), id) |
329 | } |
330 | |
331 | /// `getsockopt(fd, SOL_SOCKET, SO_ERROR)` |
332 | /// |
333 | /// See the [module-level documentation] for more. |
334 | /// |
335 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
336 | #[inline ] |
337 | #[doc (alias = "SO_ERROR" )] |
338 | pub fn get_socket_error<Fd: AsFd>(fd: Fd) -> io::Result<Result<(), io::Errno>> { |
339 | backend::net::sockopt::get_socket_error(fd.as_fd()) |
340 | } |
341 | |
342 | /// `getsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE)` |
343 | /// |
344 | /// See the [module-level documentation] for more. |
345 | /// |
346 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
347 | #[cfg (any(apple, freebsdlike, target_os = "netbsd" ))] |
348 | #[doc (alias = "SO_NOSIGPIPE" )] |
349 | #[inline ] |
350 | pub fn get_socket_nosigpipe<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
351 | backend::net::sockopt::get_socket_nosigpipe(fd.as_fd()) |
352 | } |
353 | |
354 | /// `setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, value)` |
355 | /// |
356 | /// See the [module-level documentation] for more. |
357 | /// |
358 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
359 | #[cfg (any(apple, freebsdlike, target_os = "netbsd" ))] |
360 | #[doc (alias = "SO_NOSIGPIPE" )] |
361 | #[inline ] |
362 | pub fn set_socket_nosigpipe<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
363 | backend::net::sockopt::set_socket_nosigpipe(fd.as_fd(), value) |
364 | } |
365 | |
366 | /// `setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, value)` |
367 | /// |
368 | /// See the [module-level documentation] for more. |
369 | /// |
370 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
371 | #[inline ] |
372 | #[doc (alias = "SO_KEEPALIVE" )] |
373 | pub fn set_socket_keepalive<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
374 | backend::net::sockopt::set_socket_keepalive(fd.as_fd(), keepalive:value) |
375 | } |
376 | |
377 | /// `getsockopt(fd, SOL_SOCKET, SO_KEEPALIVE)` |
378 | /// |
379 | /// See the [module-level documentation] for more. |
380 | /// |
381 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
382 | #[inline ] |
383 | #[doc (alias = "SO_KEEPALIVE" )] |
384 | pub fn get_socket_keepalive<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
385 | backend::net::sockopt::get_socket_keepalive(fd.as_fd()) |
386 | } |
387 | |
388 | /// `setsockopt(fd, SOL_SOCKET, SO_RCVBUF, value)` |
389 | /// |
390 | /// See the [module-level documentation] for more. |
391 | /// |
392 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
393 | #[inline ] |
394 | #[doc (alias = "SO_RCVBUF" )] |
395 | pub fn set_socket_recv_buffer_size<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> { |
396 | backend::net::sockopt::set_socket_recv_buffer_size(fd.as_fd(), size:value) |
397 | } |
398 | |
399 | /// `getsockopt(fd, SOL_SOCKET, SO_RCVBUF)` |
400 | /// |
401 | /// See the [module-level documentation] for more. |
402 | /// |
403 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
404 | #[inline ] |
405 | #[doc (alias = "SO_RCVBUF" )] |
406 | pub fn get_socket_recv_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> { |
407 | backend::net::sockopt::get_socket_recv_buffer_size(fd.as_fd()) |
408 | } |
409 | |
410 | /// `setsockopt(fd, SOL_SOCKET, SO_SNDBUF, value)` |
411 | /// |
412 | /// See the [module-level documentation] for more. |
413 | /// |
414 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
415 | #[inline ] |
416 | #[doc (alias = "SO_SNDBUF" )] |
417 | pub fn set_socket_send_buffer_size<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> { |
418 | backend::net::sockopt::set_socket_send_buffer_size(fd.as_fd(), size:value) |
419 | } |
420 | |
421 | /// `getsockopt(fd, SOL_SOCKET, SO_SNDBUF)` |
422 | /// |
423 | /// See the [module-level documentation] for more. |
424 | /// |
425 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
426 | #[inline ] |
427 | #[doc (alias = "SO_SNDBUF" )] |
428 | pub fn get_socket_send_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> { |
429 | backend::net::sockopt::get_socket_send_buffer_size(fd.as_fd()) |
430 | } |
431 | |
432 | /// `getsockopt(fd, SOL_SOCKET, SO_DOMAIN)` |
433 | /// |
434 | /// See the [module-level documentation] for more. |
435 | /// |
436 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
437 | #[cfg (not(any( |
438 | apple, |
439 | windows, |
440 | target_os = "aix" , |
441 | target_os = "dragonfly" , |
442 | target_os = "emscripten" , |
443 | target_os = "espidf" , |
444 | target_os = "haiku" , |
445 | target_os = "netbsd" , |
446 | target_os = "nto" , |
447 | target_os = "vita" , |
448 | )))] |
449 | #[inline ] |
450 | #[doc (alias = "SO_DOMAIN" )] |
451 | pub fn get_socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> { |
452 | backend::net::sockopt::get_socket_domain(fd.as_fd()) |
453 | } |
454 | |
455 | /// `getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN)` |
456 | /// |
457 | /// See the [module-level documentation] for more. |
458 | /// |
459 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
460 | #[cfg (not(apple))] // Apple platforms declare the constant, but do not actually implement it. |
461 | #[inline ] |
462 | #[doc (alias = "SO_ACCEPTCONN" )] |
463 | pub fn get_socket_acceptconn<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
464 | backend::net::sockopt::get_socket_acceptconn(fd.as_fd()) |
465 | } |
466 | |
467 | /// `setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, value)` |
468 | /// |
469 | /// See the [module-level documentation] for more. |
470 | /// |
471 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
472 | #[inline ] |
473 | #[doc (alias = "SO_OOBINLINE" )] |
474 | pub fn set_socket_oobinline<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
475 | backend::net::sockopt::set_socket_oobinline(fd.as_fd(), value) |
476 | } |
477 | |
478 | /// `getsockopt(fd, SOL_SOCKET, SO_OOBINLINE)` |
479 | /// |
480 | /// See the [module-level documentation] for more. |
481 | /// |
482 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
483 | #[inline ] |
484 | #[doc (alias = "SO_OOBINLINE" )] |
485 | pub fn get_socket_oobinline<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
486 | backend::net::sockopt::get_socket_oobinline(fd.as_fd()) |
487 | } |
488 | |
489 | /// `setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, value)` |
490 | /// |
491 | /// See the [module-level documentation] for more. |
492 | /// |
493 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
494 | #[cfg (not(any(solarish, windows)))] |
495 | #[cfg (not(windows))] |
496 | #[inline ] |
497 | #[doc (alias = "SO_REUSEPORT" )] |
498 | pub fn set_socket_reuseport<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
499 | backend::net::sockopt::set_socket_reuseport(fd.as_fd(), value) |
500 | } |
501 | |
502 | /// `getsockopt(fd, SOL_SOCKET, SO_REUSEPORT)` |
503 | /// |
504 | /// See the [module-level documentation] for more. |
505 | /// |
506 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
507 | #[cfg (not(any(solarish, windows)))] |
508 | #[inline ] |
509 | #[doc (alias = "SO_REUSEPORT" )] |
510 | pub fn get_socket_reuseport<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
511 | backend::net::sockopt::get_socket_reuseport(fd.as_fd()) |
512 | } |
513 | |
514 | /// `setsockopt(fd, SOL_SOCKET, SO_REUSEPORT_LB, value)` |
515 | /// |
516 | /// See the [module-level documentation] for more. |
517 | /// |
518 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
519 | #[cfg (target_os = "freebsd" )] |
520 | #[inline ] |
521 | #[doc (alias = "SO_REUSEPORT_LB" )] |
522 | pub fn set_socket_reuseport_lb<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
523 | backend::net::sockopt::set_socket_reuseport_lb(fd.as_fd(), value) |
524 | } |
525 | |
526 | /// `getsockopt(fd, SOL_SOCKET, SO_REUSEPORT_LB)` |
527 | /// |
528 | /// See the [module-level documentation] for more. |
529 | /// |
530 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
531 | #[cfg (target_os = "freebsd" )] |
532 | #[inline ] |
533 | #[doc (alias = "SO_REUSEPORT_LB" )] |
534 | pub fn get_socket_reuseport_lb<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
535 | backend::net::sockopt::get_socket_reuseport_lb(fd.as_fd()) |
536 | } |
537 | |
538 | /// `getsockopt(fd, SOL_SOCKET, SO_PROTOCOL)` |
539 | /// |
540 | /// See the [module-level documentation] for more. |
541 | /// |
542 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
543 | #[cfg (any( |
544 | linux_kernel, |
545 | target_os = "freebsd" , |
546 | target_os = "fuchsia" , |
547 | target_os = "openbsd" , |
548 | target_os = "redox" , |
549 | target_env = "newlib" |
550 | ))] |
551 | #[inline ] |
552 | #[doc (alias = "SO_PROTOCOL" )] |
553 | pub fn get_socket_protocol<Fd: AsFd>(fd: Fd) -> io::Result<Option<Protocol>> { |
554 | backend::net::sockopt::get_socket_protocol(fd.as_fd()) |
555 | } |
556 | |
557 | /// `getsockopt(fd, SOL_SOCKET, SO_COOKIE)` |
558 | /// |
559 | /// See the [module-level documentation] for more. |
560 | /// |
561 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
562 | #[cfg (target_os = "linux" )] |
563 | #[inline ] |
564 | #[doc (alias = "SO_COOKIE" )] |
565 | pub fn get_socket_cookie<Fd: AsFd>(fd: Fd) -> io::Result<u64> { |
566 | backend::net::sockopt::get_socket_cookie(fd.as_fd()) |
567 | } |
568 | |
569 | /// `getsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU)` |
570 | /// |
571 | /// See the [module-level documentation] for more. |
572 | /// |
573 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
574 | #[cfg (target_os = "linux" )] |
575 | #[inline ] |
576 | #[doc (alias = "SO_INCOMING_CPU" )] |
577 | pub fn get_socket_incoming_cpu<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
578 | backend::net::sockopt::get_socket_incoming_cpu(fd.as_fd()) |
579 | } |
580 | |
581 | /// `setsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU, value)` |
582 | /// |
583 | /// See the [module-level documentation] for more. |
584 | /// |
585 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
586 | #[cfg (target_os = "linux" )] |
587 | #[inline ] |
588 | #[doc (alias = "SO_INCOMING_CPU" )] |
589 | pub fn set_socket_incoming_cpu<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
590 | backend::net::sockopt::set_socket_incoming_cpu(fd.as_fd(), value) |
591 | } |
592 | |
593 | /// `setsockopt(fd, IPPROTO_IP, IP_TTL, value)` |
594 | /// |
595 | /// See the [module-level documentation] for more. |
596 | /// |
597 | /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions |
598 | #[inline ] |
599 | #[doc (alias = "IP_TTL" )] |
600 | pub fn set_ip_ttl<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
601 | backend::net::sockopt::set_ip_ttl(fd.as_fd(), ttl:value) |
602 | } |
603 | |
604 | /// `getsockopt(fd, IPPROTO_IP, IP_TTL)` |
605 | /// |
606 | /// See the [module-level documentation] for more. |
607 | /// |
608 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
609 | #[inline ] |
610 | #[doc (alias = "IP_TTL" )] |
611 | pub fn get_ip_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
612 | backend::net::sockopt::get_ip_ttl(fd.as_fd()) |
613 | } |
614 | |
615 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, value)` |
616 | /// |
617 | /// See the [module-level documentation] for more. |
618 | /// |
619 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
620 | #[inline ] |
621 | #[doc (alias = "IPV6_V6ONLY" )] |
622 | pub fn set_ipv6_v6only<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
623 | backend::net::sockopt::set_ipv6_v6only(fd.as_fd(), only_v6:value) |
624 | } |
625 | |
626 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY)` |
627 | /// |
628 | /// See the [module-level documentation] for more. |
629 | /// |
630 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
631 | #[inline ] |
632 | #[doc (alias = "IPV6_V6ONLY" )] |
633 | pub fn get_ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
634 | backend::net::sockopt::get_ipv6_v6only(fd.as_fd()) |
635 | } |
636 | |
637 | /// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, value)` |
638 | /// |
639 | /// See the [module-level documentation] for more. |
640 | /// |
641 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
642 | #[inline ] |
643 | #[doc (alias = "IP_MULTICAST_LOOP" )] |
644 | pub fn set_ip_multicast_loop<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
645 | backend::net::sockopt::set_ip_multicast_loop(fd.as_fd(), multicast_loop:value) |
646 | } |
647 | |
648 | /// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP)` |
649 | /// |
650 | /// See the [module-level documentation] for more. |
651 | /// |
652 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
653 | #[inline ] |
654 | #[doc (alias = "IP_MULTICAST_LOOP" )] |
655 | pub fn get_ip_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
656 | backend::net::sockopt::get_ip_multicast_loop(fd.as_fd()) |
657 | } |
658 | |
659 | /// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, value)` |
660 | /// |
661 | /// See the [module-level documentation] for more. |
662 | /// |
663 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
664 | #[inline ] |
665 | #[doc (alias = "IP_MULTICAST_TTL" )] |
666 | pub fn set_ip_multicast_ttl<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
667 | backend::net::sockopt::set_ip_multicast_ttl(fd.as_fd(), multicast_ttl:value) |
668 | } |
669 | |
670 | /// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL)` |
671 | /// |
672 | /// See the [module-level documentation] for more. |
673 | /// |
674 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
675 | #[inline ] |
676 | #[doc (alias = "IP_MULTICAST_TTL" )] |
677 | pub fn get_ip_multicast_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
678 | backend::net::sockopt::get_ip_multicast_ttl(fd.as_fd()) |
679 | } |
680 | |
681 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, value)` |
682 | /// |
683 | /// See the [module-level documentation] for more. |
684 | /// |
685 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
686 | #[inline ] |
687 | #[doc (alias = "IPV6_MULTICAST_LOOP" )] |
688 | pub fn set_ipv6_multicast_loop<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
689 | backend::net::sockopt::set_ipv6_multicast_loop(fd.as_fd(), multicast_loop:value) |
690 | } |
691 | |
692 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP)` |
693 | /// |
694 | /// See the [module-level documentation] for more. |
695 | /// |
696 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
697 | #[inline ] |
698 | #[doc (alias = "IPV6_MULTICAST_LOOP" )] |
699 | pub fn get_ipv6_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
700 | backend::net::sockopt::get_ipv6_multicast_loop(fd.as_fd()) |
701 | } |
702 | |
703 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS)` |
704 | /// |
705 | /// See the [module-level documentation] for more. |
706 | /// |
707 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
708 | #[inline ] |
709 | #[doc (alias = "IPV6_UNICAST_HOPS" )] |
710 | pub fn get_ipv6_unicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u8> { |
711 | backend::net::sockopt::get_ipv6_unicast_hops(fd.as_fd()) |
712 | } |
713 | |
714 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, value)` |
715 | /// |
716 | /// See the [module-level documentation] for more. |
717 | /// |
718 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
719 | #[inline ] |
720 | #[doc (alias = "IPV6_UNICAST_HOPS" )] |
721 | pub fn set_ipv6_unicast_hops<Fd: AsFd>(fd: Fd, value: Option<u8>) -> io::Result<()> { |
722 | backend::net::sockopt::set_ipv6_unicast_hops(fd.as_fd(), hops:value) |
723 | } |
724 | |
725 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, value)` |
726 | /// |
727 | /// See the [module-level documentation] for more. |
728 | /// |
729 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
730 | #[inline ] |
731 | #[doc (alias = "IPV6_MULTICAST_HOPS" )] |
732 | pub fn set_ipv6_multicast_hops<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
733 | backend::net::sockopt::set_ipv6_multicast_hops(fd.as_fd(), multicast_hops:value) |
734 | } |
735 | |
736 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS)` |
737 | /// |
738 | /// See the [module-level documentation] for more. |
739 | /// |
740 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
741 | #[inline ] |
742 | #[doc (alias = "IPV6_MULTICAST_HOPS" )] |
743 | pub fn get_ipv6_multicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
744 | backend::net::sockopt::get_ipv6_multicast_hops(fd.as_fd()) |
745 | } |
746 | |
747 | /// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, interface)` |
748 | /// |
749 | /// This is similar to [`set_ip_add_membership`] but always sets `ifindex` |
750 | /// value to zero. |
751 | /// |
752 | /// See the [module-level documentation] for more. |
753 | /// |
754 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
755 | #[inline ] |
756 | #[doc (alias = "IP_ADD_MEMBERSHIP" )] |
757 | pub fn set_ip_add_membership<Fd: AsFd>( |
758 | fd: Fd, |
759 | multiaddr: &Ipv4Addr, |
760 | interface: &Ipv4Addr, |
761 | ) -> io::Result<()> { |
762 | backend::net::sockopt::set_ip_add_membership(fd.as_fd(), multiaddr, interface) |
763 | } |
764 | |
765 | /// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, address, |
766 | /// ifindex)` |
767 | /// |
768 | /// This is similar to [`set_ip_add_membership_with_ifindex`] but additionally |
769 | /// allows a `ifindex` value to be given. |
770 | /// |
771 | /// See the [module-level documentation] for more. |
772 | /// |
773 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
774 | #[cfg (any( |
775 | apple, |
776 | freebsdlike, |
777 | linux_like, |
778 | target_os = "fuchsia" , |
779 | target_os = "openbsd" |
780 | ))] |
781 | #[inline ] |
782 | #[doc (alias = "IP_ADD_MEMBERSHIP" )] |
783 | pub fn set_ip_add_membership_with_ifindex<Fd: AsFd>( |
784 | fd: Fd, |
785 | multiaddr: &Ipv4Addr, |
786 | address: &Ipv4Addr, |
787 | ifindex: i32, |
788 | ) -> io::Result<()> { |
789 | backend::net::sockopt::set_ip_add_membership_with_ifindex( |
790 | fd.as_fd(), |
791 | multiaddr, |
792 | address, |
793 | ifindex, |
794 | ) |
795 | } |
796 | |
797 | /// `setsockopt(fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, value)` |
798 | /// |
799 | /// See the [module-level documentation] for more. |
800 | /// |
801 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
802 | #[cfg (any(apple, freebsdlike, linux_like, solarish, target_os = "aix" ))] |
803 | #[inline ] |
804 | #[doc (alias = "IP_ADD_SOURCE_MEMBERSHIP" )] |
805 | pub fn set_ip_add_source_membership<Fd: AsFd>( |
806 | fd: Fd, |
807 | multiaddr: &Ipv4Addr, |
808 | interface: &Ipv4Addr, |
809 | sourceaddr: &Ipv4Addr, |
810 | ) -> io::Result<()> { |
811 | backend::net::sockopt::set_ip_add_source_membership( |
812 | fd.as_fd(), |
813 | multiaddr, |
814 | interface, |
815 | sourceaddr, |
816 | ) |
817 | } |
818 | |
819 | /// `setsockopt(fd, IPPROTO_IP, IP_DROP_SOURCE_MEMBERSHIP, value)` |
820 | /// |
821 | /// See the [module-level documentation] for more. |
822 | /// |
823 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
824 | #[cfg (any(apple, freebsdlike, linux_like, solarish, target_os = "aix" ))] |
825 | #[inline ] |
826 | #[doc (alias = "IP_DROP_SOURCE_MEMBERSHIP" )] |
827 | pub fn set_ip_drop_source_membership<Fd: AsFd>( |
828 | fd: Fd, |
829 | multiaddr: &Ipv4Addr, |
830 | interface: &Ipv4Addr, |
831 | sourceaddr: &Ipv4Addr, |
832 | ) -> io::Result<()> { |
833 | backend::net::sockopt::set_ip_drop_source_membership( |
834 | fd.as_fd(), |
835 | multiaddr, |
836 | interface, |
837 | sourceaddr, |
838 | ) |
839 | } |
840 | |
841 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, multiaddr, interface)` |
842 | /// |
843 | /// See the [module-level documentation] for more. |
844 | /// |
845 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
846 | #[inline ] |
847 | #[doc (alias = "IPV6_JOIN_GROUP" )] |
848 | #[doc (alias = "IPV6_ADD_MEMBERSHIP" )] |
849 | pub fn set_ipv6_add_membership<Fd: AsFd>( |
850 | fd: Fd, |
851 | multiaddr: &Ipv6Addr, |
852 | interface: u32, |
853 | ) -> io::Result<()> { |
854 | backend::net::sockopt::set_ipv6_add_membership(fd.as_fd(), multiaddr, interface) |
855 | } |
856 | |
857 | /// `setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, multiaddr, interface)` |
858 | /// |
859 | /// This is similar to [`set_ip_drop_membership`] but always sets `ifindex` |
860 | /// value to zero. |
861 | /// |
862 | /// See the [module-level documentation] for more. |
863 | /// |
864 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
865 | #[inline ] |
866 | #[doc (alias = "IP_DROP_MEMBERSHIP" )] |
867 | pub fn set_ip_drop_membership<Fd: AsFd>( |
868 | fd: Fd, |
869 | multiaddr: &Ipv4Addr, |
870 | interface: &Ipv4Addr, |
871 | ) -> io::Result<()> { |
872 | backend::net::sockopt::set_ip_drop_membership(fd.as_fd(), multiaddr, interface) |
873 | } |
874 | |
875 | /// `setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, multiaddr, interface)` |
876 | /// |
877 | /// This is similar to [`set_ip_drop_membership_with_ifindex`] but additionally |
878 | /// allows a `ifindex` value to be given. |
879 | /// |
880 | /// See the [module-level documentation] for more. |
881 | /// |
882 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
883 | #[cfg (any( |
884 | apple, |
885 | freebsdlike, |
886 | linux_like, |
887 | target_os = "fuchsia" , |
888 | target_os = "openbsd" |
889 | ))] |
890 | #[inline ] |
891 | #[doc (alias = "IP_DROP_MEMBERSHIP" )] |
892 | pub fn set_ip_drop_membership_with_ifindex<Fd: AsFd>( |
893 | fd: Fd, |
894 | multiaddr: &Ipv4Addr, |
895 | address: &Ipv4Addr, |
896 | ifindex: i32, |
897 | ) -> io::Result<()> { |
898 | backend::net::sockopt::set_ip_drop_membership_with_ifindex( |
899 | fd.as_fd(), |
900 | multiaddr, |
901 | address, |
902 | ifindex, |
903 | ) |
904 | } |
905 | |
906 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, multiaddr, interface)` |
907 | /// |
908 | /// See the [module-level documentation] for more. |
909 | /// |
910 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
911 | #[inline ] |
912 | #[doc (alias = "IPV6_LEAVE_GROUP" )] |
913 | #[doc (alias = "IPV6_DROP_MEMBERSHIP" )] |
914 | pub fn set_ipv6_drop_membership<Fd: AsFd>( |
915 | fd: Fd, |
916 | multiaddr: &Ipv6Addr, |
917 | interface: u32, |
918 | ) -> io::Result<()> { |
919 | backend::net::sockopt::set_ipv6_drop_membership(fd.as_fd(), multiaddr, interface) |
920 | } |
921 | |
922 | /// `setsockopt(fd, IPPROTO_IP, IP_TOS, value)` |
923 | /// |
924 | /// See the [module-level documentation] for more. |
925 | /// |
926 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
927 | #[cfg (any( |
928 | bsd, |
929 | linux_like, |
930 | target_os = "aix" , |
931 | target_os = "fuchsia" , |
932 | target_os = "haiku" , |
933 | target_os = "nto" , |
934 | target_env = "newlib" |
935 | ))] |
936 | #[inline ] |
937 | #[doc (alias = "IP_TOS" )] |
938 | pub fn set_ip_tos<Fd: AsFd>(fd: Fd, value: u8) -> io::Result<()> { |
939 | backend::net::sockopt::set_ip_tos(fd.as_fd(), value) |
940 | } |
941 | |
942 | /// `getsockopt(fd, IPPROTO_IP, IP_TOS)` |
943 | /// |
944 | /// See the [module-level documentation] for more. |
945 | /// |
946 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
947 | #[cfg (any( |
948 | bsd, |
949 | linux_like, |
950 | target_os = "aix" , |
951 | target_os = "fuchsia" , |
952 | target_os = "haiku" , |
953 | target_os = "nto" , |
954 | target_env = "newlib" |
955 | ))] |
956 | #[inline ] |
957 | #[doc (alias = "IP_TOS" )] |
958 | pub fn get_ip_tos<Fd: AsFd>(fd: Fd) -> io::Result<u8> { |
959 | backend::net::sockopt::get_ip_tos(fd.as_fd()) |
960 | } |
961 | |
962 | /// `setsockopt(fd, IPPROTO_IP, IP_RECVTOS, value)` |
963 | /// |
964 | /// See the [module-level documentation] for more. |
965 | /// |
966 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
967 | #[cfg (any(apple, linux_like, target_os = "freebsd" , target_os = "fuchsia" ))] |
968 | #[inline ] |
969 | #[doc (alias = "IP_RECVTOS" )] |
970 | pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
971 | backend::net::sockopt::set_ip_recvtos(fd.as_fd(), value) |
972 | } |
973 | |
974 | /// `getsockopt(fd, IPPROTO_IP, IP_RECVTOS)` |
975 | /// |
976 | /// See the [module-level documentation] for more. |
977 | /// |
978 | /// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions |
979 | #[cfg (any(apple, linux_like, target_os = "freebsd" , target_os = "fuchsia" ))] |
980 | #[inline ] |
981 | #[doc (alias = "IP_RECVTOS" )] |
982 | pub fn get_ip_recvtos<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
983 | backend::net::sockopt::get_ip_recvtos(fd.as_fd()) |
984 | } |
985 | |
986 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, value)` |
987 | /// |
988 | /// See the [module-level documentation] for more. |
989 | /// |
990 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
991 | #[cfg (any( |
992 | bsd, |
993 | linux_like, |
994 | target_os = "aix" , |
995 | target_os = "fuchsia" , |
996 | target_os = "nto" |
997 | ))] |
998 | #[inline ] |
999 | #[doc (alias = "IPV6_RECVTCLASS" )] |
1000 | pub fn set_ipv6_recvtclass<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1001 | backend::net::sockopt::set_ipv6_recvtclass(fd.as_fd(), value) |
1002 | } |
1003 | |
1004 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS)` |
1005 | /// |
1006 | /// See the [module-level documentation] for more. |
1007 | /// |
1008 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1009 | #[cfg (any( |
1010 | bsd, |
1011 | linux_like, |
1012 | target_os = "aix" , |
1013 | target_os = "fuchsia" , |
1014 | target_os = "nto" |
1015 | ))] |
1016 | #[inline ] |
1017 | #[doc (alias = "IPV6_RECVTCLASS" )] |
1018 | pub fn get_ipv6_recvtclass<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1019 | backend::net::sockopt::get_ipv6_recvtclass(fd.as_fd()) |
1020 | } |
1021 | |
1022 | /// `setsockopt(fd, IPPROTO_IP, IP_FREEBIND, value)` |
1023 | /// |
1024 | /// See the [module-level documentation] for more. |
1025 | /// |
1026 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1027 | #[cfg (any(linux_kernel, target_os = "fuchsia" ))] |
1028 | #[inline ] |
1029 | #[doc (alias = "IP_FREEBIND" )] |
1030 | pub fn set_ip_freebind<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1031 | backend::net::sockopt::set_ip_freebind(fd.as_fd(), value) |
1032 | } |
1033 | |
1034 | /// `getsockopt(fd, IPPROTO_IP, IP_FREEBIND)` |
1035 | /// |
1036 | /// See the [module-level documentation] for more. |
1037 | /// |
1038 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1039 | #[cfg (any(linux_kernel, target_os = "fuchsia" ))] |
1040 | #[inline ] |
1041 | #[doc (alias = "IP_FREEBIND" )] |
1042 | pub fn get_ip_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1043 | backend::net::sockopt::get_ip_freebind(fd.as_fd()) |
1044 | } |
1045 | |
1046 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_FREEBIND, value)` |
1047 | /// |
1048 | /// See the [module-level documentation] for more. |
1049 | /// |
1050 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1051 | #[cfg (linux_kernel)] |
1052 | #[inline ] |
1053 | #[doc (alias = "IPV6_FREEBIND" )] |
1054 | pub fn set_ipv6_freebind<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1055 | backend::net::sockopt::set_ipv6_freebind(fd.as_fd(), value) |
1056 | } |
1057 | |
1058 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_FREEBIND)` |
1059 | /// |
1060 | /// See the [module-level documentation] for more. |
1061 | /// |
1062 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1063 | #[cfg (linux_kernel)] |
1064 | #[inline ] |
1065 | #[doc (alias = "IPV6_FREEBIND" )] |
1066 | pub fn get_ipv6_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1067 | backend::net::sockopt::get_ipv6_freebind(fd.as_fd()) |
1068 | } |
1069 | |
1070 | /// `getsockopt(fd, IPPROTO_IP, SO_ORIGINAL_DST)` |
1071 | /// |
1072 | /// Even though this corresponnds to a `SO_*` constant, it is an `IPPROTO_IP` |
1073 | /// option. |
1074 | /// |
1075 | /// See the [module-level documentation] for more. |
1076 | /// |
1077 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1078 | #[cfg (any(linux_kernel, target_os = "fuchsia" ))] |
1079 | #[inline ] |
1080 | #[doc (alias = "SO_ORIGINAL_DST" )] |
1081 | pub fn get_ip_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV4> { |
1082 | backend::net::sockopt::get_ip_original_dst(fd.as_fd()) |
1083 | } |
1084 | |
1085 | /// `getsockopt(fd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST)` |
1086 | /// |
1087 | /// Even though this corresponnds to a `IP6T_*` constant, it is an |
1088 | /// `IPPROTO_IPV6` option. |
1089 | /// |
1090 | /// See the [module-level documentation] for more. |
1091 | /// |
1092 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1093 | #[cfg (linux_kernel)] |
1094 | #[inline ] |
1095 | #[doc (alias = "IP6T_SO_ORIGINAL_DST" )] |
1096 | pub fn get_ipv6_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV6> { |
1097 | backend::net::sockopt::get_ipv6_original_dst(fd.as_fd()) |
1098 | } |
1099 | |
1100 | /// `setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, value)` |
1101 | /// |
1102 | /// See the [module-level documentation] for more. |
1103 | /// |
1104 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1105 | #[cfg (not(any( |
1106 | solarish, |
1107 | windows, |
1108 | target_os = "espidf" , |
1109 | target_os = "haiku" , |
1110 | target_os = "vita" |
1111 | )))] |
1112 | #[inline ] |
1113 | #[doc (alias = "IPV6_TCLASS" )] |
1114 | pub fn set_ipv6_tclass<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1115 | backend::net::sockopt::set_ipv6_tclass(fd.as_fd(), value) |
1116 | } |
1117 | |
1118 | /// `getsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS)` |
1119 | /// |
1120 | /// See the [module-level documentation] for more. |
1121 | /// |
1122 | /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions |
1123 | #[cfg (not(any( |
1124 | solarish, |
1125 | windows, |
1126 | target_os = "espidf" , |
1127 | target_os = "haiku" , |
1128 | target_os = "vita" |
1129 | )))] |
1130 | #[inline ] |
1131 | #[doc (alias = "IPV6_TCLASS" )] |
1132 | pub fn get_ipv6_tclass<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
1133 | backend::net::sockopt::get_ipv6_tclass(fd.as_fd()) |
1134 | } |
1135 | |
1136 | /// `setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, value)` |
1137 | /// |
1138 | /// See the [module-level documentation] for more. |
1139 | /// |
1140 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1141 | #[inline ] |
1142 | #[doc (alias = "TCP_NODELAY" )] |
1143 | pub fn set_tcp_nodelay<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1144 | backend::net::sockopt::set_tcp_nodelay(fd.as_fd(), nodelay:value) |
1145 | } |
1146 | |
1147 | /// `getsockopt(fd, IPPROTO_TCP, TCP_NODELAY)` |
1148 | /// |
1149 | /// See the [module-level documentation] for more. |
1150 | /// |
1151 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1152 | #[inline ] |
1153 | #[doc (alias = "TCP_NODELAY" )] |
1154 | pub fn get_tcp_nodelay<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1155 | backend::net::sockopt::get_tcp_nodelay(fd.as_fd()) |
1156 | } |
1157 | |
1158 | /// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, value)` |
1159 | /// |
1160 | /// See the [module-level documentation] for more. |
1161 | /// |
1162 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1163 | #[cfg (not(any(target_os = "openbsd" , target_os = "haiku" , target_os = "nto" )))] |
1164 | #[inline ] |
1165 | #[doc (alias = "TCP_KEEPCNT" )] |
1166 | pub fn set_tcp_keepcnt<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1167 | backend::net::sockopt::set_tcp_keepcnt(fd.as_fd(), count:value) |
1168 | } |
1169 | |
1170 | /// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT)` |
1171 | /// |
1172 | /// See the [module-level documentation] for more. |
1173 | /// |
1174 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1175 | #[cfg (not(any(target_os = "openbsd" , target_os = "haiku" , target_os = "nto" )))] |
1176 | #[inline ] |
1177 | #[doc (alias = "TCP_KEEPCNT" )] |
1178 | pub fn get_tcp_keepcnt<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
1179 | backend::net::sockopt::get_tcp_keepcnt(fd.as_fd()) |
1180 | } |
1181 | |
1182 | /// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, value)` |
1183 | /// |
1184 | /// `TCP_KEEPALIVE` on Apple platforms. |
1185 | /// |
1186 | /// See the [module-level documentation] for more. |
1187 | /// |
1188 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1189 | #[cfg (not(any(target_os = "openbsd" , target_os = "haiku" , target_os = "nto" )))] |
1190 | #[inline ] |
1191 | #[doc (alias = "TCP_KEEPIDLE" )] |
1192 | pub fn set_tcp_keepidle<Fd: AsFd>(fd: Fd, value: Duration) -> io::Result<()> { |
1193 | backend::net::sockopt::set_tcp_keepidle(fd.as_fd(), duration:value) |
1194 | } |
1195 | |
1196 | /// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE)` |
1197 | /// |
1198 | /// `TCP_KEEPALIVE` on Apple platforms. |
1199 | /// |
1200 | /// See the [module-level documentation] for more. |
1201 | /// |
1202 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1203 | #[cfg (not(any(target_os = "openbsd" , target_os = "haiku" , target_os = "nto" )))] |
1204 | #[inline ] |
1205 | #[doc (alias = "TCP_KEEPIDLE" )] |
1206 | pub fn get_tcp_keepidle<Fd: AsFd>(fd: Fd) -> io::Result<Duration> { |
1207 | backend::net::sockopt::get_tcp_keepidle(fd.as_fd()) |
1208 | } |
1209 | |
1210 | /// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, value)` |
1211 | /// |
1212 | /// See the [module-level documentation] for more. |
1213 | /// |
1214 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1215 | #[cfg (not(any(target_os = "openbsd" , target_os = "haiku" , target_os = "nto" )))] |
1216 | #[inline ] |
1217 | #[doc (alias = "TCP_KEEPINTVL" )] |
1218 | pub fn set_tcp_keepintvl<Fd: AsFd>(fd: Fd, value: Duration) -> io::Result<()> { |
1219 | backend::net::sockopt::set_tcp_keepintvl(fd.as_fd(), duration:value) |
1220 | } |
1221 | |
1222 | /// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL)` |
1223 | /// |
1224 | /// See the [module-level documentation] for more. |
1225 | /// |
1226 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1227 | #[cfg (not(any(target_os = "openbsd" , target_os = "haiku" , target_os = "nto" )))] |
1228 | #[inline ] |
1229 | #[doc (alias = "TCP_KEEPINTVL" )] |
1230 | pub fn get_tcp_keepintvl<Fd: AsFd>(fd: Fd) -> io::Result<Duration> { |
1231 | backend::net::sockopt::get_tcp_keepintvl(fd.as_fd()) |
1232 | } |
1233 | |
1234 | /// `setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, value)` |
1235 | /// |
1236 | /// See the [module-level documentation] for more. |
1237 | /// |
1238 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1239 | #[cfg (any(linux_like, target_os = "fuchsia" ))] |
1240 | #[inline ] |
1241 | #[doc (alias = "TCP_USER_TIMEOUT" )] |
1242 | pub fn set_tcp_user_timeout<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1243 | backend::net::sockopt::set_tcp_user_timeout(fd.as_fd(), value) |
1244 | } |
1245 | |
1246 | /// `getsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT)` |
1247 | /// |
1248 | /// See the [module-level documentation] for more. |
1249 | /// |
1250 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1251 | #[cfg (any(linux_like, target_os = "fuchsia" ))] |
1252 | #[inline ] |
1253 | #[doc (alias = "TCP_USER_TIMEOUT" )] |
1254 | pub fn get_tcp_user_timeout<Fd: AsFd>(fd: Fd) -> io::Result<u32> { |
1255 | backend::net::sockopt::get_tcp_user_timeout(fd.as_fd()) |
1256 | } |
1257 | |
1258 | /// `setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, value)` |
1259 | /// |
1260 | /// See the [module-level documentation] for more. |
1261 | /// |
1262 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1263 | #[cfg (any(linux_like, target_os = "fuchsia" ))] |
1264 | #[inline ] |
1265 | #[doc (alias = "TCP_QUICKACK" )] |
1266 | pub fn set_tcp_quickack<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1267 | backend::net::sockopt::set_tcp_quickack(fd.as_fd(), value) |
1268 | } |
1269 | |
1270 | /// `getsockopt(fd, IPPROTO_TCP, TCP_QUICKACK)` |
1271 | /// |
1272 | /// See the [module-level documentation] for more. |
1273 | /// |
1274 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1275 | #[cfg (any(linux_like, target_os = "fuchsia" ))] |
1276 | #[inline ] |
1277 | #[doc (alias = "TCP_QUICKACK" )] |
1278 | pub fn get_tcp_quickack<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1279 | backend::net::sockopt::get_tcp_quickack(fd.as_fd()) |
1280 | } |
1281 | |
1282 | /// `setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, value)` |
1283 | /// |
1284 | /// See the [module-level documentation] for more. |
1285 | /// |
1286 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1287 | #[cfg (any( |
1288 | linux_like, |
1289 | target_os = "freebsd" , |
1290 | target_os = "fuchsia" , |
1291 | target_os = "illumos" |
1292 | ))] |
1293 | #[inline ] |
1294 | #[doc (alias = "TCP_CONGESTION" )] |
1295 | pub fn set_tcp_congestion<Fd: AsFd>(fd: Fd, value: &str) -> io::Result<()> { |
1296 | backend::net::sockopt::set_tcp_congestion(fd.as_fd(), value) |
1297 | } |
1298 | |
1299 | /// `getsockopt(fd, IPPROTO_TCP, TCP_CONGESTION)` |
1300 | /// |
1301 | /// See the [module-level documentation] for more. |
1302 | /// |
1303 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1304 | #[cfg (feature = "alloc" )] |
1305 | #[cfg (any( |
1306 | linux_like, |
1307 | target_os = "freebsd" , |
1308 | target_os = "fuchsia" , |
1309 | target_os = "illumos" |
1310 | ))] |
1311 | #[inline ] |
1312 | #[doc (alias = "TCP_CONGESTION" )] |
1313 | pub fn get_tcp_congestion<Fd: AsFd>(fd: Fd) -> io::Result<String> { |
1314 | backend::net::sockopt::get_tcp_congestion(fd.as_fd()) |
1315 | } |
1316 | |
1317 | /// `setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, value)` |
1318 | /// |
1319 | /// See the [module-level documentation] for more. |
1320 | /// |
1321 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1322 | #[cfg (any(linux_like, target_os = "fuchsia" ))] |
1323 | #[inline ] |
1324 | #[doc (alias = "TCP_THIN_LINEAR_TIMEOUTS" )] |
1325 | pub fn set_tcp_thin_linear_timeouts<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1326 | backend::net::sockopt::set_tcp_thin_linear_timeouts(fd.as_fd(), value) |
1327 | } |
1328 | |
1329 | /// `getsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS)` |
1330 | /// |
1331 | /// See the [module-level documentation] for more. |
1332 | /// |
1333 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1334 | #[cfg (any(linux_like, target_os = "fuchsia" ))] |
1335 | #[inline ] |
1336 | #[doc (alias = "TCP_THIN_LINEAR_TIMEOUTS" )] |
1337 | pub fn get_tcp_thin_linear_timeouts<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1338 | backend::net::sockopt::get_tcp_thin_linear_timeouts(fd.as_fd()) |
1339 | } |
1340 | |
1341 | /// `setsockopt(fd, IPPROTO_TCP, TCP_CORK, value)` |
1342 | /// |
1343 | /// See the [module-level documentation] for more. |
1344 | /// |
1345 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1346 | #[cfg (any(linux_like, solarish, target_os = "fuchsia" ))] |
1347 | #[inline ] |
1348 | #[doc (alias = "TCP_CORK" )] |
1349 | pub fn set_tcp_cork<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { |
1350 | backend::net::sockopt::set_tcp_cork(fd.as_fd(), value) |
1351 | } |
1352 | |
1353 | /// `getsockopt(fd, IPPROTO_TCP, TCP_CORK)` |
1354 | /// |
1355 | /// See the [module-level documentation] for more. |
1356 | /// |
1357 | /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions |
1358 | #[cfg (any(linux_like, solarish, target_os = "fuchsia" ))] |
1359 | #[inline ] |
1360 | #[doc (alias = "TCP_CORK" )] |
1361 | pub fn get_tcp_cork<Fd: AsFd>(fd: Fd) -> io::Result<bool> { |
1362 | backend::net::sockopt::get_tcp_cork(fd.as_fd()) |
1363 | } |
1364 | |
1365 | /// Get credentials of Unix domain socket peer process |
1366 | /// |
1367 | /// # References |
1368 | /// - [Linux `unix`] |
1369 | /// |
1370 | /// [Linux `unix`]: https://man7.org/linux/man-pages/man7/unix.7.html |
1371 | #[cfg (linux_kernel)] |
1372 | #[doc (alias = "SO_PEERCRED" )] |
1373 | pub fn get_socket_peercred<Fd: AsFd>(fd: Fd) -> io::Result<super::UCred> { |
1374 | backend::net::sockopt::get_socket_peercred(fd.as_fd()) |
1375 | } |
1376 | |
1377 | /// `setsockopt(fd, SOL_XDP, XDP_UMEM_REG, value)` |
1378 | /// |
1379 | /// On kernel versions only supporting v1, the flags are ignored. |
1380 | /// |
1381 | /// # References |
1382 | /// - [Linux] |
1383 | /// |
1384 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-umem-reg-setsockopt |
1385 | #[cfg (target_os = "linux" )] |
1386 | #[doc (alias = "XDP_UMEM_REG" )] |
1387 | pub fn set_xdp_umem_reg<Fd: AsFd>(fd: Fd, value: XdpUmemReg) -> io::Result<()> { |
1388 | backend::net::sockopt::set_xdp_umem_reg(fd.as_fd(), value) |
1389 | } |
1390 | |
1391 | /// `setsockopt(fd, SOL_XDP, XDP_UMEM_FILL_RING, value)` |
1392 | /// |
1393 | /// # References |
1394 | /// - [Linux] |
1395 | /// |
1396 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts |
1397 | #[cfg (target_os = "linux" )] |
1398 | #[doc (alias = "XDP_UMEM_FILL_RING" )] |
1399 | pub fn set_xdp_umem_fill_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1400 | backend::net::sockopt::set_xdp_umem_fill_ring_size(fd.as_fd(), value) |
1401 | } |
1402 | |
1403 | /// `setsockopt(fd, SOL_XDP, XDP_UMEM_COMPLETION_RING, value)` |
1404 | /// |
1405 | /// # References |
1406 | /// - [Linux] |
1407 | /// |
1408 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts |
1409 | #[cfg (target_os = "linux" )] |
1410 | #[doc (alias = "XDP_UMEM_COMPLETION_RING" )] |
1411 | pub fn set_xdp_umem_completion_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1412 | backend::net::sockopt::set_xdp_umem_completion_ring_size(fd.as_fd(), value) |
1413 | } |
1414 | |
1415 | /// `setsockopt(fd, SOL_XDP, XDP_TX_RING, value)` |
1416 | /// |
1417 | /// # References |
1418 | /// - [Linux] |
1419 | /// |
1420 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts |
1421 | #[cfg (target_os = "linux" )] |
1422 | #[doc (alias = "XDP_TX_RING" )] |
1423 | pub fn set_xdp_tx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1424 | backend::net::sockopt::set_xdp_tx_ring_size(fd.as_fd(), value) |
1425 | } |
1426 | |
1427 | /// `setsockopt(fd, SOL_XDP, XDP_RX_RING, value)` |
1428 | /// |
1429 | /// # References |
1430 | /// - [Linux] |
1431 | /// |
1432 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts |
1433 | #[cfg (target_os = "linux" )] |
1434 | #[doc (alias = "XDP_RX_RING" )] |
1435 | pub fn set_xdp_rx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> { |
1436 | backend::net::sockopt::set_xdp_rx_ring_size(fd.as_fd(), value) |
1437 | } |
1438 | |
1439 | /// `getsockopt(fd, SOL_XDP, XDP_MMAP_OFFSETS)` |
1440 | /// |
1441 | /// # References |
1442 | /// - [Linux] |
1443 | /// |
1444 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html |
1445 | #[cfg (target_os = "linux" )] |
1446 | #[doc (alias = "XDP_MMAP_OFFSETS" )] |
1447 | pub fn get_xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> { |
1448 | backend::net::sockopt::get_xdp_mmap_offsets(fd.as_fd()) |
1449 | } |
1450 | |
1451 | /// `getsockopt(fd, SOL_XDP, XDP_STATISTICS)` |
1452 | /// |
1453 | /// # References |
1454 | /// - [Linux] |
1455 | /// |
1456 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt |
1457 | #[cfg (target_os = "linux" )] |
1458 | #[doc (alias = "XDP_STATISTICS" )] |
1459 | pub fn get_xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> { |
1460 | backend::net::sockopt::get_xdp_statistics(fd.as_fd()) |
1461 | } |
1462 | |
1463 | /// `getsockopt(fd, SOL_XDP, XDP_OPTIONS)` |
1464 | /// |
1465 | /// # References |
1466 | /// - [Linux] |
1467 | /// |
1468 | /// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-options-getsockopt |
1469 | #[cfg (target_os = "linux" )] |
1470 | #[doc (alias = "XDP_OPTIONS" )] |
1471 | pub fn get_xdp_options<Fd: AsFd>(fd: Fd) -> io::Result<XdpOptionsFlags> { |
1472 | backend::net::sockopt::get_xdp_options(fd.as_fd()) |
1473 | } |
1474 | |
1475 | #[test ] |
1476 | fn test_sizes() { |
1477 | use c::c_int; |
1478 | |
1479 | // Backend code needs to cast these to `c_int` so make sure that cast |
1480 | // isn't lossy. |
1481 | assert_eq_size!(Timeout, c_int); |
1482 | } |
1483 | |