From 5ce4d0de1a11483ac7c77400fe642eaf2af942dc Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 20 Mar 2025 11:59:43 +0100 Subject: [PATCH 1/5] Refresh of #94678 --- library/std/src/lib.rs | 1 + library/std/src/net/tcp.rs | 78 +++++++++++++++++++ library/std/src/net/tcp/tests.rs | 17 ++++ library/std/src/net/udp.rs | 76 ++++++++++++++++++ library/std/src/net/udp/tests.rs | 12 +++ library/std/src/sys/net/connection/sgx.rs | 33 ++++++++ library/std/src/sys/net/connection/socket.rs | 36 +++++++++ .../src/sys/net/connection/socket/windows.rs | 8 +- .../std/src/sys/net/connection/uefi/mod.rs | 32 ++++++++ .../std/src/sys/net/connection/unsupported.rs | 32 ++++++++ library/std/src/sys/net/connection/wasip1.rs | 32 ++++++++ .../sys/net/connection/xous/tcplistener.rs | 8 ++ .../src/sys/net/connection/xous/tcpstream.rs | 8 ++ .../std/src/sys/net/connection/xous/udp.rs | 16 ++++ .../std/src/sys/pal/windows/c/bindings.txt | 2 + .../std/src/sys/pal/windows/c/windows_sys.rs | 2 + 16 files changed, 389 insertions(+), 4 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 5c381181218df..8b703bc33dd0f 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -349,6 +349,7 @@ #![feature(hashmap_internals)] #![feature(hint_must_use)] #![feature(ip)] +#![feature(ipv6_hop_limit)] #![feature(lazy_get)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_write_slice)] diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 6a95142640726..e5b78a1c45e38 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -548,6 +548,46 @@ impl TcpStream { self.0.ttl() } + // Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// This value sets the unicast hop limit field that is used in every packet + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpStream; + /// + /// let stream = TcpStream::connect("127.0.0.1:54321") + /// .expect("Couldn't connect to the server..."); + /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0.set_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`TcpStream::set_hop_limit_v6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpStream; + /// + /// let stream = TcpStream::connect("127.0.0.1:54321") + /// .expect("Couldn't connect to the server..."); + /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(stream.hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn hop_limit_v6(&self) -> io::Result { + self.0.hop_limit_v6() + } + /// Gets the value of the `SO_ERROR` option on this socket. /// /// This will retrieve the stored error in the underlying socket, clearing @@ -942,6 +982,44 @@ impl TcpListener { self.0.ttl() } + /// Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// This value sets the unicast hop limit field that is used in every packet + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpListener; + /// + /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); + /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0.set_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`TcpListener::set_hop_limit_v6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpListener; + /// + /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); + /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(listener.hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn hop_limit_v6(&self) -> io::Result { + self.0.hop_limit_v6() + } + #[stable(feature = "net2_mutators", since = "1.9.0")] #[deprecated(since = "1.16.0", note = "this option can only be set before the socket is bound")] #[allow(missing_docs)] diff --git a/library/std/src/net/tcp/tests.rs b/library/std/src/net/tcp/tests.rs index 03003037b295c..d14acbb40cb0b 100644 --- a/library/std/src/net/tcp/tests.rs +++ b/library/std/src/net/tcp/tests.rs @@ -875,6 +875,23 @@ fn ttl() { assert_eq!(ttl, t!(stream.ttl())); } +#[test] +#[cfg_attr(target_env = "sgx", ignore)] +fn hop_limit() { + let hlim = 100; + + let addr = next_test_ip6(); + let listener = t!(TcpListener::bind(&addr)); + + t!(listener.set_hop_limit_v6(hlim)); + assert_eq!(hlim, t!(listener.hop_limit_v6())); + + let stream = t!(TcpStream::connect(&addr)); + + t!(stream.set_hop_limit_v6(hlim)); + assert_eq!(hlim, t!(stream.hop_limit_v6())); +} + #[test] #[cfg_attr(target_env = "sgx", ignore)] fn set_nonblocking() { diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index a97b3299774bb..1848376bf1cf2 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -582,6 +582,82 @@ impl UdpSocket { self.0.ttl() } + /// Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// This value sets the unicast hop limit field that is used in every packet + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0.set_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_v6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(socket.hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn hop_limit_v6(&self) -> io::Result { + self.0.hop_limit_v6() + } + + /// Sets the value for the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// This value sets the hop limit field for outgoing multicast packets + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0.set_multicast_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_multicast_hop_limit_v6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); + /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0.multicast_hop_limit_v6() + } + /// Executes an operation of the `IP_ADD_MEMBERSHIP` type. /// /// This function specifies a new multicast group for this socket to join. diff --git a/library/std/src/net/udp/tests.rs b/library/std/src/net/udp/tests.rs index 91da3135f97c6..8af9ee2f7e5ef 100644 --- a/library/std/src/net/udp/tests.rs +++ b/library/std/src/net/udp/tests.rs @@ -357,6 +357,18 @@ fn ttl() { assert_eq!(ttl, t!(stream.ttl())); } +#[test] +fn hop_limit() { + let hlim = 100; + + let addr = next_test_ip6(); + + let stream = t!(UdpSocket::bind(&addr)); + + t!(stream.set_hop_limit_v6(hlim)); + assert_eq!(hlim, t!(stream.hop_limit_v6())); +} + #[test] fn set_nonblocking() { each_ip(&mut |addr, _| { diff --git a/library/std/src/sys/net/connection/sgx.rs b/library/std/src/sys/net/connection/sgx.rs index 242df10bc3270..52aac652b7b3a 100644 --- a/library/std/src/sys/net/connection/sgx.rs +++ b/library/std/src/sys/net/connection/sgx.rs @@ -8,6 +8,7 @@ use crate::time::Duration; use crate::{error, fmt}; const DEFAULT_FAKE_TTL: u32 = 64; +const DEFAULT_FAKE_HLIM: u8 = 64; #[derive(Debug, Clone)] pub struct Socket { @@ -199,6 +200,14 @@ impl TcpStream { sgx_ineffective(DEFAULT_FAKE_TTL) } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn hop_limit_v6(&self) -> io::Result { + sgx_ineffective(DEFAULT_FAKE_HLIM) + } + pub fn take_error(&self) -> io::Result> { Ok(None) } @@ -277,6 +286,14 @@ impl TcpListener { sgx_ineffective(DEFAULT_FAKE_TTL) } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn hop_limit_v6(&self) -> io::Result { + sgx_ineffective(DEFAULT_FAKE_HLIM) + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { sgx_ineffective(()) } @@ -416,6 +433,22 @@ impl UdpSocket { self.0 } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { + self.0 + } + + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } diff --git a/library/std/src/sys/net/connection/socket.rs b/library/std/src/sys/net/connection/socket.rs index 7301bde6881a3..9af63fe5fd078 100644 --- a/library/std/src/sys/net/connection/socket.rs +++ b/library/std/src/sys/net/connection/socket.rs @@ -454,6 +454,15 @@ impl TcpStream { Ok(raw as u32) } + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) + } + + pub fn hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + Ok(raw as u8) + } + pub fn take_error(&self) -> io::Result> { self.inner.take_error() } @@ -581,6 +590,15 @@ impl TcpListener { Ok(raw as u32) } + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) + } + + pub fn hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + Ok(raw as u8) + } + pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } @@ -786,6 +804,24 @@ impl UdpSocket { Ok(raw as u32) } + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) + } + + pub fn hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + Ok(raw as u8) + } + + pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) + } + + pub fn multicast_hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; + Ok(raw as u8) + } + pub fn take_error(&self) -> io::Result> { self.inner.take_error() } diff --git a/library/std/src/sys/net/connection/socket/windows.rs b/library/std/src/sys/net/connection/socket/windows.rs index ce975bb2289c2..8ac9837dbcb8b 100644 --- a/library/std/src/sys/net/connection/socket/windows.rs +++ b/library/std/src/sys/net/connection/socket/windows.rs @@ -30,10 +30,10 @@ pub(super) mod netc { pub use crate::sys::c::{ ADDRESS_FAMILY as sa_family_t, ADDRINFOA as addrinfo, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, IPPROTO_IP, IPPROTO_IPV6, - IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_MULTICAST_LOOP, IPV6_V6ONLY, SO_BROADCAST, - SO_RCVTIMEO, SO_SNDTIMEO, SOCK_DGRAM, SOCK_STREAM, SOCKADDR as sockaddr, - SOCKADDR_STORAGE as sockaddr_storage, SOL_SOCKET, bind, connect, freeaddrinfo, getpeername, - getsockname, getsockopt, listen, setsockopt, + IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_LOOP, + IPV6_UNICAST_HOPS, IPV6_V6ONLY, SO_BROADCAST, SO_RCVTIMEO, SO_SNDTIMEO, SOCK_DGRAM, + SOCK_STREAM, SOCKADDR as sockaddr, SOCKADDR_STORAGE as sockaddr_storage, SOL_SOCKET, bind, + connect, freeaddrinfo, getpeername, getsockname, getsockopt, listen, setsockopt, }; #[allow(non_camel_case_types)] diff --git a/library/std/src/sys/net/connection/uefi/mod.rs b/library/std/src/sys/net/connection/uefi/mod.rs index da2174396266f..437284f9c9177 100644 --- a/library/std/src/sys/net/connection/uefi/mod.rs +++ b/library/std/src/sys/net/connection/uefi/mod.rs @@ -103,6 +103,14 @@ impl TcpStream { self.0 } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } @@ -145,6 +153,14 @@ impl TcpListener { self.0 } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { self.0 } @@ -271,6 +287,22 @@ impl UdpSocket { self.0 } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { + self.0 + } + + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } diff --git a/library/std/src/sys/net/connection/unsupported.rs b/library/std/src/sys/net/connection/unsupported.rs index da2174396266f..73417c0d5fc88 100644 --- a/library/std/src/sys/net/connection/unsupported.rs +++ b/library/std/src/sys/net/connection/unsupported.rs @@ -103,6 +103,14 @@ impl TcpStream { self.0 } + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } @@ -145,6 +153,14 @@ impl TcpListener { self.0 } + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { self.0 } @@ -271,6 +287,22 @@ impl UdpSocket { self.0 } + pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + self.0 + } + + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } diff --git a/library/std/src/sys/net/connection/wasip1.rs b/library/std/src/sys/net/connection/wasip1.rs index 951dc65e5b47d..a62912b6407af 100644 --- a/library/std/src/sys/net/connection/wasip1.rs +++ b/library/std/src/sys/net/connection/wasip1.rs @@ -162,6 +162,14 @@ impl TcpStream { unsupported() } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + pub fn take_error(&self) -> io::Result> { unsupported() } @@ -245,6 +253,14 @@ impl TcpListener { unsupported() } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { unsupported() } @@ -416,6 +432,22 @@ impl UdpSocket { unsupported() } + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hop_limit_v6(&self) -> io::Result { + unsupported() + } + pub fn take_error(&self) -> io::Result> { unsupported() } diff --git a/library/std/src/sys/net/connection/xous/tcplistener.rs b/library/std/src/sys/net/connection/xous/tcplistener.rs index 7f13ca5592040..8e9febac28c85 100644 --- a/library/std/src/sys/net/connection/xous/tcplistener.rs +++ b/library/std/src/sys/net/connection/xous/tcplistener.rs @@ -199,6 +199,14 @@ impl TcpListener { .map(|res| res[0] as _)?) } + pub fn set_hop_limit_v6(&self, hlim: u8) -> io::Result<()> { + unimpl!(); + } + + pub fn hop_limit_v6(&self) -> io::Result { + unimpl!(); + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { unimpl!(); } diff --git a/library/std/src/sys/net/connection/xous/tcpstream.rs b/library/std/src/sys/net/connection/xous/tcpstream.rs index e8aea8b706a58..e36fb079ffbf4 100644 --- a/library/std/src/sys/net/connection/xous/tcpstream.rs +++ b/library/std/src/sys/net/connection/xous/tcpstream.rs @@ -389,6 +389,14 @@ impl TcpStream { .map(|res| res[0] as _)?) } + pub fn set_hop_limit_v6(&self, hlim: u8) -> io::Result<()> { + unimpl!(); + } + + pub fn hop_limit_v6(&self) -> io::Result { + unimpl!(); + } + pub fn take_error(&self) -> io::Result> { // this call doesn't have a meaning on our platform, but we can at least not panic if it's used. Ok(None) diff --git a/library/std/src/sys/net/connection/xous/udp.rs b/library/std/src/sys/net/connection/xous/udp.rs index c112c04ce94bc..81bedba77fc73 100644 --- a/library/std/src/sys/net/connection/xous/udp.rs +++ b/library/std/src/sys/net/connection/xous/udp.rs @@ -376,6 +376,14 @@ impl UdpSocket { .map(|res| res[0] as _)?) } + pub fn set_hop_limit_v6(&self, hlim: u8) -> io::Result<()> { + unimpl!(); + } + + pub fn hop_limit_v6(&self) -> io::Result { + unimpl!(); + } + pub fn take_error(&self) -> io::Result> { // this call doesn't have a meaning on our platform, but we can at least not panic if it's used. Ok(None) @@ -411,6 +419,14 @@ impl UdpSocket { unimpl!(); } + pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { + unimpl!(); + } + + pub fn multicast_hop_limit_v6(&self) -> io::Result { + unimpl!(); + } + pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> { unimpl!(); } diff --git a/library/std/src/sys/pal/windows/c/bindings.txt b/library/std/src/sys/pal/windows/c/bindings.txt index d5fbb453c6f96..1f3cb311347d7 100644 --- a/library/std/src/sys/pal/windows/c/bindings.txt +++ b/library/std/src/sys/pal/windows/c/bindings.txt @@ -2246,7 +2246,9 @@ IPPROTO_UDP IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP IPV6_MREQ +IPV6_MULTICAST_HOPS IPV6_MULTICAST_LOOP +IPV6_UNICAST_HOPS IPV6_V6ONLY LINGER listen diff --git a/library/std/src/sys/pal/windows/c/windows_sys.rs b/library/std/src/sys/pal/windows/c/windows_sys.rs index eb2914b864473..4d9395bbb078a 100644 --- a/library/std/src/sys/pal/windows/c/windows_sys.rs +++ b/library/std/src/sys/pal/windows/c/windows_sys.rs @@ -2875,7 +2875,9 @@ impl Default for IPV6_MREQ { unsafe { core::mem::zeroed() } } } +pub const IPV6_MULTICAST_HOPS: i32 = 10i32; pub const IPV6_MULTICAST_LOOP: i32 = 11i32; +pub const IPV6_UNICAST_HOPS: i32 = 4i32; pub const IPV6_V6ONLY: i32 = 27i32; pub const IP_ADD_MEMBERSHIP: i32 = 12i32; pub const IP_DROP_MEMBERSHIP: i32 = 13i32; From 03aef02eb87077926b122e717bd92507f402b0a9 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 20 Mar 2025 16:03:05 +0100 Subject: [PATCH 2/5] Use IPv6 addresses in hop_limit_v6 docs --- library/std/src/net/tcp.rs | 8 ++++---- library/std/src/net/udp.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index e5b78a1c45e38..13895fcbc396e 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -559,7 +559,7 @@ impl TcpStream { /// #![feature(ipv6_hop_limit)] /// use std::net::TcpStream; /// - /// let stream = TcpStream::connect("127.0.0.1:54321") + /// let stream = TcpStream::connect("[::1]:12345") /// .expect("Couldn't connect to the server..."); /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` @@ -578,7 +578,7 @@ impl TcpStream { /// #![feature(ipv6_hop_limit)] /// use std::net::TcpStream; /// - /// let stream = TcpStream::connect("127.0.0.1:54321") + /// let stream = TcpStream::connect("[::1]:12345") /// .expect("Couldn't connect to the server..."); /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// assert_eq!(stream.hop_limit_v6().unwrap(), 88); @@ -993,7 +993,7 @@ impl TcpListener { /// #![feature(ipv6_hop_limit)] /// use std::net::TcpListener; /// - /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); + /// let listener = TcpListener::bind("[::1]:12345").unwrap(); /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] @@ -1011,7 +1011,7 @@ impl TcpListener { /// #![feature(ipv6_hop_limit)] /// use std::net::TcpListener; /// - /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); + /// let listener = TcpListener::bind("[::1]:12345").unwrap(); /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// assert_eq!(listener.hop_limit_v6().unwrap(), 88); /// ``` diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 1848376bf1cf2..6f470c7a22dda 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -593,7 +593,7 @@ impl UdpSocket { /// #![feature(ipv6_hop_limit)] /// use std::net::UdpSocket; /// - /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// let socket = UdpSocket::bind("[::1]:12345").expect("couldn't bind to address"); /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] @@ -611,7 +611,7 @@ impl UdpSocket { /// #![feature(ipv6_hop_limit)] /// use std::net::UdpSocket; /// - /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// let socket = UdpSocket::bind("[::1]:12345").expect("couldn't bind to address"); /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// assert_eq!(socket.hop_limit_v6().unwrap(), 88); /// ``` @@ -631,7 +631,7 @@ impl UdpSocket { /// #![feature(ipv6_hop_limit)] /// use std::net::UdpSocket; /// - /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// let socket = UdpSocket::bind("[::1]:12345").expect("couldn't bind to address"); /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] @@ -649,7 +649,7 @@ impl UdpSocket { /// #![feature(ipv6_hop_limit)] /// use std::net::UdpSocket; /// - /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// let socket = UdpSocket::bind("[::1]:12345").expect("couldn't bind to address"); /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88); /// ``` From 5ace46a36ac60df622136441df7785e0797df581 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 31 Mar 2025 12:04:44 +0200 Subject: [PATCH 3/5] Update tracking issue to 139166 --- library/std/src/net/tcp.rs | 8 ++++---- library/std/src/net/udp.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 13895fcbc396e..e3ad5e54be3f0 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -563,7 +563,7 @@ impl TcpStream { /// .expect("Couldn't connect to the server..."); /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -583,7 +583,7 @@ impl TcpStream { /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// assert_eq!(stream.hop_limit_v6().unwrap(), 88); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } @@ -996,7 +996,7 @@ impl TcpListener { /// let listener = TcpListener::bind("[::1]:12345").unwrap(); /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -1015,7 +1015,7 @@ impl TcpListener { /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// assert_eq!(listener.hop_limit_v6().unwrap(), 88); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 6f470c7a22dda..a1c55fa8316c0 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -596,7 +596,7 @@ impl UdpSocket { /// let socket = UdpSocket::bind("[::1]:12345").expect("couldn't bind to address"); /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -615,7 +615,7 @@ impl UdpSocket { /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// assert_eq!(socket.hop_limit_v6().unwrap(), 88); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } @@ -634,7 +634,7 @@ impl UdpSocket { /// let socket = UdpSocket::bind("[::1]:12345").expect("couldn't bind to address"); /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_multicast_hop_limit_v6(limit) } @@ -653,7 +653,7 @@ impl UdpSocket { /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88); /// ``` - #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + #[unstable(feature = "ipv6_hop_limit", issue = "139166")] pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0.multicast_hop_limit_v6() } From 25fb5250c10510853b3f06c6eea112ca51a2bb71 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 31 Mar 2025 12:06:28 +0200 Subject: [PATCH 4/5] Update docs according to PR review Co-authored-by: David Tolnay --- library/std/src/net/tcp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index e3ad5e54be3f0..aac7a52c7e133 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -548,7 +548,7 @@ impl TcpStream { self.0.ttl() } - // Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. /// /// This value sets the unicast hop limit field that is used in every packet /// sent from this socket. From 6657c75c3b47d0d396fbbe96c18b4c624553475b Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 16 Apr 2025 12:20:56 +0200 Subject: [PATCH 5/5] Fix unused_variables --- library/std/src/sys/net/connection/unsupported.rs | 8 ++++---- library/std/src/sys/net/connection/xous/tcpstream.rs | 2 +- library/std/src/sys/net/connection/xous/udp.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/std/src/sys/net/connection/unsupported.rs b/library/std/src/sys/net/connection/unsupported.rs index 73417c0d5fc88..437284f9c9177 100644 --- a/library/std/src/sys/net/connection/unsupported.rs +++ b/library/std/src/sys/net/connection/unsupported.rs @@ -103,7 +103,7 @@ impl TcpStream { self.0 } - pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { self.0 } @@ -153,7 +153,7 @@ impl TcpListener { self.0 } - pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { self.0 } @@ -287,7 +287,7 @@ impl UdpSocket { self.0 } - pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { self.0 } @@ -295,7 +295,7 @@ impl UdpSocket { self.0 } - pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { self.0 } diff --git a/library/std/src/sys/net/connection/xous/tcpstream.rs b/library/std/src/sys/net/connection/xous/tcpstream.rs index e36fb079ffbf4..d27886b7b9c01 100644 --- a/library/std/src/sys/net/connection/xous/tcpstream.rs +++ b/library/std/src/sys/net/connection/xous/tcpstream.rs @@ -389,7 +389,7 @@ impl TcpStream { .map(|res| res[0] as _)?) } - pub fn set_hop_limit_v6(&self, hlim: u8) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { unimpl!(); } diff --git a/library/std/src/sys/net/connection/xous/udp.rs b/library/std/src/sys/net/connection/xous/udp.rs index 81bedba77fc73..1b8bc3c015cb9 100644 --- a/library/std/src/sys/net/connection/xous/udp.rs +++ b/library/std/src/sys/net/connection/xous/udp.rs @@ -376,7 +376,7 @@ impl UdpSocket { .map(|res| res[0] as _)?) } - pub fn set_hop_limit_v6(&self, hlim: u8) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { unimpl!(); }