Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ const fn into_linger(duration: Option<Duration>) -> sys::linger {
}
}

/// Socket options for IPv4 sockets, get/set using `IPPROTO_IP`.
/// Socket options for IPv4 sockets, get/set using `IPPROTO_IP` or `SOL_IP`.
///
/// Additional documentation can be found in documentation of the OS.
/// * Linux: <https://man7.org/linux/man-pages/man7/ip.7.html>
Expand Down Expand Up @@ -1670,9 +1670,23 @@ impl Socket {
.map(|recv_tos| recv_tos > 0)
}
}

/// Get the value for the `SO_ORIGINAL_DST` option on this socket.
#[cfg(all(
feature = "all",
any(
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
target_os = "windows",
)
))]
pub fn original_dst_v4(&self) -> io::Result<SockAddr> {
sys::original_dst_v4(self.as_raw())
}
}

/// Socket options for IPv6 sockets, get/set using `IPPROTO_IPV6`.
/// Socket options for IPv6 sockets, get/set using `IPPROTO_IPV6` or `SOL_IPV6`.
///
/// Additional documentation can be found in documentation of the OS.
/// * Linux: <https://man7.org/linux/man-pages/man7/ipv6.7.html>
Expand Down Expand Up @@ -2075,6 +2089,15 @@ impl Socket {
)
}
}

/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket.
#[cfg(all(
feature = "all",
any(target_os = "android", target_os = "linux", target_os = "windows")
))]
pub fn original_dst_v6(&self) -> io::Result<SockAddr> {
sys::original_dst_v6(self.as_raw())
}
}

/// Socket options for TCP sockets, get/set using `IPPROTO_TCP`.
Expand All @@ -2096,8 +2119,8 @@ impl Socket {
target_os = "vita"
))
))]
pub fn keepalive_time(&self) -> io::Result<Duration> {
sys::keepalive_time(self.as_raw())
pub fn tcp_keepalive_time(&self) -> io::Result<Duration> {
sys::tcp_keepalive_time(self.as_raw())
}

/// Get the value of the `TCP_KEEPINTVL` option on this socket.
Expand All @@ -2123,7 +2146,7 @@ impl Socket {
target_os = "cygwin",
)
))]
pub fn keepalive_interval(&self) -> io::Result<Duration> {
pub fn tcp_keepalive_interval(&self) -> io::Result<Duration> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_TCP, sys::TCP_KEEPINTVL)
.map(|secs| Duration::from_secs(secs as u64))
Expand Down Expand Up @@ -2154,7 +2177,7 @@ impl Socket {
target_os = "windows",
)
))]
pub fn keepalive_retries(&self) -> io::Result<u32> {
pub fn tcp_keepalive_retries(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_TCP, sys::TCP_KEEPCNT)
.map(|retries| retries as u32)
Expand Down Expand Up @@ -2206,10 +2229,10 @@ impl Socket {

/// Get the value of the `TCP_NODELAY` option on this socket.
///
/// For more information about this option, see [`set_nodelay`].
/// For more information about this option, see [`set_tcp_nodelay`].
///
/// [`set_nodelay`]: Socket::set_nodelay
pub fn nodelay(&self) -> io::Result<bool> {
/// [`set_tcp_nodelay`]: Socket::set_tcp_nodelay
pub fn tcp_nodelay(&self) -> io::Result<bool> {
unsafe {
getsockopt::<Bool>(self.as_raw(), sys::IPPROTO_TCP, sys::TCP_NODELAY)
.map(|nodelay| nodelay != 0)
Expand All @@ -2223,7 +2246,7 @@ impl Socket {
/// small amount of data. When not set, data is buffered until there is a
/// sufficient amount to send out, thereby avoiding the frequent sending of
/// small packets.
pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> {
pub fn set_tcp_nodelay(&self, nodelay: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand All @@ -2233,29 +2256,6 @@ impl Socket {
)
}
}

/// Get the value for the `SO_ORIGINAL_DST` option on this socket.
#[cfg(all(
feature = "all",
any(
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
target_os = "windows",
)
))]
pub fn original_dst(&self) -> io::Result<SockAddr> {
sys::original_dst(self.as_raw())
}

/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket.
#[cfg(all(
feature = "all",
any(target_os = "android", target_os = "linux", target_os = "windows")
))]
pub fn original_dst_ipv6(&self) -> io::Result<SockAddr> {
sys::original_dst_ipv6(self.as_raw())
}
}

