#![doc(alias = "getsockopt")]
#![doc(alias = "setsockopt")]
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::clockid::ClockId;
#[cfg(target_os = "linux")]
use crate::net::xdp::{XdpMmapOffsets, XdpOptionsFlags, XdpStatistics, XdpUmemReg};
#[cfg(not(any(
apple,
windows,
target_os = "aix",
target_os = "cygwin",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "espidf",
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "vita",
)))]
use crate::net::AddressFamily;
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "openbsd",
target_os = "redox",
target_env = "newlib"
))]
use crate::net::Protocol;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
use crate::net::SocketAddrV4;
#[cfg(linux_kernel)]
use crate::net::SocketAddrV6;
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::net::TxTimeFlags;
use crate::net::{Ipv4Addr, Ipv6Addr, SocketType};
use crate::{backend, io};
#[cfg(feature = "alloc")]
#[cfg(any(
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos"
))]
use alloc::string::String;
use backend::c;
use backend::fd::AsFd;
use core::time::Duration;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(u32)]
pub enum Timeout {
Recv = c::SO_RCVTIMEO as _,
Send = c::SO_SNDTIMEO as _,
}
#[cfg(linux_kernel)]
pub type RawIpv4PathMtuDiscovery = i32;
#[cfg(linux_kernel)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct Ipv4PathMtuDiscovery(RawIpv4PathMtuDiscovery);
#[cfg(linux_kernel)]
impl Ipv4PathMtuDiscovery {
#[doc(alias = "IP_PMTUDISC_DONT")]
pub const DONT: Self = Self(c::IP_PMTUDISC_DONT as _);
#[doc(alias = "IP_PMTUDISC_WANT")]
pub const WANT: Self = Self(c::IP_PMTUDISC_WANT as _);
#[doc(alias = "IP_PMTUDISC_DO")]
pub const DO: Self = Self(c::IP_PMTUDISC_DO as _);
#[doc(alias = "IP_PMTUDISC_PROBE")]
pub const PROBE: Self = Self(c::IP_PMTUDISC_PROBE as _);
#[doc(alias = "IP_PMTUDISC_INTERFACE")]
pub const INTERFACE: Self = Self(c::IP_PMTUDISC_INTERFACE as _);
#[doc(alias = "IP_PMTUDISC_OMIT")]
pub const OMIT: Self = Self(c::IP_PMTUDISC_OMIT as _);
#[inline]
pub const fn from_raw(raw: RawIpv4PathMtuDiscovery) -> Self {
Self(raw)
}
#[inline]
pub const fn as_raw(self) -> RawIpv4PathMtuDiscovery {
self.0
}
}
#[cfg(linux_kernel)]
pub type RawIpv6PathMtuDiscovery = i32;
#[cfg(linux_kernel)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct Ipv6PathMtuDiscovery(RawIpv6PathMtuDiscovery);
#[cfg(linux_kernel)]
impl Ipv6PathMtuDiscovery {
#[doc(alias = "IPV6_PMTUDISC_DONT")]
pub const DONT: Self = Self(c::IPV6_PMTUDISC_DONT as _);
#[doc(alias = "IPV6_PMTUDISC_WANT")]
pub const WANT: Self = Self(c::IPV6_PMTUDISC_WANT as _);
#[doc(alias = "IPV6_PMTUDISC_DO")]
pub const DO: Self = Self(c::IPV6_PMTUDISC_DO as _);
#[doc(alias = "IPV6_PMTUDISC_PROBE")]
pub const PROBE: Self = Self(c::IPV6_PMTUDISC_PROBE as _);
#[doc(alias = "IPV6_PMTUDISC_INTERFACE")]
pub const INTERFACE: Self = Self(c::IPV6_PMTUDISC_INTERFACE as _);
#[doc(alias = "IPV6_PMTUDISC_OMIT")]
pub const OMIT: Self = Self(c::IPV6_PMTUDISC_OMIT as _);
#[inline]
pub const fn from_raw(raw: RawIpv6PathMtuDiscovery) -> Self {
Self(raw)
}
#[inline]
pub const fn as_raw(self) -> RawIpv6PathMtuDiscovery {
self.0
}
}
#[inline]
#[doc(alias = "SO_TYPE")]
pub fn socket_type<Fd: AsFd>(fd: Fd) -> io::Result<SocketType> {
backend::net::sockopt::socket_type(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_REUSEADDR")]
pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_reuseaddr(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_REUSEADDR")]
pub fn socket_reuseaddr<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_reuseaddr(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_BROADCAST")]
pub fn set_socket_broadcast<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_broadcast(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_BROADCAST")]
pub fn socket_broadcast<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_broadcast(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_LINGER")]
pub fn set_socket_linger<Fd: AsFd>(fd: Fd, value: Option<Duration>) -> io::Result<()> {
backend::net::sockopt::set_socket_linger(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_LINGER")]
pub fn socket_linger<Fd: AsFd>(fd: Fd) -> io::Result<Option<Duration>> {
backend::net::sockopt::socket_linger(fd.as_fd())
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "SO_PASSCRED")]
pub fn set_socket_passcred<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_passcred(fd.as_fd(), value)
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "SO_PASSCRED")]
pub fn socket_passcred<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_passcred(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_RCVTIMEO")]
#[doc(alias = "SO_SNDTIMEO")]
pub fn set_socket_timeout<Fd: AsFd>(
fd: Fd,
id: Timeout,
value: Option<Duration>,
) -> io::Result<()> {
backend::net::sockopt::set_socket_timeout(fd.as_fd(), id, value)
}
#[inline]
#[doc(alias = "SO_RCVTIMEO")]
#[doc(alias = "SO_SNDTIMEO")]
pub fn socket_timeout<Fd: AsFd>(fd: Fd, id: Timeout) -> io::Result<Option<Duration>> {
backend::net::sockopt::socket_timeout(fd.as_fd(), id)
}
#[inline]
#[doc(alias = "SO_ERROR")]
pub fn socket_error<Fd: AsFd>(fd: Fd) -> io::Result<Result<(), io::Errno>> {
backend::net::sockopt::socket_error(fd.as_fd())
}
#[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
#[doc(alias = "SO_NOSIGPIPE")]
#[inline]
pub fn socket_nosigpipe<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_nosigpipe(fd.as_fd())
}
#[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
#[doc(alias = "SO_NOSIGPIPE")]
#[inline]
pub fn set_socket_nosigpipe<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_nosigpipe(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_KEEPALIVE")]
pub fn set_socket_keepalive<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_keepalive(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_KEEPALIVE")]
pub fn socket_keepalive<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_keepalive(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_RCVBUF")]
pub fn set_socket_recv_buffer_size<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
backend::net::sockopt::set_socket_recv_buffer_size(fd.as_fd(), value)
}
#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "redox"))]
#[inline]
#[doc(alias = "SO_RCVBUFFORCE")]
pub fn set_socket_recv_buffer_size_force<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
backend::net::sockopt::set_socket_recv_buffer_size_force(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_RCVBUF")]
pub fn socket_recv_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> {
backend::net::sockopt::socket_recv_buffer_size(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_SNDBUF")]
pub fn set_socket_send_buffer_size<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
backend::net::sockopt::set_socket_send_buffer_size(fd.as_fd(), value)
}
#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "redox"))]
#[inline]
#[doc(alias = "SO_SNDBUFFORCE")]
pub fn set_socket_send_buffer_size_force<Fd: AsFd>(fd: Fd, value: usize) -> io::Result<()> {
backend::net::sockopt::set_socket_send_buffer_size_force(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_SNDBUF")]
pub fn socket_send_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> {
backend::net::sockopt::socket_send_buffer_size(fd.as_fd())
}
#[cfg(not(any(
apple,
windows,
target_os = "aix",
target_os = "cygwin",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "espidf",
target_os = "haiku",
target_os = "horizon",
target_os = "hurd",
target_os = "netbsd",
target_os = "nto",
target_os = "vita",
)))]
#[inline]
#[doc(alias = "SO_DOMAIN")]
pub fn socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> {
backend::net::sockopt::socket_domain(fd.as_fd())
}
#[cfg(not(apple))] #[inline]
#[doc(alias = "SO_ACCEPTCONN")]
pub fn socket_acceptconn<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_acceptconn(fd.as_fd())
}
#[inline]
#[doc(alias = "SO_OOBINLINE")]
pub fn set_socket_oobinline<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_oobinline(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "SO_OOBINLINE")]
pub fn socket_oobinline<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_oobinline(fd.as_fd())
}
#[cfg(not(any(solarish, windows, target_os = "cygwin")))]
#[cfg(not(windows))]
#[inline]
#[doc(alias = "SO_REUSEPORT")]
pub fn set_socket_reuseport<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_reuseport(fd.as_fd(), value)
}
#[cfg(not(any(solarish, windows, target_os = "cygwin")))]
#[inline]
#[doc(alias = "SO_REUSEPORT")]
pub fn socket_reuseport<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_reuseport(fd.as_fd())
}
#[cfg(target_os = "freebsd")]
#[inline]
#[doc(alias = "SO_REUSEPORT_LB")]
pub fn set_socket_reuseport_lb<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_socket_reuseport_lb(fd.as_fd(), value)
}
#[cfg(target_os = "freebsd")]
#[inline]
#[doc(alias = "SO_REUSEPORT_LB")]
pub fn socket_reuseport_lb<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::socket_reuseport_lb(fd.as_fd())
}
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "openbsd",
target_os = "redox",
target_env = "newlib"
))]
#[inline]
#[doc(alias = "SO_PROTOCOL")]
pub fn socket_protocol<Fd: AsFd>(fd: Fd) -> io::Result<Option<Protocol>> {
backend::net::sockopt::socket_protocol(fd.as_fd())
}
#[cfg(target_os = "linux")]
#[inline]
#[doc(alias = "SO_COOKIE")]
pub fn socket_cookie<Fd: AsFd>(fd: Fd) -> io::Result<u64> {
backend::net::sockopt::socket_cookie(fd.as_fd())
}
#[cfg(target_os = "linux")]
#[inline]
#[doc(alias = "SO_INCOMING_CPU")]
pub fn socket_incoming_cpu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::socket_incoming_cpu(fd.as_fd())
}
#[cfg(target_os = "linux")]
#[inline]
#[doc(alias = "SO_INCOMING_CPU")]
pub fn set_socket_incoming_cpu<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_socket_incoming_cpu(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IP_TTL")]
pub fn set_ip_ttl<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ip_ttl(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IP_TTL")]
pub fn ip_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ip_ttl(fd.as_fd())
}
#[inline]
#[doc(alias = "IPV6_V6ONLY")]
pub fn set_ipv6_v6only<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ipv6_v6only(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IPV6_V6ONLY")]
pub fn ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ipv6_v6only(fd.as_fd())
}
#[inline]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[doc(alias = "IP_MTU")]
pub fn ip_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ip_mtu(fd.as_fd())
}
#[inline]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[doc(alias = "IPV6_MTU")]
pub fn ipv6_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ipv6_mtu(fd.as_fd())
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IP_MTU_DISCOVER")]
pub fn set_ip_mtu_discover<Fd: AsFd>(fd: Fd, value: Ipv4PathMtuDiscovery) -> io::Result<()> {
backend::net::sockopt::set_ip_mtu_discover(fd.as_fd(), value)
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IP_MTU_DISCOVER")]
pub fn ip_mtu_discover<Fd: AsFd>(fd: Fd) -> io::Result<Ipv4PathMtuDiscovery> {
backend::net::sockopt::ip_mtu_discover(fd.as_fd())
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IPV6_MTU_DISCOVER")]
pub fn set_ipv6_mtu_discover<Fd: AsFd>(fd: Fd, value: Ipv6PathMtuDiscovery) -> io::Result<()> {
backend::net::sockopt::set_ipv6_mtu_discover(fd.as_fd(), value)
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IPV6_MTU_DISCOVER")]
pub fn ipv6_mtu_discover<Fd: AsFd>(fd: Fd) -> io::Result<Ipv6PathMtuDiscovery> {
backend::net::sockopt::ipv6_mtu_discover(fd.as_fd())
}
#[inline]
#[doc(alias = "IP_MULTICAST_IF")]
pub fn set_ip_multicast_if<Fd: AsFd>(fd: Fd, value: &Ipv4Addr) -> io::Result<()> {
backend::net::sockopt::set_ip_multicast_if(fd.as_fd(), value)
}
#[cfg(any(
apple,
freebsdlike,
linux_like,
target_os = "fuchsia",
target_os = "openbsd"
))]
#[inline]
#[doc(alias = "IP_MULTICAST_IF")]
pub fn set_ip_multicast_if_with_ifindex<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
address: &Ipv4Addr,
ifindex: u32,
) -> io::Result<()> {
backend::net::sockopt::set_ip_multicast_if_with_ifindex(fd.as_fd(), multiaddr, address, ifindex)
}
#[inline]
#[doc(alias = "IP_MULTICAST_IF")]
pub fn ip_multicast_if<Fd: AsFd>(fd: Fd) -> io::Result<Ipv4Addr> {
backend::net::sockopt::ip_multicast_if(fd.as_fd())
}
#[inline]
#[doc(alias = "IPV6_MULTICAST_IF")]
pub fn set_ipv6_multicast_if<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ipv6_multicast_if(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IPV6_MULTICAST_IF")]
pub fn ipv6_multicast_if<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ipv6_multicast_if(fd.as_fd())
}
#[inline]
#[doc(alias = "IP_MULTICAST_LOOP")]
pub fn set_ip_multicast_loop<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ip_multicast_loop(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IP_MULTICAST_LOOP")]
pub fn ip_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ip_multicast_loop(fd.as_fd())
}
#[inline]
#[doc(alias = "IP_MULTICAST_TTL")]
pub fn set_ip_multicast_ttl<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ip_multicast_ttl(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IP_MULTICAST_TTL")]
pub fn ip_multicast_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ip_multicast_ttl(fd.as_fd())
}
#[inline]
#[doc(alias = "IPV6_MULTICAST_LOOP")]
pub fn set_ipv6_multicast_loop<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ipv6_multicast_loop(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IPV6_MULTICAST_LOOP")]
pub fn ipv6_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ipv6_multicast_loop(fd.as_fd())
}
#[inline]
#[doc(alias = "IPV6_UNICAST_HOPS")]
pub fn ipv6_unicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u8> {
backend::net::sockopt::ipv6_unicast_hops(fd.as_fd())
}
#[inline]
#[doc(alias = "IPV6_UNICAST_HOPS")]
pub fn set_ipv6_unicast_hops<Fd: AsFd>(fd: Fd, value: Option<u8>) -> io::Result<()> {
backend::net::sockopt::set_ipv6_unicast_hops(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IPV6_MULTICAST_HOPS")]
pub fn set_ipv6_multicast_hops<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ipv6_multicast_hops(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "IPV6_MULTICAST_HOPS")]
pub fn ipv6_multicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ipv6_multicast_hops(fd.as_fd())
}
#[inline]
#[doc(alias = "IP_ADD_MEMBERSHIP")]
pub fn set_ip_add_membership<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
interface: &Ipv4Addr,
) -> io::Result<()> {
backend::net::sockopt::set_ip_add_membership(fd.as_fd(), multiaddr, interface)
}
#[cfg(any(
apple,
freebsdlike,
linux_like,
target_os = "fuchsia",
target_os = "openbsd"
))]
#[inline]
#[doc(alias = "IP_ADD_MEMBERSHIP")]
pub fn set_ip_add_membership_with_ifindex<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
address: &Ipv4Addr,
ifindex: u32,
) -> io::Result<()> {
backend::net::sockopt::set_ip_add_membership_with_ifindex(
fd.as_fd(),
multiaddr,
address,
ifindex,
)
}
#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))]
#[inline]
#[doc(alias = "IP_ADD_SOURCE_MEMBERSHIP")]
pub fn set_ip_add_source_membership<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
interface: &Ipv4Addr,
sourceaddr: &Ipv4Addr,
) -> io::Result<()> {
backend::net::sockopt::set_ip_add_source_membership(
fd.as_fd(),
multiaddr,
interface,
sourceaddr,
)
}
#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))]
#[inline]
#[doc(alias = "IP_DROP_SOURCE_MEMBERSHIP")]
pub fn set_ip_drop_source_membership<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
interface: &Ipv4Addr,
sourceaddr: &Ipv4Addr,
) -> io::Result<()> {
backend::net::sockopt::set_ip_drop_source_membership(
fd.as_fd(),
multiaddr,
interface,
sourceaddr,
)
}
#[inline]
#[doc(alias = "IPV6_JOIN_GROUP")]
#[doc(alias = "IPV6_ADD_MEMBERSHIP")]
pub fn set_ipv6_add_membership<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv6Addr,
interface: u32,
) -> io::Result<()> {
backend::net::sockopt::set_ipv6_add_membership(fd.as_fd(), multiaddr, interface)
}
#[inline]
#[doc(alias = "IP_DROP_MEMBERSHIP")]
pub fn set_ip_drop_membership<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
interface: &Ipv4Addr,
) -> io::Result<()> {
backend::net::sockopt::set_ip_drop_membership(fd.as_fd(), multiaddr, interface)
}
#[cfg(any(
apple,
freebsdlike,
linux_like,
target_os = "fuchsia",
target_os = "openbsd"
))]
#[inline]
#[doc(alias = "IP_DROP_MEMBERSHIP")]
pub fn set_ip_drop_membership_with_ifindex<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv4Addr,
address: &Ipv4Addr,
ifindex: u32,
) -> io::Result<()> {
backend::net::sockopt::set_ip_drop_membership_with_ifindex(
fd.as_fd(),
multiaddr,
address,
ifindex,
)
}
#[inline]
#[doc(alias = "IPV6_LEAVE_GROUP")]
#[doc(alias = "IPV6_DROP_MEMBERSHIP")]
pub fn set_ipv6_drop_membership<Fd: AsFd>(
fd: Fd,
multiaddr: &Ipv6Addr,
interface: u32,
) -> io::Result<()> {
backend::net::sockopt::set_ipv6_drop_membership(fd.as_fd(), multiaddr, interface)
}
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "haiku",
target_os = "nto",
target_env = "newlib"
))]
#[inline]
#[doc(alias = "IP_TOS")]
pub fn set_ip_tos<Fd: AsFd>(fd: Fd, value: u8) -> io::Result<()> {
backend::net::sockopt::set_ip_tos(fd.as_fd(), value)
}
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "haiku",
target_os = "nto",
target_env = "newlib"
))]
#[inline]
#[doc(alias = "IP_TOS")]
pub fn ip_tos<Fd: AsFd>(fd: Fd) -> io::Result<u8> {
backend::net::sockopt::ip_tos(fd.as_fd())
}
#[cfg(any(
apple,
linux_like,
target_os = "cygwin",
target_os = "freebsd",
target_os = "fuchsia",
))]
#[inline]
#[doc(alias = "IP_RECVTOS")]
pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ip_recvtos(fd.as_fd(), value)
}
#[cfg(any(
apple,
linux_like,
target_os = "cygwin",
target_os = "freebsd",
target_os = "fuchsia",
))]
#[inline]
#[doc(alias = "IP_RECVTOS")]
pub fn ip_recvtos<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ip_recvtos(fd.as_fd())
}
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
#[inline]
#[doc(alias = "IPV6_RECVTCLASS")]
pub fn set_ipv6_recvtclass<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ipv6_recvtclass(fd.as_fd(), value)
}
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
#[inline]
#[doc(alias = "IPV6_RECVTCLASS")]
pub fn ipv6_recvtclass<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ipv6_recvtclass(fd.as_fd())
}
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "IP_FREEBIND")]
pub fn set_ip_freebind<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ip_freebind(fd.as_fd(), value)
}
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "IP_FREEBIND")]
pub fn ip_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ip_freebind(fd.as_fd())
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IPV6_FREEBIND")]
pub fn set_ipv6_freebind<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_ipv6_freebind(fd.as_fd(), value)
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IPV6_FREEBIND")]
pub fn ipv6_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ipv6_freebind(fd.as_fd())
}
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "SO_ORIGINAL_DST")]
pub fn ip_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV4> {
backend::net::sockopt::ip_original_dst(fd.as_fd())
}
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IP6T_SO_ORIGINAL_DST")]
pub fn ipv6_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV6> {
backend::net::sockopt::ipv6_original_dst(fd.as_fd())
}
#[cfg(not(any(
solarish,
windows,
target_os = "espidf",
target_os = "haiku",
target_os = "horizon",
target_os = "redox",
target_os = "vita"
)))]
#[inline]
#[doc(alias = "IPV6_TCLASS")]
pub fn set_ipv6_tclass<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ipv6_tclass(fd.as_fd(), value)
}
#[cfg(not(any(
solarish,
windows,
target_os = "espidf",
target_os = "haiku",
target_os = "horizon",
target_os = "redox",
target_os = "vita"
)))]
#[inline]
#[doc(alias = "IPV6_TCLASS")]
pub fn ipv6_tclass<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ipv6_tclass(fd.as_fd())
}
#[inline]
#[doc(alias = "TCP_NODELAY")]
pub fn set_tcp_nodelay<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_tcp_nodelay(fd.as_fd(), value)
}
#[inline]
#[doc(alias = "TCP_NODELAY")]
pub fn tcp_nodelay<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::tcp_nodelay(fd.as_fd())
}
#[cfg(not(any(
target_os = "haiku",
target_os = "nto",
target_os = "openbsd",
target_os = "redox"
)))]
#[inline]
#[doc(alias = "TCP_KEEPCNT")]
pub fn set_tcp_keepcnt<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_tcp_keepcnt(fd.as_fd(), value)
}
#[cfg(not(any(
target_os = "haiku",
target_os = "nto",
target_os = "openbsd",
target_os = "redox"
)))]
#[inline]
#[doc(alias = "TCP_KEEPCNT")]
pub fn tcp_keepcnt<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::tcp_keepcnt(fd.as_fd())
}
#[cfg(not(any(target_os = "haiku", target_os = "nto", target_os = "openbsd")))]
#[inline]
#[doc(alias = "TCP_KEEPIDLE")]
pub fn set_tcp_keepidle<Fd: AsFd>(fd: Fd, value: Duration) -> io::Result<()> {
backend::net::sockopt::set_tcp_keepidle(fd.as_fd(), value)
}
#[cfg(not(any(target_os = "haiku", target_os = "nto", target_os = "openbsd")))]
#[inline]
#[doc(alias = "TCP_KEEPIDLE")]
pub fn tcp_keepidle<Fd: AsFd>(fd: Fd) -> io::Result<Duration> {
backend::net::sockopt::tcp_keepidle(fd.as_fd())
}
#[cfg(not(any(
target_os = "haiku",
target_os = "nto",
target_os = "openbsd",
target_os = "redox"
)))]
#[inline]
#[doc(alias = "TCP_KEEPINTVL")]
pub fn set_tcp_keepintvl<Fd: AsFd>(fd: Fd, value: Duration) -> io::Result<()> {
backend::net::sockopt::set_tcp_keepintvl(fd.as_fd(), value)
}
#[cfg(not(any(
target_os = "haiku",
target_os = "nto",
target_os = "openbsd",
target_os = "redox"
)))]
#[inline]
#[doc(alias = "TCP_KEEPINTVL")]
pub fn tcp_keepintvl<Fd: AsFd>(fd: Fd) -> io::Result<Duration> {
backend::net::sockopt::tcp_keepintvl(fd.as_fd())
}
#[cfg(any(linux_like, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_USER_TIMEOUT")]
pub fn set_tcp_user_timeout<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_tcp_user_timeout(fd.as_fd(), value)
}
#[cfg(any(linux_like, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_USER_TIMEOUT")]
pub fn tcp_user_timeout<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::tcp_user_timeout(fd.as_fd())
}
#[cfg(any(linux_like, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_QUICKACK")]
pub fn set_tcp_quickack<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_tcp_quickack(fd.as_fd(), value)
}
#[cfg(any(linux_like, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_QUICKACK")]
pub fn tcp_quickack<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::tcp_quickack(fd.as_fd())
}
#[cfg(any(
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos"
))]
#[inline]
#[doc(alias = "TCP_CONGESTION")]
pub fn set_tcp_congestion<Fd: AsFd>(fd: Fd, value: &str) -> io::Result<()> {
backend::net::sockopt::set_tcp_congestion(fd.as_fd(), value)
}
#[cfg(feature = "alloc")]
#[cfg(any(
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos"
))]
#[inline]
#[doc(alias = "TCP_CONGESTION")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn tcp_congestion<Fd: AsFd>(fd: Fd) -> io::Result<String> {
backend::net::sockopt::tcp_congestion(fd.as_fd())
}
#[cfg(any(linux_like, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_THIN_LINEAR_TIMEOUTS")]
pub fn set_tcp_thin_linear_timeouts<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_tcp_thin_linear_timeouts(fd.as_fd(), value)
}
#[cfg(any(linux_like, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_THIN_LINEAR_TIMEOUTS")]
pub fn tcp_thin_linear_timeouts<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::tcp_thin_linear_timeouts(fd.as_fd())
}
#[cfg(any(linux_like, solarish, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_CORK")]
pub fn set_tcp_cork<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::sockopt::set_tcp_cork(fd.as_fd(), value)
}
#[cfg(any(linux_like, solarish, target_os = "fuchsia"))]
#[inline]
#[doc(alias = "TCP_CORK")]
pub fn tcp_cork<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::tcp_cork(fd.as_fd())
}
#[cfg(linux_kernel)]
#[doc(alias = "SO_PEERCRED")]
pub fn socket_peercred<Fd: AsFd>(fd: Fd) -> io::Result<super::UCred> {
backend::net::sockopt::socket_peercred(fd.as_fd())
}
#[cfg(all(target_os = "linux", feature = "time"))]
#[doc(alias = "SO_TXTIME")]
pub fn get_txtime<Fd: AsFd>(fd: Fd) -> io::Result<(ClockId, TxTimeFlags)> {
backend::net::sockopt::get_txtime(fd.as_fd())
}
#[cfg(all(target_os = "linux", feature = "time"))]
#[doc(alias = "SO_TXTIME")]
pub fn set_txtime<Fd: AsFd>(fd: Fd, clockid: ClockId, flags: TxTimeFlags) -> io::Result<()> {
backend::net::sockopt::set_txtime(fd.as_fd(), clockid, flags)
}
#[cfg(target_os = "linux")]
#[doc(alias = "XDP_UMEM_REG")]
pub fn set_xdp_umem_reg<Fd: AsFd>(fd: Fd, value: XdpUmemReg) -> io::Result<()> {
backend::net::sockopt::set_xdp_umem_reg(fd.as_fd(), value)
}
#[cfg(target_os = "linux")]
#[doc(alias = "XDP_UMEM_FILL_RING")]
pub fn set_xdp_umem_fill_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_xdp_umem_fill_ring_size(fd.as_fd(), value)
}
#[cfg(target_os = "linux")]
#[doc(alias = "XDP_UMEM_COMPLETION_RING")]
pub fn set_xdp_umem_completion_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_xdp_umem_completion_ring_size(fd.as_fd(), value)
}
#[cfg(target_os = "linux")]
#[doc(alias = "XDP_TX_RING")]
pub fn set_xdp_tx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_xdp_tx_ring_size(fd.as_fd(), value)
}
#[cfg(target_os = "linux")]
#[doc(alias = "XDP_RX_RING")]
pub fn set_xdp_rx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_xdp_rx_ring_size(fd.as_fd(), value)
}
#[cfg(linux_raw_dep)]
#[doc(alias = "XDP_MMAP_OFFSETS")]
pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
backend::net::sockopt::xdp_mmap_offsets(fd.as_fd())
}
#[cfg(linux_raw_dep)]
#[doc(alias = "XDP_STATISTICS")]
pub fn xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> {
backend::net::sockopt::xdp_statistics(fd.as_fd())
}
#[cfg(target_os = "linux")]
#[doc(alias = "XDP_OPTIONS")]
pub fn xdp_options<Fd: AsFd>(fd: Fd) -> io::Result<XdpOptionsFlags> {
backend::net::sockopt::xdp_options(fd.as_fd())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sizes() {
use c::c_int;
assert_eq_size!(Timeout, c_int);
}
}