@@ -116,16 +116,58 @@ pub struct Ipv6Addr {
116116 inner : c:: in6_addr ,
117117}
118118
119- #[ allow( missing_docs) ]
119+ /// Scope of an [IPv6 multicast address] as defined in [IETF RFC 7346 section 2].
120+ ///
121+ /// # Stability Guarantees
122+ ///
123+ /// Not all possible values for a multicast scope have been assigned.
124+ /// Future RFCs may introduce new scopes, which will be added as variants to this enum;
125+ /// because of this the enum is marked as `#[non_exhaustive]`.
126+ ///
127+ /// # Examples
128+ /// ```
129+ /// #![feature(ip)]
130+ ///
131+ /// use std::net::Ipv6Addr;
132+ /// use std::net::Ipv6MulticastScope::*;
133+ ///
134+ /// // An IPv6 multicast address with global scope (`ff0e::`).
135+ /// let address = Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0);
136+ ///
137+ /// // Will print "Global scope".
138+ /// match address.multicast_scope() {
139+ /// Some(InterfaceLocal) => println!("Interface-Local scope"),
140+ /// Some(LinkLocal) => println!("Link-Local scope"),
141+ /// Some(RealmLocal) => println!("Realm-Local scope"),
142+ /// Some(AdminLocal) => println!("Admin-Local scope"),
143+ /// Some(SiteLocal) => println!("Site-Local scope"),
144+ /// Some(OrganizationLocal) => println!("Organization-Local scope"),
145+ /// Some(Global) => println!("Global scope"),
146+ /// Some(_) => println!("Unknown scope"),
147+ /// None => println!("Not a multicast address!")
148+ /// }
149+ ///
150+ /// ```
151+ ///
152+ /// [IPv6 multicast address]: Ipv6Addr
153+ /// [IETF RFC 7346 section 2]: https://tools.ietf.org/html/rfc7346#section-2
120154#[ derive( Copy , PartialEq , Eq , Clone , Hash , Debug ) ]
121155#[ unstable( feature = "ip" , issue = "27709" ) ]
156+ #[ non_exhaustive]
122157pub enum Ipv6MulticastScope {
158+ /// Interface-Local scope.
123159 InterfaceLocal ,
160+ /// Link-Local scope.
124161 LinkLocal ,
162+ /// Realm-Local scope.
125163 RealmLocal ,
164+ /// Admin-Local scope.
126165 AdminLocal ,
166+ /// Site-Local scope.
127167 SiteLocal ,
168+ /// Organization-Local scope.
128169 OrganizationLocal ,
170+ /// Global scope.
129171 Global ,
130172}
131173
@@ -486,8 +528,7 @@ impl Ipv4Addr {
486528 /// - addresses used for documentation (see [`Ipv4Addr::is_documentation()`])
487529 /// - the unspecified address (see [`Ipv4Addr::is_unspecified()`]), and the whole
488530 /// `0.0.0.0/8` block
489- /// - addresses reserved for future protocols (see
490- /// [`Ipv4Addr::is_ietf_protocol_assignment()`], except
531+ /// - addresses reserved for future protocols, except
491532 /// `192.0.0.9/32` and `192.0.0.10/32` which are globally routable
492533 /// - addresses reserved for future use (see [`Ipv4Addr::is_reserved()`]
493534 /// - addresses reserved for networking devices benchmarking (see
@@ -560,7 +601,8 @@ impl Ipv4Addr {
560601 && !self . is_broadcast ( )
561602 && !self . is_documentation ( )
562603 && !self . is_shared ( )
563- && !self . is_ietf_protocol_assignment ( )
604+ // addresses reserved for future protocols (`192.0.0.0/24`)
605+ && !( self . octets ( ) [ 0 ] == 192 && self . octets ( ) [ 1 ] == 0 && self . octets ( ) [ 2 ] == 0 )
564606 && !self . is_reserved ( )
565607 && !self . is_benchmarking ( )
566608 // Make sure the address is not in 0.0.0.0/8
@@ -589,40 +631,6 @@ impl Ipv4Addr {
589631 self . octets ( ) [ 0 ] == 100 && ( self . octets ( ) [ 1 ] & 0b1100_0000 == 0b0100_0000 )
590632 }
591633
592- /// Returns [`true`] if this address is part of `192.0.0.0/24`, which is reserved to
593- /// IANA for IETF protocol assignments, as documented in [IETF RFC 6890].
594- ///
595- /// Note that parts of this block are in use:
596- ///
597- /// - `192.0.0.8/32` is the "IPv4 dummy address" (see [IETF RFC 7600])
598- /// - `192.0.0.9/32` is the "Port Control Protocol Anycast" (see [IETF RFC 7723])
599- /// - `192.0.0.10/32` is used for NAT traversal (see [IETF RFC 8155])
600- ///
601- /// [IETF RFC 6890]: https://tools.ietf.org/html/rfc6890
602- /// [IETF RFC 7600]: https://tools.ietf.org/html/rfc7600
603- /// [IETF RFC 7723]: https://tools.ietf.org/html/rfc7723
604- /// [IETF RFC 8155]: https://tools.ietf.org/html/rfc8155
605- ///
606- /// # Examples
607- ///
608- /// ```
609- /// #![feature(ip)]
610- /// use std::net::Ipv4Addr;
611- ///
612- /// assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_ietf_protocol_assignment(), true);
613- /// assert_eq!(Ipv4Addr::new(192, 0, 0, 8).is_ietf_protocol_assignment(), true);
614- /// assert_eq!(Ipv4Addr::new(192, 0, 0, 9).is_ietf_protocol_assignment(), true);
615- /// assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_ietf_protocol_assignment(), true);
616- /// assert_eq!(Ipv4Addr::new(192, 0, 1, 0).is_ietf_protocol_assignment(), false);
617- /// assert_eq!(Ipv4Addr::new(191, 255, 255, 255).is_ietf_protocol_assignment(), false);
618- /// ```
619- #[ rustc_const_unstable( feature = "const_ipv4" , issue = "76205" ) ]
620- #[ unstable( feature = "ip" , issue = "27709" ) ]
621- #[ inline]
622- pub const fn is_ietf_protocol_assignment ( & self ) -> bool {
623- self . octets ( ) [ 0 ] == 192 && self . octets ( ) [ 1 ] == 0 && self . octets ( ) [ 2 ] == 0
624- }
625-
626634 /// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for
627635 /// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0`
628636 /// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`.
0 commit comments