summaryrefslogtreecommitdiff
path: root/src/sys/socket/sockopt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/socket/sockopt.rs')
-rw-r--r--src/sys/socket/sockopt.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index fcb4be81..3ad139ad 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -17,6 +17,7 @@ use std::os::unix::ffi::OsStrExt;
// Constants
// TCP_CA_NAME_MAX isn't defined in user space include files
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
+#[cfg(feature = "net")]
const TCP_CA_NAME_MAX: usize = 16;
/// Helper for implementing `SetSockOpt` for a given socket option. See
@@ -251,7 +252,9 @@ sockopt_impl!(
/// Permits multiple AF_INET or AF_INET6 sockets to be bound to an
/// identical socket address.
ReusePort, Both, libc::SOL_SOCKET, libc::SO_REUSEPORT, bool);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Under most circumstances, TCP sends data when it is presented; when
/// outstanding data has not yet been acknowledged, it gathers small amounts
/// of output to be sent in a single packet once an acknowledgement is
@@ -265,20 +268,28 @@ sockopt_impl!(
/// queued messages for the socket have been successfully sent or the
/// linger timeout has been reached.
Linger, Both, libc::SOL_SOCKET, libc::SO_LINGER, libc::linger);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Join a multicast group
IpAddMembership, SetOnly, libc::IPPROTO_IP, libc::IP_ADD_MEMBERSHIP,
super::IpMembershipRequest);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave a multicast group.
IpDropMembership, SetOnly, libc::IPPROTO_IP, libc::IP_DROP_MEMBERSHIP,
super::IpMembershipRequest);
cfg_if! {
if #[cfg(any(target_os = "android", target_os = "linux"))] {
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Join an IPv6 multicast group.
Ipv6AddMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_ADD_MEMBERSHIP, super::Ipv6MembershipRequest);
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave an IPv6 multicast group.
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_DROP_MEMBERSHIP, super::Ipv6MembershipRequest);
} else if #[cfg(any(target_os = "dragonfly",
@@ -289,26 +300,36 @@ cfg_if! {
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))] {
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Join an IPv6 multicast group.
Ipv6AddMembership, SetOnly, libc::IPPROTO_IPV6,
libc::IPV6_JOIN_GROUP, super::Ipv6MembershipRequest);
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave an IPv6 multicast group.
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6,
libc::IPV6_LEAVE_GROUP, super::Ipv6MembershipRequest);
}
}
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Set or read the time-to-live value of outgoing multicast packets for
/// this socket.
IpMulticastTtl, Both, libc::IPPROTO_IP, libc::IP_MULTICAST_TTL, u8);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Set or read a boolean integer argument that determines whether sent
/// multicast packets should be looped back to the local sockets.
IpMulticastLoop, Both, libc::IPPROTO_IP, libc::IP_MULTICAST_LOOP, bool);
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// If enabled, this boolean option allows binding to an IP address that
/// is nonlocal or does not (yet) exist.
IpFreebind, Both, libc::IPPROTO_IP, libc::IP_FREEBIND, bool);
@@ -347,7 +368,9 @@ sockopt_impl!(
PeerCredentials, GetOnly, libc::SOL_SOCKET, libc::SO_PEERCRED, super::UnixCredentials);
#[cfg(any(target_os = "ios",
target_os = "macos"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Specify the amount of time, in seconds, that the connection must be idle
/// before keepalive probes (if enabled) are sent.
TcpKeepAlive, Both, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, u32);
@@ -356,7 +379,9 @@ sockopt_impl!(
target_os = "freebsd",
target_os = "linux",
target_os = "nacl"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The time (in seconds) the connection needs to remain idle before TCP
/// starts sending keepalive probes
TcpKeepIdle, Both, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, u32);
@@ -372,7 +397,9 @@ cfg_if! {
}
}
#[cfg(not(target_os = "openbsd"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The maximum number of keepalive probes TCP should send before
/// dropping the connection.
TcpKeepCount, Both, libc::IPPROTO_TCP, libc::TCP_KEEPCNT, u32);
@@ -384,11 +411,15 @@ sockopt_impl!(
// Not documented by Linux!
TcpRepair, Both, libc::IPPROTO_TCP, libc::TCP_REPAIR, u32);
#[cfg(not(target_os = "openbsd"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The time (in seconds) between individual keepalive probes.
TcpKeepInterval, Both, libc::IPPROTO_TCP, libc::TCP_KEEPINTVL, u32);
#[cfg(any(target_os = "fuchsia", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Specifies the maximum amount of time in milliseconds that transmitted
/// data may remain unacknowledged before TCP will forcibly close the
/// corresponding connection
@@ -423,7 +454,9 @@ sockopt_impl!(
/// Bind this socket to a particular device like “eth0”.
BindToDevice, Both, libc::SOL_SOCKET, libc::SO_BINDTODEVICE, OsString<[u8; libc::IFNAMSIZ]>);
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[allow(missing_docs)]
// Not documented by Linux!
OriginalDst, GetOnly, libc::SOL_IP, libc::SO_ORIGINAL_DST, libc::sockaddr_in);
@@ -440,16 +473,22 @@ sockopt_impl!(
/// Enable or disable the receiving of the `SO_TIMESTAMPNS` control message.
ReceiveTimestampns, Both, libc::SOL_SOCKET, libc::SO_TIMESTAMPNS, bool);
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Setting this boolean option enables transparent proxying on this socket.
IpTransparent, Both, libc::SOL_IP, libc::IP_TRANSPARENT, bool);
#[cfg(target_os = "openbsd")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Allows the socket to be bound to addresses which are not local to the
/// machine, so it can be used to make a transparent proxy.
BindAny, Both, libc::SOL_SOCKET, libc::SO_BINDANY, bool);
#[cfg(target_os = "freebsd")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Can `bind(2)` to any address, even one not bound to any available
/// network interface in the system.
BindAny, Both, libc::IPPROTO_IP, libc::IP_BINDANY, bool);
@@ -464,7 +503,9 @@ sockopt_impl!(
/// message.
PassCred, Both, libc::SOL_SOCKET, libc::SO_PASSCRED, bool);
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// This option allows the caller to set the TCP congestion control
/// algorithm to be used, on a per-socket basis.
TcpCongestion, Both, libc::IPPROTO_TCP, libc::TCP_CONGESTION, OsString<[u8; TCP_CA_NAME_MAX]>);
@@ -475,7 +516,9 @@ sockopt_impl!(
target_os = "macos",
target_os = "netbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Pass an `IP_PKTINFO` ancillary message that contains a pktinfo
/// structure that supplies some information about the incoming packet.
Ipv4PacketInfo, Both, libc::IPPROTO_IP, libc::IP_PKTINFO, bool);
@@ -488,7 +531,9 @@ sockopt_impl!(
target_os = "netbsd",
target_os = "openbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Set delivery of the `IPV6_PKTINFO` control message on incoming
/// datagrams.
Ipv6RecvPacketInfo, Both, libc::IPPROTO_IPV6, libc::IPV6_RECVPKTINFO, bool);
@@ -499,7 +544,9 @@ sockopt_impl!(
target_os = "netbsd",
target_os = "openbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The `recvmsg(2)` call returns a `struct sockaddr_dl` corresponding to
/// the interface on which the packet was received.
Ipv4RecvIf, Both, libc::IPPROTO_IP, libc::IP_RECVIF, bool);
@@ -510,17 +557,23 @@ sockopt_impl!(
target_os = "netbsd",
target_os = "openbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The `recvmsg(2)` call will return the destination IP address for a UDP
/// datagram.
Ipv4RecvDstAddr, Both, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool);
#[cfg(target_os = "linux")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[allow(missing_docs)]
// Not documented by Linux!
UdpGsoSegment, Both, libc::SOL_UDP, libc::UDP_SEGMENT, libc::c_int);
#[cfg(target_os = "linux")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[allow(missing_docs)]
// Not documented by Linux!
UdpGroSegment, Both, libc::IPPROTO_UDP, libc::UDP_GRO, bool);
@@ -530,7 +583,9 @@ sockopt_impl!(
/// be attached to received skbs indicating the number of packets dropped by
/// the socket since its creation.
RxqOvfl, Both, libc::SOL_SOCKET, libc::SO_RXQ_OVFL, libc::c_int);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The socket is restricted to sending and receiving IPv6 packets only.
Ipv6V6Only, Both, libc::IPPROTO_IPV6, libc::IPV6_V6ONLY, bool);
#[cfg(any(target_os = "android", target_os = "linux"))]