@@ -532,6 +532,34 @@ impl Ipv4Addr {
532
532
!self . is_broadcast ( ) && !self . is_documentation ( ) && !self . is_unspecified ( )
533
533
}
534
534
535
+ /// Returns [`true`] if this address is reserved by IANA for future use. [IETF RFC 1112]
536
+ /// defines the block of reserved addresses as `240.0.0.0/4`. This range normally includes the
537
+ /// broadcast address `255.255.255.255`, but this implementation explicitely excludes it, since
538
+ /// it is obviously not reserved for future use.
539
+ ///
540
+ /// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112
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(240, 0, 0, 0).is_reserved(), true);
551
+ /// assert_eq!(Ipv4Addr::new(255, 255, 255, 254).is_reserved(), true);
552
+ ///
553
+ /// assert_eq!(Ipv4Addr::new(239, 255, 255, 255).is_reserved(), false);
554
+ /// // The broadcast address is not considered as reserved for future use by this
555
+ /// // implementation
556
+ /// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_reserved(), false);
557
+ /// }
558
+ /// ```
559
+ pub fn is_reserved ( & self ) -> bool {
560
+ self . octets ( ) [ 0 ] & 240 == 240 && !self . is_broadcast ( )
561
+ }
562
+
535
563
/// Returns [`true`] if this is a multicast address (224.0.0.0/4).
536
564
///
537
565
/// Multicast addresses have a most significant octet between 224 and 239,
0 commit comments