impl Read for Socket {
Expand Down
4 changes: 2 additions & 2 deletions src/sockref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use crate::Socket;
///
/// // Create a `SockRef`erence to the stream.
/// let socket_ref = SockRef::from(&stream);
/// // Use `Socket::set_nodelay` on the stream.
/// socket_ref.set_nodelay(true)?;
/// // Use `Socket::set_tcp_nodelay` on the stream.
/// socket_ref.set_tcp_nodelay(true)?;
/// drop(socket_ref);
///
/// assert_eq!(stream.nodelay()?, true);
Expand Down
62 changes: 31 additions & 31 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
feature = "all",
not(any(target_os = "haiku", target_os = "openbsd", target_os = "vita"))
))]
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
pub(crate) fn tcp_keepalive_time(fd: Socket) -> io::Result<Duration> {
unsafe {
getsockopt::<c_int>(fd, IPPROTO_TCP, KEEPALIVE_TIME)
.map(|secs| Duration::from_secs(secs as u64))
Expand Down Expand Up @@ -1380,7 +1380,7 @@ pub(crate) const fn to_mreqn(
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub(crate) fn original_dst(fd: Socket) -> io::Result<SockAddr> {
pub(crate) fn original_dst_v4(fd: Socket) -> io::Result<SockAddr> {
// Safety: `getsockopt` initialises the `SockAddr` for us.
unsafe {
SockAddr::try_init(|storage, len| {
Expand All @@ -1401,7 +1401,7 @@ pub(crate) fn original_dst(fd: Socket) -> io::Result<SockAddr> {
/// This value contains the original destination IPv6 address of the connection
/// redirected using `ip6tables` `REDIRECT` or `TPROXY`.
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
pub(crate) fn original_dst_ipv6(fd: Socket) -> io::Result<SockAddr> {
pub(crate) fn original_dst_v6(fd: Socket) -> io::Result<SockAddr> {
// Safety: `getsockopt` initialises the `SockAddr` for us.
unsafe {
SockAddr::try_init(|storage, len| {
Expand Down Expand Up @@ -1565,11 +1565,11 @@ impl crate::Socket {

/// Gets the value of the `TCP_MAXSEG` option on this socket.
///
/// For more information about this option, see [`set_mss`].
/// For more information about this option, see [`set_tcp_mss`].
///
/// [`set_mss`]: crate::Socket::set_mss
/// [`set_tcp_mss`]: crate::Socket::set_tcp_mss
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub fn mss(&self) -> io::Result<u32> {
pub fn tcp_mss(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), libc::IPPROTO_TCP, libc::TCP_MAXSEG)
.map(|mss| mss as u32)
Expand All @@ -1581,7 +1581,7 @@ impl crate::Socket {
/// The `TCP_MAXSEG` option denotes the TCP Maximum Segment Size and is only
/// available on TCP sockets.
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub fn set_mss(&self, mss: u32) -> io::Result<()> {
pub fn set_tcp_mss(&self, mss: u32) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand Down Expand Up @@ -1690,14 +1690,14 @@ impl crate::Socket {

/// Get the value of the `TCP_CORK` option on this socket.
///
/// For more information about this option, see [`set_cork`].
/// For more information about this option, see [`set_tcp_cork`].
///
/// [`set_cork`]: crate::Socket::set_cork
/// [`set_tcp_cork`]: crate::Socket::set_tcp_cork
#[cfg(all(
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub fn cork(&self) -> io::Result<bool> {
pub fn tcp_cork(&self) -> io::Result<bool> {
unsafe {
getsockopt::<Bool>(self.as_raw(), libc::IPPROTO_TCP, libc::TCP_CORK)
.map(|cork| cork != 0)
Expand All @@ -1714,7 +1714,7 @@ impl crate::Socket {
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub fn set_cork(&self, cork: bool) -> io::Result<()> {
pub fn set_tcp_cork(&self, cork: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand All @@ -1727,9 +1727,9 @@ impl crate::Socket {

/// Get the value of the `TCP_QUICKACK` option on this socket.
///
/// For more information about this option, see [`set_quickack`].
/// For more information about this option, see [`set_tcp_quickack`].
///
/// [`set_quickack`]: crate::Socket::set_quickack
/// [`set_tcp_quickack`]: crate::Socket::set_tcp_quickack
#[cfg(all(
feature = "all",
any(
Expand All @@ -1739,7 +1739,7 @@ impl crate::Socket {
target_os = "cygwin",
)
))]
pub fn quickack(&self) -> io::Result<bool> {
pub fn tcp_quickack(&self) -> io::Result<bool> {
unsafe {
getsockopt::<Bool>(self.as_raw(), libc::IPPROTO_TCP, libc::TCP_QUICKACK)
.map(|quickack| quickack != 0)
Expand All @@ -1761,7 +1761,7 @@ impl crate::Socket {
target_os = "cygwin",
)
))]
pub fn set_quickack(&self, quickack: bool) -> io::Result<()> {
pub fn set_tcp_quickack(&self, quickack: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand All @@ -1774,14 +1774,14 @@ impl crate::Socket {

/// Get the value of the `TCP_THIN_LINEAR_TIMEOUTS` option on this socket.
///
/// For more information about this option, see [`set_thin_linear_timeouts`].
/// For more information about this option, see [`set_tcp_thin_linear_timeouts`].
///
/// [`set_thin_linear_timeouts`]: crate::Socket::set_thin_linear_timeouts
/// [`set_tcp_thin_linear_timeouts`]: crate::Socket::set_tcp_thin_linear_timeouts
#[cfg(all(
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub fn thin_linear_timeouts(&self) -> io::Result<bool> {
pub fn tcp_thin_linear_timeouts(&self) -> io::Result<bool> {
unsafe {
getsockopt::<Bool>(
self.as_raw(),
Expand All @@ -1801,7 +1801,7 @@ impl crate::Socket {
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub fn set_thin_linear_timeouts(&self, timeouts: bool) -> io::Result<()> {
pub fn set_tcp_thin_linear_timeouts(&self, timeouts: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand Down Expand Up @@ -2160,14 +2160,14 @@ impl crate::Socket {

/// Get the value of the `IP_FREEBIND` option on this socket.
///
/// For more information about this option, see [`set_freebind`].
/// For more information about this option, see [`set_freebind_v4`].
///
/// [`set_freebind`]: crate::Socket::set_freebind
/// [`set_freebind_v4`]: crate::Socket::set_freebind_v4
#[cfg(all(
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub fn freebind(&self) -> io::Result<bool> {
pub fn freebind_v4(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), libc::SOL_IP, libc::IP_FREEBIND)
.map(|freebind| freebind != 0)
Expand All @@ -2185,7 +2185,7 @@ impl crate::Socket {
feature = "all",
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
))]
pub fn set_freebind(&self, freebind: bool) -> io::Result<()> {
pub fn set_freebind_v4(&self, freebind: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand All @@ -2200,11 +2200,11 @@ impl crate::Socket {
///
/// This is an IPv6 counterpart of `IP_FREEBIND` socket option on
/// Android/Linux. For more information about this option, see
/// [`set_freebind`].
/// [`set_freebind_v4`].
///
/// [`set_freebind`]: crate::Socket::set_freebind
/// [`set_freebind_v4`]: crate::Socket::set_freebind_v4
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
pub fn freebind_ipv6(&self) -> io::Result<bool> {
pub fn freebind_v6(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), libc::SOL_IPV6, libc::IPV6_FREEBIND)
.map(|freebind| freebind != 0)
Expand All @@ -2215,9 +2215,9 @@ impl crate::Socket {
///
/// This is an IPv6 counterpart of `IP_FREEBIND` socket option on
/// Android/Linux. For more information about this option, see
/// [`set_freebind`].
/// [`set_freebind_v4`].
///
/// [`set_freebind`]: crate::Socket::set_freebind
/// [`set_freebind_v4`]: crate::Socket::set_freebind_v4
///
/// # Examples
///
Expand All @@ -2229,8 +2229,8 @@ impl crate::Socket {
///
/// fn enable_freebind(socket: &Socket) -> io::Result<()> {
/// match socket.domain()? {
/// Domain::IPV4 => socket.set_freebind(true)?,
/// Domain::IPV6 => socket.set_freebind_ipv6(true)?,
/// Domain::IPV4 => socket.set_freebind_v4(true)?,
/// Domain::IPV6 => socket.set_freebind_v6(true)?,
/// _ => return Err(Error::new(ErrorKind::Other, "unsupported domain")),
/// };
/// Ok(())
Expand All @@ -2242,7 +2242,7 @@ impl crate::Socket {
/// # }
/// ```
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
pub fn set_freebind_ipv6(&self, freebind: bool) -> io::Result<()> {
pub fn set_freebind_v6(&self, freebind: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ pub(crate) fn to_mreqn(
}

#[cfg(feature = "all")]
pub(crate) fn original_dst(socket: Socket) -> io::Result<SockAddr> {
pub(crate) fn original_dst_v4(socket: Socket) -> io::Result<SockAddr> {
unsafe {
SockAddr::try_init(|storage, len| {
syscall!(
Expand All @@ -903,7 +903,7 @@ pub(crate) fn original_dst(socket: Socket) -> io::Result<SockAddr> {
}

#[cfg(feature = "all")]
pub(crate) fn original_dst_ipv6(socket: Socket) -> io::Result<SockAddr> {
pub(crate) fn original_dst_v6(socket: Socket) -> io::Result<SockAddr> {
unsafe {
SockAddr::try_init(|storage, len| {
syscall!(
Expand Down
Loading
Loading