From 6be0b7ec79e156feed1b33ac1a72d16a740b0e09 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 20 Mar 2025 11:59:43 +0100 Subject: [PATCH 1/9] Add methods to TCP and UDP sockets to modify hop limit --- library/std/src/lib.rs | 8 +- 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 ++++++++ .../std/src/sys/net/connection/socket/mod.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, 392 insertions(+), 8 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c8c8a6c897142..6af76ca64ae64 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -342,10 +342,10 @@ #![feature(hint_must_use)] #![feature(int_from_ascii)] #![feature(ip)] -#![feature(iter_advance_by)] -#![feature(iter_next_chunk)] -#![feature(maybe_uninit_array_assume_init)] -#![feature(maybe_uninit_fill)] +#![feature(ipv6_hop_limit)] +#![feature(lazy_get)] +#![feature(maybe_uninit_slice)] +#![feature(maybe_uninit_write_slice)] #![feature(panic_can_unwind)] #![feature(panic_internals)] #![feature(pin_coerce_unsized_trait)] diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index dac568e419f3f..189c206c3dc78 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -553,6 +553,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 @@ -947,6 +987,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 e4a30b80e3df4..b2e2be5530447 100644 --- a/library/std/src/net/tcp/tests.rs +++ b/library/std/src/net/tcp/tests.rs @@ -876,6 +876,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 136803ab16f1f..7f017b4be4694 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -581,6 +581,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 0638b36c54f9d..a2b1555d1b9ac 100644 --- a/library/std/src/net/udp/tests.rs +++ b/library/std/src/net/udp/tests.rs @@ -358,6 +358,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 6a625664494b5..9ba1032d29e7a 100644 --- a/library/std/src/sys/net/connection/sgx.rs +++ b/library/std/src/sys/net/connection/sgx.rs @@ -9,6 +9,7 @@ use crate::sys::{AsInner, FromInner, IntoInner, TryIntoInner, sgx_ineffective, u use crate::time::Duration; const DEFAULT_FAKE_TTL: u32 = 64; +const DEFAULT_FAKE_HLIM: u8 = 64; #[derive(Debug, Clone)] pub struct Socket { @@ -235,6 +236,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) } @@ -314,6 +323,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(()) } @@ -453,6 +470,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/mod.rs b/library/std/src/sys/net/connection/socket/mod.rs index 256b99dfa9874..e6b90129e0867 100644 --- a/library/std/src/sys/net/connection/socket/mod.rs +++ b/library/std/src/sys/net/connection/socket/mod.rs @@ -485,6 +485,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() } @@ -613,6 +622,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<()> { unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } } @@ -833,6 +851,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 b23fb9c09f871..badd7d27b0d35 100644 --- a/library/std/src/sys/net/connection/socket/windows.rs +++ b/library/std/src/sys/net/connection/socket/windows.rs @@ -29,10 +29,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 107a3e23733de..b127903bc0d15 100644 --- a/library/std/src/sys/net/connection/uefi/mod.rs +++ b/library/std/src/sys/net/connection/uefi/mod.rs @@ -128,6 +128,14 @@ impl TcpStream { self.inner.ttl() } + 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> { unsupported() } @@ -179,6 +187,14 @@ impl TcpListener { self.inner.ttl() } + 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<()> { unsupported() } @@ -305,6 +321,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 fb18e8dec557c..7532e2486375f 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 95a4ab2fbf0fd..733bc17e1eadb 100644 --- a/library/std/src/sys/net/connection/wasip1.rs +++ b/library/std/src/sys/net/connection/wasip1.rs @@ -161,6 +161,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() } @@ -244,6 +252,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() } @@ -415,6 +431,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 8818ef2ca9a9b..c53c27b842ad3 100644 --- a/library/std/src/sys/net/connection/xous/tcplistener.rs +++ b/library/std/src/sys/net/connection/xous/tcplistener.rs @@ -203,6 +203,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 4df75453d1f45..1fbe87109034d 100644 --- a/library/std/src/sys/net/connection/xous/tcpstream.rs +++ b/library/std/src/sys/net/connection/xous/tcpstream.rs @@ -392,6 +392,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 ce54ea3b79ef8..57e4407d7c8cd 100644 --- a/library/std/src/sys/net/connection/xous/udp.rs +++ b/library/std/src/sys/net/connection/xous/udp.rs @@ -383,6 +383,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) @@ -418,6 +426,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 c21d1de81341f..446953942b55e 100644 --- a/library/std/src/sys/pal/windows/c/bindings.txt +++ b/library/std/src/sys/pal/windows/c/bindings.txt @@ -2256,7 +2256,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 eb54efd1c1fe0..f33a56e9419a8 100644 --- a/library/std/src/sys/pal/windows/c/windows_sys.rs +++ b/library/std/src/sys/pal/windows/c/windows_sys.rs @@ -2886,7 +2886,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 d0b87e74066c39ee80087c9ed98c60d169bf44b3 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 20 Mar 2025 16:03:05 +0100 Subject: [PATCH 2/9] 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 189c206c3dc78..37012944ca7c5 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -564,7 +564,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"); /// ``` @@ -583,7 +583,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); @@ -998,7 +998,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")] @@ -1016,7 +1016,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 7f017b4be4694..9ba3388c73ed3 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -592,7 +592,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")] @@ -610,7 +610,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); /// ``` @@ -630,7 +630,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")] @@ -648,7 +648,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 96b0d97d63325e9e38fc8648a313996881dd4db8 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 31 Mar 2025 12:04:44 +0200 Subject: [PATCH 3/9] 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 37012944ca7c5..133e32169673a 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -568,7 +568,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) } @@ -588,7 +588,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() } @@ -1001,7 +1001,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) } @@ -1020,7 +1020,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 9ba3388c73ed3..c2a53d1ae535b 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -595,7 +595,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) } @@ -614,7 +614,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() } @@ -633,7 +633,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) } @@ -652,7 +652,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 901e36bf36a4a0d9cc8fc3d76e5a0990589171b3 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 31 Mar 2025 12:06:28 +0200 Subject: [PATCH 4/9] 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 133e32169673a..2931672a88c2f 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -553,7 +553,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 b3c63c8ad83a3abca37598aa7609e50d83317044 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 16 Apr 2025 12:20:56 +0200 Subject: [PATCH 5/9] 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 7532e2486375f..3fbb8c00390af 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 1fbe87109034d..49367ef39ace0 100644 --- a/library/std/src/sys/net/connection/xous/tcpstream.rs +++ b/library/std/src/sys/net/connection/xous/tcpstream.rs @@ -392,7 +392,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 57e4407d7c8cd..de162773da791 100644 --- a/library/std/src/sys/net/connection/xous/udp.rs +++ b/library/std/src/sys/net/connection/xous/udp.rs @@ -383,7 +383,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!(); } From eadb89ebca5c537dfdf93eea535e4e9b58350662 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Tue, 24 Mar 2026 12:27:38 +0100 Subject: [PATCH 6/9] fix: add cfg guards on unsupported wasi p2 and p3 targets --- library/std/src/net/tcp.rs | 4 ++++ library/std/src/net/tcp/tests.rs | 1 + library/std/src/net/udp.rs | 4 ++++ library/std/src/net/udp/tests.rs | 1 + library/std/src/sys/net/connection/socket/mod.rs | 8 ++++++++ 5 files changed, 18 insertions(+) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 2931672a88c2f..eb9806774a812 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -569,6 +569,7 @@ impl TcpStream { /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -589,6 +590,7 @@ impl TcpStream { /// assert_eq!(stream.hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } @@ -1002,6 +1004,7 @@ impl TcpListener { /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -1021,6 +1024,7 @@ impl TcpListener { /// assert_eq!(listener.hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } diff --git a/library/std/src/net/tcp/tests.rs b/library/std/src/net/tcp/tests.rs index b2e2be5530447..e4dd1dda6f9ed 100644 --- a/library/std/src/net/tcp/tests.rs +++ b/library/std/src/net/tcp/tests.rs @@ -878,6 +878,7 @@ fn ttl() { #[test] #[cfg_attr(target_env = "sgx", ignore)] +#[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] fn hop_limit() { let hlim = 100; diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index c2a53d1ae535b..fdb33e2fdc6be 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -596,6 +596,7 @@ impl UdpSocket { /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -615,6 +616,7 @@ impl UdpSocket { /// assert_eq!(socket.hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } @@ -634,6 +636,7 @@ impl UdpSocket { /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_multicast_hop_limit_v6(limit) } @@ -653,6 +656,7 @@ impl UdpSocket { /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0.multicast_hop_limit_v6() } diff --git a/library/std/src/net/udp/tests.rs b/library/std/src/net/udp/tests.rs index a2b1555d1b9ac..7ae5d6e70fb31 100644 --- a/library/std/src/net/udp/tests.rs +++ b/library/std/src/net/udp/tests.rs @@ -359,6 +359,7 @@ fn ttl() { } #[test] +#[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] fn hop_limit() { let hlim = 100; diff --git a/library/std/src/sys/net/connection/socket/mod.rs b/library/std/src/sys/net/connection/socket/mod.rs index e6b90129e0867..eea4de0065c17 100644 --- a/library/std/src/sys/net/connection/socket/mod.rs +++ b/library/std/src/sys/net/connection/socket/mod.rs @@ -485,10 +485,12 @@ impl TcpStream { Ok(raw as u32) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) @@ -622,10 +624,12 @@ impl TcpListener { Ok(raw as u32) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) @@ -851,19 +855,23 @@ impl UdpSocket { Ok(raw as u32) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) From efe66ba7046265da83f1fd7a06501e4ee0fab5ab Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Tue, 24 Mar 2026 13:10:36 +0100 Subject: [PATCH 7/9] fix: tidy PAL and unsafe blocks CI failure --- library/std/src/lib.rs | 7 ++- library/std/src/net/tcp.rs | 4 -- library/std/src/net/udp.rs | 4 -- .../std/src/sys/net/connection/socket/mod.rs | 56 ++++++++++++++++--- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 6af76ca64ae64..20f9d2e68fc20 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -342,10 +342,11 @@ #![feature(hint_must_use)] #![feature(int_from_ascii)] #![feature(ip)] +#![feature(iter_advance_by)] +#![feature(iter_next_chunk)] #![feature(ipv6_hop_limit)] -#![feature(lazy_get)] -#![feature(maybe_uninit_slice)] -#![feature(maybe_uninit_write_slice)] +#![feature(maybe_uninit_array_assume_init)] +#![feature(maybe_uninit_fill)] #![feature(panic_can_unwind)] #![feature(panic_internals)] #![feature(pin_coerce_unsized_trait)] diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index eb9806774a812..2931672a88c2f 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -569,7 +569,6 @@ impl TcpStream { /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -590,7 +589,6 @@ impl TcpStream { /// assert_eq!(stream.hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } @@ -1004,7 +1002,6 @@ impl TcpListener { /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -1024,7 +1021,6 @@ impl TcpListener { /// assert_eq!(listener.hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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 fdb33e2fdc6be..c2a53d1ae535b 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -596,7 +596,6 @@ impl UdpSocket { /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -616,7 +615,6 @@ impl UdpSocket { /// assert_eq!(socket.hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { self.0.hop_limit_v6() } @@ -636,7 +634,6 @@ impl UdpSocket { /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { self.0.set_multicast_hop_limit_v6(limit) } @@ -656,7 +653,6 @@ impl UdpSocket { /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "139166")] - #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0.multicast_hop_limit_v6() } diff --git a/library/std/src/sys/net/connection/socket/mod.rs b/library/std/src/sys/net/connection/socket/mod.rs index eea4de0065c17..18f4167b77b55 100644 --- a/library/std/src/sys/net/connection/socket/mod.rs +++ b/library/std/src/sys/net/connection/socket/mod.rs @@ -487,15 +487,25 @@ impl TcpStream { #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) + unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } + } + + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) } #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)? }; Ok(raw as u8) } + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn hop_limit_v6(&self) -> io::Result { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) + } + pub fn take_error(&self) -> io::Result> { self.inner.take_error() } @@ -626,15 +636,25 @@ impl TcpListener { #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) + unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } + } + + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) } #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)? }; Ok(raw as u8) } + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn hop_limit_v6(&self) -> io::Result { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) + } + pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } } @@ -857,26 +877,46 @@ impl UdpSocket { #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) + unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } + } + + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) } #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn hop_limit_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)? }; Ok(raw as u8) } + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn hop_limit_v6(&self) -> io::Result { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) + } + #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] 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) + unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) } + } + + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) } #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn multicast_hop_limit_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; + let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)? }; Ok(raw as u8) } + #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] + pub fn multicast_hop_limit_v6(&self) -> io::Result { + Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) + } + pub fn take_error(&self) -> io::Result> { self.inner.take_error() } From 847b70647ff04fc908698f377625a0f20630c7dc Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Tue, 24 Mar 2026 15:02:06 +0100 Subject: [PATCH 8/9] fix: tidy CI --- library/std/src/sys/net/connection/socket/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/net/connection/socket/mod.rs b/library/std/src/sys/net/connection/socket/mod.rs index 18f4167b77b55..b288d9d3e51ff 100644 --- a/library/std/src/sys/net/connection/socket/mod.rs +++ b/library/std/src/sys/net/connection/socket/mod.rs @@ -908,7 +908,8 @@ impl UdpSocket { #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] pub fn multicast_hop_limit_v6(&self) -> io::Result { - let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)? }; + let raw: c_int = + unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)? }; Ok(raw as u8) } From 7402270ac78d695f6867e80a7e352e63c733975c Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Tue, 24 Mar 2026 15:18:30 +0100 Subject: [PATCH 9/9] fix: tidy CI --- library/std/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 20f9d2e68fc20..5e28b7e853798 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -342,9 +342,9 @@ #![feature(hint_must_use)] #![feature(int_from_ascii)] #![feature(ip)] +#![feature(ipv6_hop_limit)] #![feature(iter_advance_by)] #![feature(iter_next_chunk)] -#![feature(ipv6_hop_limit)] #![feature(maybe_uninit_array_assume_init)] #![feature(maybe_uninit_fill)] #![feature(panic_can_unwind)]