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