1 //! `getsockopt` and `setsockopt` functions.
3 //! In the rustix API, there is a separate function for each option, so that
4 //! it can be given an option-specific type signature.
6 #![doc(alias = "getsockopt")]
7 #![doc(alias = "setsockopt")]
9 use crate::net
::{Ipv4Addr, Ipv6Addr, SocketType}
;
10 use crate::{backend, io}
;
11 use backend
::fd
::AsFd
;
12 use core
::time
::Duration
;
14 pub use backend
::net
::types
::Timeout
;
16 /// `getsockopt(fd, SOL_SOCKET, SO_TYPE)`—Returns the type of a socket.
19 /// - [POSIX `getsockopt`]
20 /// - [POSIX `sys/socket.h`]
21 /// - [Linux `getsockopt`]
22 /// - [Linux `socket`]
23 /// - [Winsock2 `getsockopt`]
24 /// - [Winsock2 `SOL_SOCKET` options]
26 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
27 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
28 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
29 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
30 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
31 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
33 #[doc(alias = "SO_TYPE")]
34 pub fn get_socket_type
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<SocketType
> {
35 backend
::net
::syscalls
::sockopt
::get_socket_type(fd
.as_fd())
38 /// `setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, value)`
41 /// - [POSIX `setsockopt`]
42 /// - [POSIX `sys/socket.h`]
43 /// - [Linux `setsockopt`]
44 /// - [Linux `socket`]
45 /// - [Winsock2 `setsockopt`]
46 /// - [Winsock2 `SOL_SOCKET` options]
48 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
49 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
50 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
51 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
52 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
53 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
55 #[doc(alias = "SO_REUSEADDR")]
56 pub fn set_socket_reuseaddr
<Fd
: AsFd
>(fd
: Fd
, value
: bool
) -> io
::Result
<()> {
57 backend
::net
::syscalls
::sockopt
::set_socket_reuseaddr(fd
.as_fd(), value
)
60 /// `setsockopt(fd, SOL_SOCKET, SO_BROADCAST, broadcast)`
63 /// - [POSIX `setsockopt`]
64 /// - [POSIX `sys/socket.h`]
65 /// - [Linux `setsockopt`]
66 /// - [Linux `socket`]
67 /// - [Winsock2 `setsockopt`]
68 /// - [Winsock2 `SOL_SOCKET` options]
70 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
71 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
72 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
73 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
74 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
75 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
77 #[doc(alias = "SO_BROADCAST")]
78 pub fn set_socket_broadcast
<Fd
: AsFd
>(fd
: Fd
, broadcast
: bool
) -> io
::Result
<()> {
79 backend
::net
::syscalls
::sockopt
::set_socket_broadcast(fd
.as_fd(), broadcast
)
82 /// `getsockopt(fd, SOL_SOCKET, SO_BROADCAST)`
85 /// - [POSIX `getsockopt`]
86 /// - [POSIX `sys/socket.h`]
87 /// - [Linux `getsockopt`]
88 /// - [Linux `socket`]
89 /// - [Winsock2 `getsockopt`]
90 /// - [Winsock2 `SOL_SOCKET` options]
92 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
93 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
94 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
95 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
96 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
97 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
99 #[doc(alias = "SO_BROADCAST")]
100 pub fn get_socket_broadcast
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<bool
> {
101 backend
::net
::syscalls
::sockopt
::get_socket_broadcast(fd
.as_fd())
104 /// `setsockopt(fd, SOL_SOCKET, SO_LINGER, linger)`
107 /// - [POSIX `setsockopt`]
108 /// - [POSIX `sys/socket.h`]
109 /// - [Linux `setsockopt`]
110 /// - [Linux `socket`]
111 /// - [Winsock2 `setsockopt`]
112 /// - [Winsock2 `SOL_SOCKET` options]
114 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
115 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
116 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
117 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
118 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
119 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
121 #[doc(alias = "SO_LINGER")]
122 pub fn set_socket_linger
<Fd
: AsFd
>(fd
: Fd
, linger
: Option
<Duration
>) -> io
::Result
<()> {
123 backend
::net
::syscalls
::sockopt
::set_socket_linger(fd
.as_fd(), linger
)
126 /// `getsockopt(fd, SOL_SOCKET, SO_LINGER)`
129 /// - [POSIX `getsockopt`]
130 /// - [POSIX `sys/socket.h`]
131 /// - [Linux `getsockopt`]
132 /// - [Linux `socket`]
133 /// - [Winsock2 `getsockopt`]
134 /// - [Winsock2 `SOL_SOCKET` options]
136 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
137 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
138 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
139 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
140 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
141 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
143 #[doc(alias = "SO_LINGER")]
144 pub fn get_socket_linger
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<Option
<Duration
>> {
145 backend
::net
::syscalls
::sockopt
::get_socket_linger(fd
.as_fd())
148 /// `setsockopt(fd, SOL_SOCKET, SO_PASSCRED, passcred)`
151 /// - [Linux `setsockopt`]
152 /// - [Linux `socket`]
154 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
155 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
156 #[cfg(any(target_os = "android", target_os = "linux"))]
158 #[doc(alias = "SO_PASSCRED")]
159 pub fn set_socket_passcred
<Fd
: AsFd
>(fd
: Fd
, passcred
: bool
) -> io
::Result
<()> {
160 backend
::net
::syscalls
::sockopt
::set_socket_passcred(fd
.as_fd(), passcred
)
163 /// `getsockopt(fd, SOL_SOCKET, SO_PASSCRED)`
166 /// - [Linux `getsockopt`]
167 /// - [Linux `socket`]
169 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
170 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
171 #[cfg(any(target_os = "android", target_os = "linux"))]
173 #[doc(alias = "SO_PASSCRED")]
174 pub fn get_socket_passcred
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<bool
> {
175 backend
::net
::syscalls
::sockopt
::get_socket_passcred(fd
.as_fd())
178 /// `setsockopt(fd, SOL_SOCKET, id, timeout)`—Set the sending
179 /// or receiving timeout.
182 /// - [POSIX `setsockopt`]
183 /// - [POSIX `sys/socket.h`]
184 /// - [Linux `setsockopt`]
185 /// - [Linux `socket`]
186 /// - [Winsock2 `setsockopt`]
187 /// - [Winsock2 `SOL_SOCKET` options]
189 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
190 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
191 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
192 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
193 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
194 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
196 #[doc(alias = "SO_RCVTIMEO")]
197 #[doc(alias = "SO_SNDTIMEO")]
198 pub fn set_socket_timeout
<Fd
: AsFd
>(
201 timeout
: Option
<Duration
>,
202 ) -> io
::Result
<()> {
203 backend
::net
::syscalls
::sockopt
::set_socket_timeout(fd
.as_fd(), id
, timeout
)
206 /// `getsockopt(fd, SOL_SOCKET, id)`—Get the sending or receiving timeout.
209 /// - [POSIX `getsockopt`]
210 /// - [POSIX `sys/socket.h`]
211 /// - [Linux `getsockopt`]
212 /// - [Linux `socket`]
213 /// - [Winsock2 `getsockopt`]
214 /// - [Winsock2 `SOL_SOCKET` options]
216 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
217 /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
218 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
219 /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
220 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
221 /// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
223 #[doc(alias = "SO_RCVTIMEO")]
224 #[doc(alias = "SO_SNDTIMEO")]
225 pub fn get_socket_timeout
<Fd
: AsFd
>(fd
: Fd
, id
: Timeout
) -> io
::Result
<Option
<Duration
>> {
226 backend
::net
::syscalls
::sockopt
::get_socket_timeout(fd
.as_fd(), id
)
229 /// `setsockopt(fd, IPPROTO_IP, IP_TTL, ttl)`
232 /// - [POSIX `setsockopt`]
233 /// - [POSIX `netinet/in.h`]
234 /// - [Linux `setsockopt`]
236 /// - [Winsock2 `setsockopt`]
237 /// - [Winsock2 `IPPROTO_IP` options]
239 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
240 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
241 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
242 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
243 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
245 #[doc(alias = "IP_TTL")]
246 pub fn set_ip_ttl
<Fd
: AsFd
>(fd
: Fd
, ttl
: u32) -> io
::Result
<()> {
247 backend
::net
::syscalls
::sockopt
::set_ip_ttl(fd
.as_fd(), ttl
)
250 /// `getsockopt(fd, IPPROTO_IP, IP_TTL)`
253 /// - [POSIX `getsockopt`]
254 /// - [POSIX `netinet/in.h`]
255 /// - [Linux `getsockopt`]
257 /// - [Winsock2 `getsockopt`]
258 /// - [Winsock2 `IPPROTO_IPV6` options]
260 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
261 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
262 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
263 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
264 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
265 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
267 #[doc(alias = "IP_TTL")]
268 pub fn get_ip_ttl
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<u32> {
269 backend
::net
::syscalls
::sockopt
::get_ip_ttl(fd
.as_fd())
272 /// `setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, only_v6)`
275 /// - [POSIX `setsockopt`]
276 /// - [POSIX `netinet/in.h`]
277 /// - [Linux `setsockopt`]
279 /// - [Winsock2 `setsockopt`]
280 /// - [Winsock2 `IPPROTO_IPV6` options]
282 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
283 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
284 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
285 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
286 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
287 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
289 #[doc(alias = "IPV6_V6ONLY")]
290 pub fn set_ipv6_v6only
<Fd
: AsFd
>(fd
: Fd
, only_v6
: bool
) -> io
::Result
<()> {
291 backend
::net
::syscalls
::sockopt
::set_ipv6_v6only(fd
.as_fd(), only_v6
)
294 /// `getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY)`
297 /// - [POSIX `getsockopt`]
298 /// - [POSIX `netinet/in.h`]
299 /// - [Linux `getsockopt`]
301 /// - [Winsock2 `getsockopt`]
302 /// - [Winsock2 `IPPROTO_IPV6` options]
304 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
305 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
306 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
307 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
308 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
309 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
311 #[doc(alias = "IPV6_V6ONLY")]
312 pub fn get_ipv6_v6only
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<bool
> {
313 backend
::net
::syscalls
::sockopt
::get_ipv6_v6only(fd
.as_fd())
316 /// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, multicast_loop)`
319 /// - [POSIX `setsockopt`]
320 /// - [POSIX `netinet/in.h`]
321 /// - [Linux `setsockopt`]
323 /// - [Winsock2 `setsockopt`]
324 /// - [Winsock2 `IPPROTO_IP` options]
326 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
327 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
328 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
329 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
330 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
331 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
333 #[doc(alias = "IP_MULTICAST_LOOP")]
334 pub fn set_ip_multicast_loop
<Fd
: AsFd
>(fd
: Fd
, multicast_loop
: bool
) -> io
::Result
<()> {
335 backend
::net
::syscalls
::sockopt
::set_ip_multicast_loop(fd
.as_fd(), multicast_loop
)
338 /// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP)`
341 /// - [POSIX `getsockopt`]
342 /// - [POSIX `netinet/in.h`]
343 /// - [Linux `getsockopt`]
345 /// - [Winsock2 `getsockopt`]
346 /// - [Winsock2 `IPPROTO_IP` options]
348 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
349 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
350 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
351 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
352 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
353 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
355 #[doc(alias = "IP_MULTICAST_LOOP")]
356 pub fn get_ip_multicast_loop
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<bool
> {
357 backend
::net
::syscalls
::sockopt
::get_ip_multicast_loop(fd
.as_fd())
360 /// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, multicast_ttl)`
363 /// - [POSIX `setsockopt`]
364 /// - [POSIX `netinet/in.h`]
365 /// - [Linux `setsockopt`]
367 /// - [Winsock2 `setsockopt`]
368 /// - [Winsock2 `IPPROTO_IP` options]
370 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
371 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
372 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
373 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
374 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
375 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
377 #[doc(alias = "IP_MULTICAST_TTL")]
378 pub fn set_ip_multicast_ttl
<Fd
: AsFd
>(fd
: Fd
, multicast_ttl
: u32) -> io
::Result
<()> {
379 backend
::net
::syscalls
::sockopt
::set_ip_multicast_ttl(fd
.as_fd(), multicast_ttl
)
382 /// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL)`
385 /// - [POSIX `getsockopt`]
386 /// - [POSIX `netinet/in.h`]
387 /// - [Linux `getsockopt`]
389 /// - [Winsock2 `getsockopt`]
390 /// - [Winsock2 `IPPROTO_IP` options]
392 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
393 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
394 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
395 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
396 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
397 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
399 #[doc(alias = "IP_MULTICAST_TTL")]
400 pub fn get_ip_multicast_ttl
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<u32> {
401 backend
::net
::syscalls
::sockopt
::get_ip_multicast_ttl(fd
.as_fd())
404 /// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, multicast_loop)`
407 /// - [POSIX `setsockopt`]
408 /// - [POSIX `netinet/in.h`]
409 /// - [Linux `setsockopt`]
411 /// - [Winsock2 `setsockopt`]
412 /// - [Winsock2 `IPPROTO_IPV6` options]
414 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
415 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
416 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
417 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
418 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
419 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
421 #[doc(alias = "IPV6_MULTICAST_LOOP")]
422 pub fn set_ipv6_multicast_loop
<Fd
: AsFd
>(fd
: Fd
, multicast_loop
: bool
) -> io
::Result
<()> {
423 backend
::net
::syscalls
::sockopt
::set_ipv6_multicast_loop(fd
.as_fd(), multicast_loop
)
426 /// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP)`
429 /// - [POSIX `getsockopt`]
430 /// - [POSIX `netinet/in.h`]
431 /// - [Linux `getsockopt`]
433 /// - [Winsock2 `getsockopt`]
434 /// - [Winsock2 `IPPROTO_IPV6` options]
436 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
437 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
438 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
439 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
440 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
441 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
443 #[doc(alias = "IPV6_MULTICAST_LOOP")]
444 pub fn get_ipv6_multicast_loop
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<bool
> {
445 backend
::net
::syscalls
::sockopt
::get_ipv6_multicast_loop(fd
.as_fd())
448 /// `setsockopt(fd, IPPROTO_IP, IPV6_MULTICAST_HOPS, multicast_hops)`
451 /// - [POSIX `setsockopt`]
452 /// - [POSIX `netinet/in.h`]
453 /// - [Linux `setsockopt`]
455 /// - [Winsock2 `setsockopt`]
456 /// - [Winsock2 `IPPROTO_IPV6` options]
458 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
459 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
460 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
461 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
462 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
463 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
465 #[doc(alias = "IP_MULTICAST_TTL")]
466 pub fn set_ipv6_multicast_hops
<Fd
: AsFd
>(fd
: Fd
, multicast_hops
: u32) -> io
::Result
<()> {
467 backend
::net
::syscalls
::sockopt
::set_ipv6_multicast_hops(fd
.as_fd(), multicast_hops
)
470 /// `getsockopt(fd, IPPROTO_IP, IPV6_MULTICAST_HOPS)`
473 /// - [POSIX `getsockopt`]
474 /// - [POSIX `netinet/in.h`]
475 /// - [Linux `getsockopt`]
477 /// - [Winsock2 `getsockopt`]
478 /// - [Winsock2 `IPPROTO_IPV6` options]
480 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
481 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
482 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
483 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
484 /// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
485 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
487 #[doc(alias = "IP_MULTICAST_TTL")]
488 pub fn get_ipv6_multicast_hops
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<u32> {
489 backend
::net
::syscalls
::sockopt
::get_ipv6_multicast_hops(fd
.as_fd())
492 /// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, interface)`
495 /// - [POSIX `setsockopt`]
496 /// - [POSIX `netinet/in.h`]
497 /// - [Linux `setsockopt`]
499 /// - [Winsock2 `setsockopt`]
500 /// - [Winsock2 `IPPROTO_IP` options]
502 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
503 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
504 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
505 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
506 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
507 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
509 #[doc(alias = "IP_ADD_MEMBERSHIP")]
510 pub fn set_ip_add_membership
<Fd
: AsFd
>(
512 multiaddr
: &Ipv4Addr
,
513 interface
: &Ipv4Addr
,
514 ) -> io
::Result
<()> {
515 backend
::net
::syscalls
::sockopt
::set_ip_add_membership(fd
.as_fd(), multiaddr
, interface
)
518 /// `setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, multiaddr, interface)`
520 /// `IPV6_ADD_MEMBERSHIP` is the same as `IPV6_JOIN_GROUP` in POSIX.
523 /// - [POSIX `setsockopt`]
524 /// - [POSIX `netinet/in.h`]
525 /// - [Linux `setsockopt`]
527 /// - [Winsock2 `setsockopt`]
528 /// - [Winsock2 `IPPROTO_IPV6` options]
530 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
531 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
532 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
533 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
534 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
535 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
537 #[doc(alias = "IPV6_JOIN_GROUP")]
538 #[doc(alias = "IPV6_ADD_MEMBERSHIP")]
539 pub fn set_ipv6_add_membership
<Fd
: AsFd
>(
541 multiaddr
: &Ipv6Addr
,
543 ) -> io
::Result
<()> {
544 backend
::net
::syscalls
::sockopt
::set_ipv6_add_membership(fd
.as_fd(), multiaddr
, interface
)
547 /// `setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, multiaddr, interface)`
550 /// - [POSIX `setsockopt`]
551 /// - [POSIX `netinet/in.h`]
552 /// - [Linux `setsockopt`]
554 /// - [Winsock2 `setsockopt`]
555 /// - [Winsock2 `IPPROTO_IP` options]
557 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
558 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
559 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
560 /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html
561 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
562 /// [Winsock2 `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
564 #[doc(alias = "IP_DROP_MEMBERSHIP")]
565 pub fn set_ip_drop_membership
<Fd
: AsFd
>(
567 multiaddr
: &Ipv4Addr
,
568 interface
: &Ipv4Addr
,
569 ) -> io
::Result
<()> {
570 backend
::net
::syscalls
::sockopt
::set_ip_drop_membership(fd
.as_fd(), multiaddr
, interface
)
573 /// `setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, multiaddr, interface)`
575 /// `IPV6_DROP_MEMBERSHIP` is the same as `IPV6_LEAVE_GROUP` in POSIX.
578 /// - [POSIX `setsockopt`]
579 /// - [POSIX `netinet/in.h`]
580 /// - [Linux `setsockopt`]
582 /// - [Winsock2 `setsockopt`]
583 /// - [Winsock2 `IPPROTO_IPV6` options]
585 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
586 /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
587 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
588 /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
589 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
590 /// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
592 #[doc(alias = "IPV6_LEAVE_GROUP")]
593 #[doc(alias = "IPV6_DROP_MEMBERSHIP")]
594 pub fn set_ipv6_drop_membership
<Fd
: AsFd
>(
596 multiaddr
: &Ipv6Addr
,
598 ) -> io
::Result
<()> {
599 backend
::net
::syscalls
::sockopt
::set_ipv6_drop_membership(fd
.as_fd(), multiaddr
, interface
)
602 /// `setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, nodelay)`
605 /// - [POSIX `setsockopt`]
606 /// - [POSIX `netinet/tcp.h`]
607 /// - [Linux `setsockopt`]
609 /// - [Winsock2 `setsockopt`]
610 /// - [Winsock2 `IPPROTO_TCP` options]
612 /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
613 /// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
614 /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
615 /// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
616 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
617 /// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
619 #[doc(alias = "TCP_NODELAY")]
620 pub fn set_tcp_nodelay
<Fd
: AsFd
>(fd
: Fd
, nodelay
: bool
) -> io
::Result
<()> {
621 backend
::net
::syscalls
::sockopt
::set_tcp_nodelay(fd
.as_fd(), nodelay
)
624 /// `getsockopt(fd, IPPROTO_TCP, TCP_NODELAY)`
627 /// - [POSIX `getsockopt`]
628 /// - [POSIX `netinet/tcp.h`]
629 /// - [Linux `getsockopt`]
631 /// - [Winsock2 `getsockopt`]
632 /// - [Winsock2 `IPPROTO_TCP` options]
634 /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
635 /// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
636 /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
637 /// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
638 /// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
639 /// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
641 #[doc(alias = "TCP_NODELAY")]
642 pub fn get_tcp_nodelay
<Fd
: AsFd
>(fd
: Fd
) -> io
::Result
<bool
> {
643 backend
::net
::syscalls
::sockopt
::get_tcp_nodelay(fd
.as_fd())