Skip to content

Tracking Issue for #138744: Add methods to TCP and UDP sockets to modify IPv6 hop limits #139166

@Mallets

Description

@Mallets

Feature gate: #![feature(ipv6_hop_limit)]

This is a tracking issue for adding methods to set the values for IPV6_UNICAST_HOPS and IPV6_MULTICAST_HOPS on TCP and UDP ipv6 sockets.

Public API

TCP sockets

impl TcpStream {
  /// #![feature(ipv6_hop_limit)]
  /// use std::net::TcpStream;
  ///
  /// 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");
  /// ```
  pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()>;

  /// 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("[::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);
  /// ```
  pub fn hop_limit_v6(&self) -> io::Result<u8>;
}

impl TcpListener {
  /// 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("[::1]:12345").unwrap();
  /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed");
  /// ```
  pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()>;

  /// 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("[::1]:12345").unwrap();
  /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed");
  /// assert_eq!(listener.hop_limit_v6().unwrap(), 88);
  /// ```
  pub fn hop_limit_v6(&self) -> io::Result<u8>;
}

UDP sockets

impl UdpSocket {
  /// 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("[::1]:12345").expect("couldn't bind to address");
  /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed");
  /// ```
  pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()>;

  /// 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("[::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);
  /// ```
  pub fn hop_limit_v6(&self) -> io::Result<u8>;

  /// 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("[::1]:12345").expect("couldn't bind to address");
  /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed");
  /// ```
  pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()>;

  /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket.
  ///
  /// # Examples
  ///
  /// ```no_run
  /// #![feature(ipv6_hop_limit)]
  /// use std::net::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");
  /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88);
  /// ```
  pub fn multicast_hop_limit_v6(&self) -> io::Result<u8>;
}

Steps

History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Activity

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Mar 31, 2025
added 2 commits that reference this issue on Apr 13, 2025
ac13f79
dca6dc5
added a commit that references this issue on May 25, 2025
5d2ead3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Mallets

        Issue actions

          Tracking Issue for #138744: Add methods to TCP and UDP sockets to modify IPv6 hop limits · Issue #139166 · rust-lang/rust