rustix/net/sockopt.rs
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/9799919799/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://sourceware.org/glibc/manual/latest/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/9799919799/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://sourceware.org/glibc/manual/latest/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/9799919799/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://sourceware.org/glibc/manual/latest/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/9799919799/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://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man4/ip.4
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/9799919799/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://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man4/ip6.4
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/9799919799/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://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man4/tcp.4
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")]
147use 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)))]
160use 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))]
169use crate::net::Protocol;
170#[cfg(any(linux_kernel, target_os = "fuchsia"))]
171use crate::net::SocketAddrV4;
172#[cfg(linux_kernel)]
173use crate::net::SocketAddrV6;
174use crate::net::{Ipv4Addr, Ipv6Addr, SocketType};
175use 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))]
183use alloc::string::String;
184use backend::c;
185use backend::fd::AsFd;
186use core::time::Duration;
187
188/// Timeout identifier for use with [`set_socket_timeout`] and
189/// [`socket_timeout`].
190#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
191#[repr(u32)]
192pub 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")]
207pub fn socket_type<Fd: AsFd>(fd: Fd) -> io::Result<SocketType> {
208 backend::net::sockopt::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")]
219pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
220 backend::net::sockopt::set_socket_reuseaddr(fd.as_fd(), 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")]
230pub fn socket_reuseaddr<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
231 backend::net::sockopt::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")]
241pub fn set_socket_broadcast<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
242 backend::net::sockopt::set_socket_broadcast(fd.as_fd(), 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")]
252pub fn socket_broadcast<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
253 backend::net::sockopt::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")]
263pub fn set_socket_linger<Fd: AsFd>(fd: Fd, value: Option<Duration>) -> io::Result<()> {
264 backend::net::sockopt::set_socket_linger(fd.as_fd(), 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")]
274pub fn socket_linger<Fd: AsFd>(fd: Fd) -> io::Result<Option<Duration>> {
275 backend::net::sockopt::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")]
286pub fn set_socket_passcred<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
287 backend::net::sockopt::set_socket_passcred(fd.as_fd(), 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")]
298pub fn socket_passcred<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
299 backend::net::sockopt::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")]
311pub 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, 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")]
327pub fn socket_timeout<Fd: AsFd>(fd: Fd, id: Timeout) -> io::Result<Option<Duration>> {
328 backend::net::sockopt::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")]
338pub fn socket_error<Fd: AsFd>(fd: Fd) -> io::Result<Result<(), io::Errno>> {
339 backend::net::sockopt::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]
350pub fn socket_nosigpipe<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
351 backend::net::sockopt::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]
362pub 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")]
373pub fn set_socket_keepalive<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
374 backend::net::sockopt::set_socket_keepalive(fd.as_fd(), 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")]
384pub fn socket_keepalive<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
385 backend::net::sockopt::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")]
395pub 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(), value)
397}
398
399/// `setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, value)`
400///
401/// See the [module-level documentation] for more.
402///
403/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
404#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "redox"))]
405#[inline]
406#[doc(alias = "SO_RCVBUFFORCE")]
407pub fn set_socket_recv_buffer_size_force<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
408 backend::net::sockopt::set_socket_recv_buffer_size_force(fd.as_fd(), value)
409}
410
411/// `getsockopt(fd, SOL_SOCKET, SO_RCVBUF)`
412///
413/// See the [module-level documentation] for more.
414///
415/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
416#[inline]
417#[doc(alias = "SO_RCVBUF")]
418pub fn socket_recv_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> {
419 backend::net::sockopt::socket_recv_buffer_size(fd.as_fd())
420}
421
422/// `setsockopt(fd, SOL_SOCKET, SO_SNDBUF, value)`
423///
424/// See the [module-level documentation] for more.
425///
426/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
427#[inline]
428#[doc(alias = "SO_SNDBUF")]
429pub fn set_socket_send_buffer_size<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
430 backend::net::sockopt::set_socket_send_buffer_size(fd.as_fd(), value)
431}
432
433/// `setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, value)`
434///
435/// See the [module-level documentation] for more.
436///
437/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
438#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "redox"))]
439#[inline]
440#[doc(alias = "SO_SNDBUFFORCE")]
441pub fn set_socket_send_buffer_size_force<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
442 backend::net::sockopt::set_socket_send_buffer_size_force(fd.as_fd(), value)
443}
444
445/// `getsockopt(fd, SOL_SOCKET, SO_SNDBUF)`
446///
447/// See the [module-level documentation] for more.
448///
449/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
450#[inline]
451#[doc(alias = "SO_SNDBUF")]
452pub fn socket_send_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> {
453 backend::net::sockopt::socket_send_buffer_size(fd.as_fd())
454}
455
456/// `getsockopt(fd, SOL_SOCKET, SO_DOMAIN)`
457///
458/// See the [module-level documentation] for more.
459///
460/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
461#[cfg(not(any(
462 apple,
463 windows,
464 target_os = "aix",
465 target_os = "dragonfly",
466 target_os = "emscripten",
467 target_os = "espidf",
468 target_os = "haiku",
469 target_os = "horizon",
470 target_os = "hurd",
471 target_os = "netbsd",
472 target_os = "nto",
473 target_os = "vita",
474)))]
475#[inline]
476#[doc(alias = "SO_DOMAIN")]
477pub fn socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> {
478 backend::net::sockopt::socket_domain(fd.as_fd())
479}
480
481/// `getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN)`
482///
483/// See the [module-level documentation] for more.
484///
485/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
486#[cfg(not(apple))] // Apple platforms declare the constant, but do not actually implement it.
487#[inline]
488#[doc(alias = "SO_ACCEPTCONN")]
489pub fn socket_acceptconn<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
490 backend::net::sockopt::socket_acceptconn(fd.as_fd())
491}
492
493/// `setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, value)`
494///
495/// See the [module-level documentation] for more.
496///
497/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
498#[inline]
499#[doc(alias = "SO_OOBINLINE")]
500pub fn set_socket_oobinline<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
501 backend::net::sockopt::set_socket_oobinline(fd.as_fd(), value)
502}
503
504/// `getsockopt(fd, SOL_SOCKET, SO_OOBINLINE)`
505///
506/// See the [module-level documentation] for more.
507///
508/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
509#[inline]
510#[doc(alias = "SO_OOBINLINE")]
511pub fn socket_oobinline<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
512 backend::net::sockopt::socket_oobinline(fd.as_fd())
513}
514
515/// `setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, value)`
516///
517/// See the [module-level documentation] for more.
518///
519/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
520#[cfg(not(any(solarish, windows)))]
521#[cfg(not(windows))]
522#[inline]
523#[doc(alias = "SO_REUSEPORT")]
524pub fn set_socket_reuseport<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
525 backend::net::sockopt::set_socket_reuseport(fd.as_fd(), value)
526}
527
528/// `getsockopt(fd, SOL_SOCKET, SO_REUSEPORT)`
529///
530/// See the [module-level documentation] for more.
531///
532/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
533#[cfg(not(any(solarish, windows)))]
534#[inline]
535#[doc(alias = "SO_REUSEPORT")]
536pub fn socket_reuseport<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
537 backend::net::sockopt::socket_reuseport(fd.as_fd())
538}
539
540/// `setsockopt(fd, SOL_SOCKET, SO_REUSEPORT_LB, value)`
541///
542/// See the [module-level documentation] for more.
543///
544/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
545#[cfg(target_os = "freebsd")]
546#[inline]
547#[doc(alias = "SO_REUSEPORT_LB")]
548pub fn set_socket_reuseport_lb<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
549 backend::net::sockopt::set_socket_reuseport_lb(fd.as_fd(), value)
550}
551
552/// `getsockopt(fd, SOL_SOCKET, SO_REUSEPORT_LB)`
553///
554/// See the [module-level documentation] for more.
555///
556/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
557#[cfg(target_os = "freebsd")]
558#[inline]
559#[doc(alias = "SO_REUSEPORT_LB")]
560pub fn socket_reuseport_lb<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
561 backend::net::sockopt::socket_reuseport_lb(fd.as_fd())
562}
563
564/// `getsockopt(fd, SOL_SOCKET, SO_PROTOCOL)`
565///
566/// See the [module-level documentation] for more.
567///
568/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
569#[cfg(any(
570 linux_kernel,
571 target_os = "freebsd",
572 target_os = "fuchsia",
573 target_os = "openbsd",
574 target_os = "redox",
575 target_env = "newlib"
576))]
577#[inline]
578#[doc(alias = "SO_PROTOCOL")]
579pub fn socket_protocol<Fd: AsFd>(fd: Fd) -> io::Result<Option<Protocol>> {
580 backend::net::sockopt::socket_protocol(fd.as_fd())
581}
582
583/// `getsockopt(fd, SOL_SOCKET, SO_COOKIE)`
584///
585/// See the [module-level documentation] for more.
586///
587/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
588#[cfg(target_os = "linux")]
589#[inline]
590#[doc(alias = "SO_COOKIE")]
591pub fn socket_cookie<Fd: AsFd>(fd: Fd) -> io::Result<u64> {
592 backend::net::sockopt::socket_cookie(fd.as_fd())
593}
594
595/// `getsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU)`
596///
597/// See the [module-level documentation] for more.
598///
599/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
600#[cfg(target_os = "linux")]
601#[inline]
602#[doc(alias = "SO_INCOMING_CPU")]
603pub fn socket_incoming_cpu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
604 backend::net::sockopt::socket_incoming_cpu(fd.as_fd())
605}
606
607/// `setsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU, value)`
608///
609/// See the [module-level documentation] for more.
610///
611/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
612#[cfg(target_os = "linux")]
613#[inline]
614#[doc(alias = "SO_INCOMING_CPU")]
615pub fn set_socket_incoming_cpu<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
616 backend::net::sockopt::set_socket_incoming_cpu(fd.as_fd(), value)
617}
618
619/// `setsockopt(fd, IPPROTO_IP, IP_TTL, value)`
620///
621/// See the [module-level documentation] for more.
622///
623/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
624#[inline]
625#[doc(alias = "IP_TTL")]
626pub fn set_ip_ttl<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
627 backend::net::sockopt::set_ip_ttl(fd.as_fd(), value)
628}
629
630/// `getsockopt(fd, IPPROTO_IP, IP_TTL)`
631///
632/// See the [module-level documentation] for more.
633///
634/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
635#[inline]
636#[doc(alias = "IP_TTL")]
637pub fn ip_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
638 backend::net::sockopt::ip_ttl(fd.as_fd())
639}
640
641/// `setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, value)`
642///
643/// See the [module-level documentation] for more.
644///
645/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
646#[inline]
647#[doc(alias = "IPV6_V6ONLY")]
648pub fn set_ipv6_v6only<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
649 backend::net::sockopt::set_ipv6_v6only(fd.as_fd(), value)
650}
651
652/// `getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY)`
653///
654/// See the [module-level documentation] for more.
655///
656/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
657#[inline]
658#[doc(alias = "IPV6_V6ONLY")]
659pub fn ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
660 backend::net::sockopt::ipv6_v6only(fd.as_fd())
661}
662
663/// `getsockopt(fd, IPPROTO_IP, IP_MTU)`
664///
665/// See the [module-level documentation] for more.
666///
667/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
668#[inline]
669#[cfg(linux_kernel)]
670#[doc(alias = "IP_MTU")]
671pub fn ip_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
672 backend::net::sockopt::ip_mtu(fd.as_fd())
673}
674
675/// `getsockopt(fd, IPPROTO_IPV6, IPV6_MTU)`
676///
677/// See the [module-level documentation] for more.
678///
679/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
680#[inline]
681#[cfg(linux_kernel)]
682#[doc(alias = "IPV6_MTU")]
683pub fn ipv6_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
684 backend::net::sockopt::ipv6_mtu(fd.as_fd())
685}
686
687/// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, value)`
688///
689/// See the [module-level documentation] for more.
690///
691/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
692#[inline]
693#[doc(alias = "IP_MULTICAST_IF")]
694pub fn set_ip_multicast_if<Fd: AsFd>(fd: Fd, value: &Ipv4Addr) -> io::Result<()> {
695 backend::net::sockopt::set_ip_multicast_if(fd.as_fd(), value)
696}
697
698/// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, multiaddr, address,
699/// ifindex)`
700///
701/// This is similar to [`set_ip_multicast_if`] but additionally allows an
702/// `ifindex` value to be given.
703///
704/// See the [module-level documentation] for more.
705///
706/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
707#[cfg(any(
708 apple,
709 freebsdlike,
710 linux_like,
711 target_os = "fuchsia",
712 target_os = "openbsd"
713))]
714#[inline]
715#[doc(alias = "IP_MULTICAST_IF")]
716pub fn set_ip_multicast_if_with_ifindex<Fd: AsFd>(
717 fd: Fd,
718 multiaddr: &Ipv4Addr,
719 address: &Ipv4Addr,
720 ifindex: u32,
721) -> io::Result<()> {
722 backend::net::sockopt::set_ip_multicast_if_with_ifindex(fd.as_fd(), multiaddr, address, ifindex)
723}
724
725/// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF)`
726///
727/// See the [module-level documentation] for more.
728///
729/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
730#[inline]
731#[doc(alias = "IP_MULTICAST_IF")]
732pub fn ip_multicast_if<Fd: AsFd>(fd: Fd) -> io::Result<Ipv4Addr> {
733 backend::net::sockopt::ip_multicast_if(fd.as_fd())
734}
735
736/// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, value)`
737///
738/// See the [module-level documentation] for more.
739///
740/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
741#[inline]
742#[doc(alias = "IPV6_MULTICAST_IF")]
743pub fn set_ipv6_multicast_if<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
744 backend::net::sockopt::set_ipv6_multicast_if(fd.as_fd(), value)
745}
746
747/// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF)`
748///
749/// See the [module-level documentation] for more.
750///
751/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
752#[inline]
753#[doc(alias = "IPV6_MULTICAST_IF")]
754pub fn ipv6_multicast_if<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
755 backend::net::sockopt::ipv6_multicast_if(fd.as_fd())
756}
757
758/// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, value)`
759///
760/// See the [module-level documentation] for more.
761///
762/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
763#[inline]
764#[doc(alias = "IP_MULTICAST_LOOP")]
765pub fn set_ip_multicast_loop<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
766 backend::net::sockopt::set_ip_multicast_loop(fd.as_fd(), value)
767}
768
769/// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP)`
770///
771/// See the [module-level documentation] for more.
772///
773/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
774#[inline]
775#[doc(alias = "IP_MULTICAST_LOOP")]
776pub fn ip_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
777 backend::net::sockopt::ip_multicast_loop(fd.as_fd())
778}
779
780/// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, value)`
781///
782/// See the [module-level documentation] for more.
783///
784/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
785#[inline]
786#[doc(alias = "IP_MULTICAST_TTL")]
787pub fn set_ip_multicast_ttl<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
788 backend::net::sockopt::set_ip_multicast_ttl(fd.as_fd(), value)
789}
790
791/// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL)`
792///
793/// See the [module-level documentation] for more.
794///
795/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
796#[inline]
797#[doc(alias = "IP_MULTICAST_TTL")]
798pub fn ip_multicast_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
799 backend::net::sockopt::ip_multicast_ttl(fd.as_fd())
800}
801
802/// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, value)`
803///
804/// See the [module-level documentation] for more.
805///
806/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
807#[inline]
808#[doc(alias = "IPV6_MULTICAST_LOOP")]
809pub fn set_ipv6_multicast_loop<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
810 backend::net::sockopt::set_ipv6_multicast_loop(fd.as_fd(), value)
811}
812
813/// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP)`
814///
815/// See the [module-level documentation] for more.
816///
817/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
818#[inline]
819#[doc(alias = "IPV6_MULTICAST_LOOP")]
820pub fn ipv6_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
821 backend::net::sockopt::ipv6_multicast_loop(fd.as_fd())
822}
823
824/// `getsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS)`
825///
826/// See the [module-level documentation] for more.
827///
828/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
829#[inline]
830#[doc(alias = "IPV6_UNICAST_HOPS")]
831pub fn ipv6_unicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u8> {
832 backend::net::sockopt::ipv6_unicast_hops(fd.as_fd())
833}
834
835/// `setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, value)`
836///
837/// See the [module-level documentation] for more.
838///
839/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
840#[inline]
841#[doc(alias = "IPV6_UNICAST_HOPS")]
842pub fn set_ipv6_unicast_hops<Fd: AsFd>(fd: Fd, value: Option<u8>) -> io::Result<()> {
843 backend::net::sockopt::set_ipv6_unicast_hops(fd.as_fd(), value)
844}
845
846/// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, value)`
847///
848/// See the [module-level documentation] for more.
849///
850/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
851#[inline]
852#[doc(alias = "IPV6_MULTICAST_HOPS")]
853pub fn set_ipv6_multicast_hops<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
854 backend::net::sockopt::set_ipv6_multicast_hops(fd.as_fd(), value)
855}
856
857/// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS)`
858///
859/// See the [module-level documentation] for more.
860///
861/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
862#[inline]
863#[doc(alias = "IPV6_MULTICAST_HOPS")]
864pub fn ipv6_multicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
865 backend::net::sockopt::ipv6_multicast_hops(fd.as_fd())
866}
867
868/// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, interface)`
869///
870/// This is similar to [`set_ip_add_membership`] but always sets the `ifindex`
871/// value to zero. See [`set_ip_add_membership_with_ifindex`] instead to also
872/// give the `ifindex` value.
873///
874/// See the [module-level documentation] for more.
875///
876/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
877#[inline]
878#[doc(alias = "IP_ADD_MEMBERSHIP")]
879pub fn set_ip_add_membership<Fd: AsFd>(
880 fd: Fd,
881 multiaddr: &Ipv4Addr,
882 interface: &Ipv4Addr,
883) -> io::Result<()> {
884 backend::net::sockopt::set_ip_add_membership(fd.as_fd(), multiaddr, interface)
885}
886
887/// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, address,
888/// ifindex)`
889///
890/// This is similar to [`set_ip_add_membership`] but additionally allows an
891/// `ifindex` value to be given.
892///
893/// See the [module-level documentation] for more.
894///
895/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
896#[cfg(any(
897 apple,
898 freebsdlike,
899 linux_like,
900 target_os = "fuchsia",
901 target_os = "openbsd"
902))]
903#[inline]
904#[doc(alias = "IP_ADD_MEMBERSHIP")]
905pub fn set_ip_add_membership_with_ifindex<Fd: AsFd>(
906 fd: Fd,
907 multiaddr: &Ipv4Addr,
908 address: &Ipv4Addr,
909 ifindex: u32,
910) -> io::Result<()> {
911 backend::net::sockopt::set_ip_add_membership_with_ifindex(
912 fd.as_fd(),
913 multiaddr,
914 address,
915 ifindex,
916 )
917}
918
919/// `setsockopt(fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, value)`
920///
921/// See the [module-level documentation] for more.
922///
923/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
924#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))]
925#[inline]
926#[doc(alias = "IP_ADD_SOURCE_MEMBERSHIP")]
927pub fn set_ip_add_source_membership<Fd: AsFd>(
928 fd: Fd,
929 multiaddr: &Ipv4Addr,
930 interface: &Ipv4Addr,
931 sourceaddr: &Ipv4Addr,
932) -> io::Result<()> {
933 backend::net::sockopt::set_ip_add_source_membership(
934 fd.as_fd(),
935 multiaddr,
936 interface,
937 sourceaddr,
938 )
939}
940
941/// `setsockopt(fd, IPPROTO_IP, IP_DROP_SOURCE_MEMBERSHIP, value)`
942///
943/// See the [module-level documentation] for more.
944///
945/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
946#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))]
947#[inline]
948#[doc(alias = "IP_DROP_SOURCE_MEMBERSHIP")]
949pub fn set_ip_drop_source_membership<Fd: AsFd>(
950 fd: Fd,
951 multiaddr: &Ipv4Addr,
952 interface: &Ipv4Addr,
953 sourceaddr: &Ipv4Addr,
954) -> io::Result<()> {
955 backend::net::sockopt::set_ip_drop_source_membership(
956 fd.as_fd(),
957 multiaddr,
958 interface,
959 sourceaddr,
960 )
961}
962
963/// `setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, multiaddr, interface)`
964///
965/// See the [module-level documentation] for more.
966///
967/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
968#[inline]
969#[doc(alias = "IPV6_JOIN_GROUP")]
970#[doc(alias = "IPV6_ADD_MEMBERSHIP")]
971pub fn set_ipv6_add_membership<Fd: AsFd>(
972 fd: Fd,
973 multiaddr: &Ipv6Addr,
974 interface: u32,
975) -> io::Result<()> {
976 backend::net::sockopt::set_ipv6_add_membership(fd.as_fd(), multiaddr, interface)
977}
978
979/// `setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, multiaddr, interface)`
980///
981/// This is similar to [`set_ip_drop_membership`] but always sets `ifindex`
982/// value to zero.
983///
984/// See the [module-level documentation] for more.
985///
986/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
987#[inline]
988#[doc(alias = "IP_DROP_MEMBERSHIP")]
989pub fn set_ip_drop_membership<Fd: AsFd>(
990 fd: Fd,
991 multiaddr: &Ipv4Addr,
992 interface: &Ipv4Addr,
993) -> io::Result<()> {
994 backend::net::sockopt::set_ip_drop_membership(fd.as_fd(), multiaddr, interface)
995}
996
997/// `setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, multiaddr, interface)`
998///
999/// This is similar to [`set_ip_drop_membership_with_ifindex`] but additionally
1000/// allows a `ifindex` value to be given.
1001///
1002/// See the [module-level documentation] for more.
1003///
1004/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1005#[cfg(any(
1006 apple,
1007 freebsdlike,
1008 linux_like,
1009 target_os = "fuchsia",
1010 target_os = "openbsd"
1011))]
1012#[inline]
1013#[doc(alias = "IP_DROP_MEMBERSHIP")]
1014pub fn set_ip_drop_membership_with_ifindex<Fd: AsFd>(
1015 fd: Fd,
1016 multiaddr: &Ipv4Addr,
1017 address: &Ipv4Addr,
1018 ifindex: u32,
1019) -> io::Result<()> {
1020 backend::net::sockopt::set_ip_drop_membership_with_ifindex(
1021 fd.as_fd(),
1022 multiaddr,
1023 address,
1024 ifindex,
1025 )
1026}
1027
1028/// `setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, multiaddr, interface)`
1029///
1030/// See the [module-level documentation] for more.
1031///
1032/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1033#[inline]
1034#[doc(alias = "IPV6_LEAVE_GROUP")]
1035#[doc(alias = "IPV6_DROP_MEMBERSHIP")]
1036pub fn set_ipv6_drop_membership<Fd: AsFd>(
1037 fd: Fd,
1038 multiaddr: &Ipv6Addr,
1039 interface: u32,
1040) -> io::Result<()> {
1041 backend::net::sockopt::set_ipv6_drop_membership(fd.as_fd(), multiaddr, interface)
1042}
1043
1044/// `setsockopt(fd, IPPROTO_IP, IP_TOS, value)`
1045///
1046/// See the [module-level documentation] for more.
1047///
1048/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1049#[cfg(any(
1050 bsd,
1051 linux_like,
1052 target_os = "aix",
1053 target_os = "fuchsia",
1054 target_os = "haiku",
1055 target_os = "nto",
1056 target_env = "newlib"
1057))]
1058#[inline]
1059#[doc(alias = "IP_TOS")]
1060pub fn set_ip_tos<Fd: AsFd>(fd: Fd, value: u8) -> io::Result<()> {
1061 backend::net::sockopt::set_ip_tos(fd.as_fd(), value)
1062}
1063
1064/// `getsockopt(fd, IPPROTO_IP, IP_TOS)`
1065///
1066/// See the [module-level documentation] for more.
1067///
1068/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1069#[cfg(any(
1070 bsd,
1071 linux_like,
1072 target_os = "aix",
1073 target_os = "fuchsia",
1074 target_os = "haiku",
1075 target_os = "nto",
1076 target_env = "newlib"
1077))]
1078#[inline]
1079#[doc(alias = "IP_TOS")]
1080pub fn ip_tos<Fd: AsFd>(fd: Fd) -> io::Result<u8> {
1081 backend::net::sockopt::ip_tos(fd.as_fd())
1082}
1083
1084/// `setsockopt(fd, IPPROTO_IP, IP_RECVTOS, value)`
1085///
1086/// See the [module-level documentation] for more.
1087///
1088/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1089#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
1090#[inline]
1091#[doc(alias = "IP_RECVTOS")]
1092pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1093 backend::net::sockopt::set_ip_recvtos(fd.as_fd(), value)
1094}
1095
1096/// `getsockopt(fd, IPPROTO_IP, IP_RECVTOS)`
1097///
1098/// See the [module-level documentation] for more.
1099///
1100/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1101#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
1102#[inline]
1103#[doc(alias = "IP_RECVTOS")]
1104pub fn ip_recvtos<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1105 backend::net::sockopt::ip_recvtos(fd.as_fd())
1106}
1107
1108/// `setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, value)`
1109///
1110/// See the [module-level documentation] for more.
1111///
1112/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1113#[cfg(any(
1114 bsd,
1115 linux_like,
1116 target_os = "aix",
1117 target_os = "fuchsia",
1118 target_os = "nto"
1119))]
1120#[inline]
1121#[doc(alias = "IPV6_RECVTCLASS")]
1122pub fn set_ipv6_recvtclass<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1123 backend::net::sockopt::set_ipv6_recvtclass(fd.as_fd(), value)
1124}
1125
1126/// `getsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS)`
1127///
1128/// See the [module-level documentation] for more.
1129///
1130/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1131#[cfg(any(
1132 bsd,
1133 linux_like,
1134 target_os = "aix",
1135 target_os = "fuchsia",
1136 target_os = "nto"
1137))]
1138#[inline]
1139#[doc(alias = "IPV6_RECVTCLASS")]
1140pub fn ipv6_recvtclass<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1141 backend::net::sockopt::ipv6_recvtclass(fd.as_fd())
1142}
1143
1144/// `setsockopt(fd, IPPROTO_IP, IP_FREEBIND, value)`
1145///
1146/// See the [module-level documentation] for more.
1147///
1148/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1149#[cfg(any(linux_kernel, target_os = "fuchsia"))]
1150#[inline]
1151#[doc(alias = "IP_FREEBIND")]
1152pub fn set_ip_freebind<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1153 backend::net::sockopt::set_ip_freebind(fd.as_fd(), value)
1154}
1155
1156/// `getsockopt(fd, IPPROTO_IP, IP_FREEBIND)`
1157///
1158/// See the [module-level documentation] for more.
1159///
1160/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1161#[cfg(any(linux_kernel, target_os = "fuchsia"))]
1162#[inline]
1163#[doc(alias = "IP_FREEBIND")]
1164pub fn ip_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1165 backend::net::sockopt::ip_freebind(fd.as_fd())
1166}
1167
1168/// `setsockopt(fd, IPPROTO_IPV6, IPV6_FREEBIND, value)`
1169///
1170/// See the [module-level documentation] for more.
1171///
1172/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1173#[cfg(linux_kernel)]
1174#[inline]
1175#[doc(alias = "IPV6_FREEBIND")]
1176pub fn set_ipv6_freebind<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1177 backend::net::sockopt::set_ipv6_freebind(fd.as_fd(), value)
1178}
1179
1180/// `getsockopt(fd, IPPROTO_IPV6, IPV6_FREEBIND)`
1181///
1182/// See the [module-level documentation] for more.
1183///
1184/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1185#[cfg(linux_kernel)]
1186#[inline]
1187#[doc(alias = "IPV6_FREEBIND")]
1188pub fn ipv6_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1189 backend::net::sockopt::ipv6_freebind(fd.as_fd())
1190}
1191
1192/// `getsockopt(fd, IPPROTO_IP, SO_ORIGINAL_DST)`
1193///
1194/// Even though this corresponds to a `SO_*` constant, it is an `IPPROTO_IP`
1195/// option.
1196///
1197/// See the [module-level documentation] for more.
1198///
1199/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1200#[cfg(any(linux_kernel, target_os = "fuchsia"))]
1201#[inline]
1202#[doc(alias = "SO_ORIGINAL_DST")]
1203pub fn ip_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV4> {
1204 backend::net::sockopt::ip_original_dst(fd.as_fd())
1205}
1206
1207/// `getsockopt(fd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST)`
1208///
1209/// Even though this corresponds to a `IP6T_*` constant, it is an
1210/// `IPPROTO_IPV6` option.
1211///
1212/// See the [module-level documentation] for more.
1213///
1214/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1215#[cfg(linux_kernel)]
1216#[inline]
1217#[doc(alias = "IP6T_SO_ORIGINAL_DST")]
1218pub fn ipv6_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV6> {
1219 backend::net::sockopt::ipv6_original_dst(fd.as_fd())
1220}
1221
1222/// `setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, value)`
1223///
1224/// See the [module-level documentation] for more.
1225///
1226/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1227#[cfg(not(any(
1228 solarish,
1229 windows,
1230 target_os = "espidf",
1231 target_os = "haiku",
1232 target_os = "horizon",
1233 target_os = "redox",
1234 target_os = "vita"
1235)))]
1236#[inline]
1237#[doc(alias = "IPV6_TCLASS")]
1238pub fn set_ipv6_tclass<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1239 backend::net::sockopt::set_ipv6_tclass(fd.as_fd(), value)
1240}
1241
1242/// `getsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS)`
1243///
1244/// See the [module-level documentation] for more.
1245///
1246/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
1247#[cfg(not(any(
1248 solarish,
1249 windows,
1250 target_os = "espidf",
1251 target_os = "haiku",
1252 target_os = "horizon",
1253 target_os = "redox",
1254 target_os = "vita"
1255)))]
1256#[inline]
1257#[doc(alias = "IPV6_TCLASS")]
1258pub fn ipv6_tclass<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
1259 backend::net::sockopt::ipv6_tclass(fd.as_fd())
1260}
1261
1262/// `setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, value)`
1263///
1264/// See the [module-level documentation] for more.
1265///
1266/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1267#[inline]
1268#[doc(alias = "TCP_NODELAY")]
1269pub fn set_tcp_nodelay<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1270 backend::net::sockopt::set_tcp_nodelay(fd.as_fd(), value)
1271}
1272
1273/// `getsockopt(fd, IPPROTO_TCP, TCP_NODELAY)`
1274///
1275/// See the [module-level documentation] for more.
1276///
1277/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1278#[inline]
1279#[doc(alias = "TCP_NODELAY")]
1280pub fn tcp_nodelay<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1281 backend::net::sockopt::tcp_nodelay(fd.as_fd())
1282}
1283
1284/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, value)`
1285///
1286/// See the [module-level documentation] for more.
1287///
1288/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1289#[cfg(not(any(
1290 target_os = "haiku",
1291 target_os = "nto",
1292 target_os = "openbsd",
1293 target_os = "redox"
1294)))]
1295#[inline]
1296#[doc(alias = "TCP_KEEPCNT")]
1297pub fn set_tcp_keepcnt<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1298 backend::net::sockopt::set_tcp_keepcnt(fd.as_fd(), value)
1299}
1300
1301/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT)`
1302///
1303/// See the [module-level documentation] for more.
1304///
1305/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1306#[cfg(not(any(
1307 target_os = "haiku",
1308 target_os = "nto",
1309 target_os = "openbsd",
1310 target_os = "redox"
1311)))]
1312#[inline]
1313#[doc(alias = "TCP_KEEPCNT")]
1314pub fn tcp_keepcnt<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
1315 backend::net::sockopt::tcp_keepcnt(fd.as_fd())
1316}
1317
1318/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, value)`
1319///
1320/// `TCP_KEEPALIVE` on Apple platforms.
1321///
1322/// See the [module-level documentation] for more.
1323///
1324/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1325#[cfg(not(any(target_os = "haiku", target_os = "nto", target_os = "openbsd")))]
1326#[inline]
1327#[doc(alias = "TCP_KEEPIDLE")]
1328pub fn set_tcp_keepidle<Fd: AsFd>(fd: Fd, value: Duration) -> io::Result<()> {
1329 backend::net::sockopt::set_tcp_keepidle(fd.as_fd(), value)
1330}
1331
1332/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE)`
1333///
1334/// `TCP_KEEPALIVE` on Apple platforms.
1335///
1336/// See the [module-level documentation] for more.
1337///
1338/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1339#[cfg(not(any(target_os = "haiku", target_os = "nto", target_os = "openbsd")))]
1340#[inline]
1341#[doc(alias = "TCP_KEEPIDLE")]
1342pub fn tcp_keepidle<Fd: AsFd>(fd: Fd) -> io::Result<Duration> {
1343 backend::net::sockopt::tcp_keepidle(fd.as_fd())
1344}
1345
1346/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, value)`
1347///
1348/// See the [module-level documentation] for more.
1349///
1350/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1351#[cfg(not(any(
1352 target_os = "haiku",
1353 target_os = "nto",
1354 target_os = "openbsd",
1355 target_os = "redox"
1356)))]
1357#[inline]
1358#[doc(alias = "TCP_KEEPINTVL")]
1359pub fn set_tcp_keepintvl<Fd: AsFd>(fd: Fd, value: Duration) -> io::Result<()> {
1360 backend::net::sockopt::set_tcp_keepintvl(fd.as_fd(), value)
1361}
1362
1363/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL)`
1364///
1365/// See the [module-level documentation] for more.
1366///
1367/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1368#[cfg(not(any(
1369 target_os = "haiku",
1370 target_os = "nto",
1371 target_os = "openbsd",
1372 target_os = "redox"
1373)))]
1374#[inline]
1375#[doc(alias = "TCP_KEEPINTVL")]
1376pub fn tcp_keepintvl<Fd: AsFd>(fd: Fd) -> io::Result<Duration> {
1377 backend::net::sockopt::tcp_keepintvl(fd.as_fd())
1378}
1379
1380/// `setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, value)`
1381///
1382/// See the [module-level documentation] for more.
1383///
1384/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1385#[cfg(any(linux_like, target_os = "fuchsia"))]
1386#[inline]
1387#[doc(alias = "TCP_USER_TIMEOUT")]
1388pub fn set_tcp_user_timeout<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1389 backend::net::sockopt::set_tcp_user_timeout(fd.as_fd(), value)
1390}
1391
1392/// `getsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT)`
1393///
1394/// See the [module-level documentation] for more.
1395///
1396/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1397#[cfg(any(linux_like, target_os = "fuchsia"))]
1398#[inline]
1399#[doc(alias = "TCP_USER_TIMEOUT")]
1400pub fn tcp_user_timeout<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
1401 backend::net::sockopt::tcp_user_timeout(fd.as_fd())
1402}
1403
1404/// `setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, value)`
1405///
1406/// See the [module-level documentation] for more.
1407///
1408/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1409#[cfg(any(linux_like, target_os = "fuchsia"))]
1410#[inline]
1411#[doc(alias = "TCP_QUICKACK")]
1412pub fn set_tcp_quickack<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1413 backend::net::sockopt::set_tcp_quickack(fd.as_fd(), value)
1414}
1415
1416/// `getsockopt(fd, IPPROTO_TCP, TCP_QUICKACK)`
1417///
1418/// See the [module-level documentation] for more.
1419///
1420/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1421#[cfg(any(linux_like, target_os = "fuchsia"))]
1422#[inline]
1423#[doc(alias = "TCP_QUICKACK")]
1424pub fn tcp_quickack<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1425 backend::net::sockopt::tcp_quickack(fd.as_fd())
1426}
1427
1428/// `setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, value)`
1429///
1430/// See the [module-level documentation] for more.
1431///
1432/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1433#[cfg(any(
1434 linux_like,
1435 target_os = "freebsd",
1436 target_os = "fuchsia",
1437 target_os = "illumos"
1438))]
1439#[inline]
1440#[doc(alias = "TCP_CONGESTION")]
1441pub fn set_tcp_congestion<Fd: AsFd>(fd: Fd, value: &str) -> io::Result<()> {
1442 backend::net::sockopt::set_tcp_congestion(fd.as_fd(), value)
1443}
1444
1445/// `getsockopt(fd, IPPROTO_TCP, TCP_CONGESTION)`
1446///
1447/// See the [module-level documentation] for more.
1448///
1449/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1450#[cfg(feature = "alloc")]
1451#[cfg(any(
1452 linux_like,
1453 target_os = "freebsd",
1454 target_os = "fuchsia",
1455 target_os = "illumos"
1456))]
1457#[inline]
1458#[doc(alias = "TCP_CONGESTION")]
1459pub fn tcp_congestion<Fd: AsFd>(fd: Fd) -> io::Result<String> {
1460 backend::net::sockopt::tcp_congestion(fd.as_fd())
1461}
1462
1463/// `setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, value)`
1464///
1465/// See the [module-level documentation] for more.
1466///
1467/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1468#[cfg(any(linux_like, target_os = "fuchsia"))]
1469#[inline]
1470#[doc(alias = "TCP_THIN_LINEAR_TIMEOUTS")]
1471pub fn set_tcp_thin_linear_timeouts<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1472 backend::net::sockopt::set_tcp_thin_linear_timeouts(fd.as_fd(), value)
1473}
1474
1475/// `getsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS)`
1476///
1477/// See the [module-level documentation] for more.
1478///
1479/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1480#[cfg(any(linux_like, target_os = "fuchsia"))]
1481#[inline]
1482#[doc(alias = "TCP_THIN_LINEAR_TIMEOUTS")]
1483pub fn tcp_thin_linear_timeouts<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1484 backend::net::sockopt::tcp_thin_linear_timeouts(fd.as_fd())
1485}
1486
1487/// `setsockopt(fd, IPPROTO_TCP, TCP_CORK, value)`
1488///
1489/// See the [module-level documentation] for more.
1490///
1491/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1492#[cfg(any(linux_like, solarish, target_os = "fuchsia"))]
1493#[inline]
1494#[doc(alias = "TCP_CORK")]
1495pub fn set_tcp_cork<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
1496 backend::net::sockopt::set_tcp_cork(fd.as_fd(), value)
1497}
1498
1499/// `getsockopt(fd, IPPROTO_TCP, TCP_CORK)`
1500///
1501/// See the [module-level documentation] for more.
1502///
1503/// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions
1504#[cfg(any(linux_like, solarish, target_os = "fuchsia"))]
1505#[inline]
1506#[doc(alias = "TCP_CORK")]
1507pub fn tcp_cork<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
1508 backend::net::sockopt::tcp_cork(fd.as_fd())
1509}
1510
1511/// `getsockopt(fd, SOL_SOCKET, SO_PEERCRED)`—Get credentials of Unix domain
1512/// socket peer process.
1513///
1514/// # References
1515/// - [Linux `unix`]
1516///
1517/// [Linux `unix`]: https://man7.org/linux/man-pages/man7/unix.7.html
1518#[cfg(linux_kernel)]
1519#[doc(alias = "SO_PEERCRED")]
1520pub fn socket_peercred<Fd: AsFd>(fd: Fd) -> io::Result<super::UCred> {
1521 backend::net::sockopt::socket_peercred(fd.as_fd())
1522}
1523
1524/// `setsockopt(fd, SOL_XDP, XDP_UMEM_REG, value)`
1525///
1526/// On kernel versions only supporting v1, the flags are ignored.
1527///
1528/// # References
1529/// - [Linux]
1530///
1531/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-umem-reg-setsockopt
1532#[cfg(target_os = "linux")]
1533#[doc(alias = "XDP_UMEM_REG")]
1534pub fn set_xdp_umem_reg<Fd: AsFd>(fd: Fd, value: XdpUmemReg) -> io::Result<()> {
1535 backend::net::sockopt::set_xdp_umem_reg(fd.as_fd(), value)
1536}
1537
1538/// `setsockopt(fd, SOL_XDP, XDP_UMEM_FILL_RING, value)`
1539///
1540/// # References
1541/// - [Linux]
1542///
1543/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts
1544#[cfg(target_os = "linux")]
1545#[doc(alias = "XDP_UMEM_FILL_RING")]
1546pub fn set_xdp_umem_fill_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1547 backend::net::sockopt::set_xdp_umem_fill_ring_size(fd.as_fd(), value)
1548}
1549
1550/// `setsockopt(fd, SOL_XDP, XDP_UMEM_COMPLETION_RING, value)`
1551///
1552/// # References
1553/// - [Linux]
1554///
1555/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts
1556#[cfg(target_os = "linux")]
1557#[doc(alias = "XDP_UMEM_COMPLETION_RING")]
1558pub fn set_xdp_umem_completion_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1559 backend::net::sockopt::set_xdp_umem_completion_ring_size(fd.as_fd(), value)
1560}
1561
1562/// `setsockopt(fd, SOL_XDP, XDP_TX_RING, value)`
1563///
1564/// # References
1565/// - [Linux]
1566///
1567/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts
1568#[cfg(target_os = "linux")]
1569#[doc(alias = "XDP_TX_RING")]
1570pub fn set_xdp_tx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1571 backend::net::sockopt::set_xdp_tx_ring_size(fd.as_fd(), value)
1572}
1573
1574/// `setsockopt(fd, SOL_XDP, XDP_RX_RING, value)`
1575///
1576/// # References
1577/// - [Linux]
1578///
1579/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-rx-tx-umem-fill-umem-completion-ring-setsockopts
1580#[cfg(target_os = "linux")]
1581#[doc(alias = "XDP_RX_RING")]
1582pub fn set_xdp_rx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
1583 backend::net::sockopt::set_xdp_rx_ring_size(fd.as_fd(), value)
1584}
1585
1586/// `getsockopt(fd, SOL_XDP, XDP_MMAP_OFFSETS)`
1587///
1588/// # References
1589/// - [Linux]
1590///
1591/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html
1592#[cfg(target_os = "linux")]
1593#[doc(alias = "XDP_MMAP_OFFSETS")]
1594pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
1595 backend::net::sockopt::xdp_mmap_offsets(fd.as_fd())
1596}
1597
1598/// `getsockopt(fd, SOL_XDP, XDP_STATISTICS)`
1599///
1600/// # References
1601/// - [Linux]
1602///
1603/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt
1604#[cfg(target_os = "linux")]
1605#[doc(alias = "XDP_STATISTICS")]
1606pub fn xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> {
1607 backend::net::sockopt::xdp_statistics(fd.as_fd())
1608}
1609
1610/// `getsockopt(fd, SOL_XDP, XDP_OPTIONS)`
1611///
1612/// # References
1613/// - [Linux]
1614///
1615/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-options-getsockopt
1616#[cfg(target_os = "linux")]
1617#[doc(alias = "XDP_OPTIONS")]
1618pub fn xdp_options<Fd: AsFd>(fd: Fd) -> io::Result<XdpOptionsFlags> {
1619 backend::net::sockopt::xdp_options(fd.as_fd())
1620}
1621
1622#[cfg(test)]
1623mod tests {
1624 use super::*;
1625
1626 #[test]
1627 fn test_sizes() {
1628 use c::c_int;
1629
1630 // Backend code needs to cast these to `c_int` so make sure that cast
1631 // isn't lossy.
1632 assert_eq_size!(Timeout, c_int);
1633 }
1634}