Skip to content
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

std::net: Ipv4Addr and Ipv6Addr improvements #60145

Merged
merged 20 commits into from
Jun 1, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
02d815f
std::net: site-local ipv6 prefixes are global
little-dude Nov 19, 2018
5aea184
std::net: improve Ipv6Addr::is_unicast_site_local() doc
little-dude Nov 19, 2018
1f0aa40
std::net: add Ipv6Addr::is_unicast_link_local_strict()
little-dude Nov 19, 2018
aea687c
std::net: fix doc markdown in Ipv6Addr::is_unique_local()
little-dude Nov 19, 2018
8f67997
std::net: add Ipv4Addr::is_reserved()
little-dude Nov 19, 2018
de3cf0d
std::net: add Ipv4Addr::is_benchmarking()
little-dude Nov 19, 2018
f87b967
std::net: add Ipv4Addr::is_ietf_protocol_assignment()
little-dude Nov 19, 2018
67291cc
std::net: add Ipv4Addr::is_shared()
little-dude Nov 19, 2018
9f6a747
std::net: fix Ipv4Addr::is_global()
little-dude Nov 19, 2018
8106320
std::net: fix documentation markdown
little-dude Nov 20, 2018
c34bcc6
std::net: use macros to test ip properties
little-dude Nov 20, 2018
c302d2c
std::net: fix Ipv4addr::is_global() tests
little-dude Apr 20, 2019
99d9bb6
std::net: fix tests for site-local ipv6 addresses
little-dude Apr 21, 2019
40d0127
std::net: tests for Ipv6addr::is_unicast_link_local{_strict}()
little-dude Apr 22, 2019
9dcfd9f
std::net: tests for Ipv4addr::is_benchmarking()
little-dude Apr 22, 2019
a2bead8
std::net: tests for Ipv4addr::is_ietf_protocol_assignment()
little-dude Apr 22, 2019
6662777
std::net: tests for Ipv4addr::is_reserved()
little-dude Apr 22, 2019
634dcd0
std::net: add warning in Ipv6Addr::is_unicast_site_local() doc
little-dude Apr 23, 2019
fe718ef
std::net: add warning in Ipv4addr::is_reserved() documentation
little-dude Apr 23, 2019
cddb838
std::net: tests for Ipv4addr::is_shared()
little-dude Apr 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
std::net: add Ipv4Addr::is_ietf_protocol_assignment()
  • Loading branch information
little-dude committed Apr 22, 2019
commit f87b96773b0fbbfa24781c58af7a73b816c7d658
34 changes: 34 additions & 0 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,40 @@ impl Ipv4Addr {
!self.is_broadcast() && !self.is_documentation() && !self.is_unspecified()
}

/// Returns [`true`] if this address is part of `192.0.0.0/24`, which is reserved to
/// IANA for IETF protocol assignments, as documented in [IETF RFC 6890].
///
/// Note that parts of this block are in use:
///
/// - `192.0.0.8/32` is the "IPv4 dummy address" (see [IETF RFC 7600])
/// - `192.0.0.9/32` is the "Port Control Protocol Anycast" (see [IETF RFC 7723])
/// - `192.0.0.10/32` is used for NAT traversal (see [IETF RFC 8155])
///
/// [IETF RFC 6890]: https://tools.ietf.org/html/rfc6890
/// [IETF RFC 7600]: https://tools.ietf.org/html/rfc7600
/// [IETF RFC 7723]: https://tools.ietf.org/html/rfc7723
/// [IETF RFC 8155]: https://tools.ietf.org/html/rfc8155
/// [`true`]: ../../std/primitive.bool.html
///
/// # Examples
///
/// ```
/// #![feature(ip)]
/// use std::net::Ipv4Addr;
///
/// fn main() {
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_ietf_protocol_assignment(), true);
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 8).is_ietf_protocol_assignment(), true);
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 9).is_ietf_protocol_assignment(), true);
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_ietf_protocol_assignment(), true);
/// assert_eq!(Ipv4Addr::new(192, 0, 1, 0).is_ietf_protocol_assignment(), false);
/// assert_eq!(Ipv4Addr::new(191, 255, 255, 255).is_ietf_protocol_assignment(), false);
/// }
/// ```
pub fn is_ietf_protocol_assignment(&self) -> bool {
self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0
}

/// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for
/// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0`
/// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`.
Expand Down