about summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorCorentin Henry <corentinhenry@gmail.com>2018-11-19 09:37:21 -0800
committerCorentin Henry <corentinhenry@gmail.com>2019-04-22 16:03:39 +0200
commitde3cf0d5eb30be7b2a297151af1528314664bd69 (patch)
tree5fb48292c685cf6212a56bfd9e910d98d968a2a1 /src/libstd/net
parent8f679977e00dba29819aedbcfaf14927a4136430 (diff)
downloadrust-de3cf0d5eb30be7b2a297151af1528314664bd69.tar.gz
rust-de3cf0d5eb30be7b2a297151af1528314664bd69.zip
std::net: add Ipv4Addr::is_benchmarking()
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/ip.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs
index f94923d28d2..6e9c6588a1d 100644
--- a/src/libstd/net/ip.rs
+++ b/src/libstd/net/ip.rs
@@ -532,6 +532,31 @@ impl Ipv4Addr {
         !self.is_broadcast() && !self.is_documentation() && !self.is_unspecified()
     }
 
+    /// 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`.
+    ///
+    /// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112
+    /// [errate 423]: https://www.rfc-editor.org/errata/eid423
+    /// [`true`]: ../../std/primitive.bool.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(ip)]
+    /// use std::net::Ipv4Addr;
+    ///
+    /// fn main() {
+    ///     assert_eq!(Ipv4Addr::new(198, 17, 255, 255).is_benchmarking(), false);
+    ///     assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_benchmarking(), true);
+    ///     assert_eq!(Ipv4Addr::new(198, 19, 255, 255).is_benchmarking(), true);
+    ///     assert_eq!(Ipv4Addr::new(198, 20, 0, 0).is_benchmarking(), false);
+    /// }
+    /// ```
+    pub fn is_benchmarking(&self) -> bool {
+        self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18
+    }
+
     /// Returns [`true`] if this address is reserved by IANA for future use. [IETF RFC 1112]
     /// defines the block of reserved addresses as `240.0.0.0/4`. This range normally includes the
     /// broadcast address `255.255.255.255`, but this implementation explicitely excludes it, since