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