Skip to content

Commit de3cf0d

Browse files
committed
std::net: add Ipv4Addr::is_benchmarking()
1 parent 8f67997 commit de3cf0d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/libstd/net/ip.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,31 @@ impl Ipv4Addr {
532532
!self.is_broadcast() && !self.is_documentation() && !self.is_unspecified()
533533
}
534534

535+
/// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for
536+
/// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0`
537+
/// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`.
538+
///
539+
/// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112
540+
/// [errate 423]: https://www.rfc-editor.org/errata/eid423
541+
/// [`true`]: ../../std/primitive.bool.html
542+
///
543+
/// # Examples
544+
///
545+
/// ```
546+
/// #![feature(ip)]
547+
/// use std::net::Ipv4Addr;
548+
///
549+
/// fn main() {
550+
/// assert_eq!(Ipv4Addr::new(198, 17, 255, 255).is_benchmarking(), false);
551+
/// assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_benchmarking(), true);
552+
/// assert_eq!(Ipv4Addr::new(198, 19, 255, 255).is_benchmarking(), true);
553+
/// assert_eq!(Ipv4Addr::new(198, 20, 0, 0).is_benchmarking(), false);
554+
/// }
555+
/// ```
556+
pub fn is_benchmarking(&self) -> bool {
557+
self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18
558+
}
559+
535560
/// Returns [`true`] if this address is reserved by IANA for future use. [IETF RFC 1112]
536561
/// defines the block of reserved addresses as `240.0.0.0/4`. This range normally includes the
537562
/// broadcast address `255.255.255.255`, but this implementation explicitely excludes it, since

0 commit comments

Comments
 (0)