-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add methods to TCP and UDP sockets to modify hop limit #94678
Changes from 6 commits
ac288b4
44c2226
c60ab7b
090c1c9
6d0d29e
36096cf
b3e9e94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,6 +540,86 @@ 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: u32) -> 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<u32> { | ||
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::TcpStream; | ||
/// | ||
/// let stream = TcpStream::connect("127.0.0.1:54321") | ||
/// .expect("Couldn't connect to the server..."); | ||
/// stream.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); | ||
/// ``` | ||
#[unstable(feature = "ipv6_hop_limit", issue = "47727")] | ||
pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why thi is "hlim" here but "hop_limit" for unicast There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to keep the length of the method name from being too long. Should I change it to "hop_limit"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Rust doesn't generally abbreviate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the method names. |
||
self.0.set_multicast_hlim_v6(limit) | ||
} | ||
|
||
/// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. | ||
/// | ||
/// For more information about this option, see [`TcpStream::set_multicast_hlim_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_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); | ||
/// assert_eq!(stream.multicast_hlim_v6().unwrap(), 88); | ||
/// ``` | ||
#[unstable(feature = "ipv6_hop_limit", issue = "47727")] | ||
pub fn multicast_hlim_v6(&self) -> io::Result<u32> { | ||
self.0.multicast_hlim_v6() | ||
} | ||
|
||
/// Gets the value of the `SO_ERROR` option on this socket. | ||
/// | ||
/// This will retrieve the stored error in the underlying socket, clearing | ||
|
@@ -914,6 +994,82 @@ 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: u32) -> 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<u32> { | ||
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::TcpListener; | ||
/// | ||
/// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); | ||
/// listener.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); | ||
/// ``` | ||
#[unstable(feature = "ipv6_hop_limit", issue = "47727")] | ||
pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { | ||
self.0.set_multicast_hlim_v6(limit) | ||
} | ||
|
||
/// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. | ||
/// | ||
/// For more information about this option, see [`TcpListener::set_multicast_hlim_v6`]. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// #![feature(ipv6_hop_limit)] | ||
/// use std::net::TcpListener; | ||
/// | ||
/// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); | ||
/// listener.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); | ||
/// assert_eq!(listener.multicast_hlim_v6().unwrap(), 88); | ||
/// ``` | ||
#[unstable(feature = "ipv6_hop_limit", issue = "47727")] | ||
pub fn multicast_hlim_v6(&self) -> io::Result<u32> { | ||
self.0.multicast_hlim_v6() | ||
} | ||
|
||
#[stable(feature = "net2_mutators", since = "1.9.0")] | ||
#[rustc_deprecated( | ||
since = "1.16.0", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hop Limit is an 8bit header field. So using
u8
instead ofu32
would reflect that better and avoid API misusage like #73158.