Skip to content

Commit c5f3706

Browse files
authored
Auto merge of #34263 - ollie27:docs_ip, r=alexcrichton
Improve IP reserved address docs - Add links to all RFCs to make it clear these are not Rust RFCs. - Correct RFC numbers to match the numbers in [RFC 6890](https://tools.ietf.org/html/rfc6890) - Clean up formatting to show addresses and ranges in parentheses like (255.255.255.255) r? @steveklabnik
2 parents 1a942f6 + 61043fd commit c5f3706

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/libstd/net/ip.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,24 @@ impl Ipv4Addr {
8282
[(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8]
8383
}
8484

85-
/// Returns true for the special 'unspecified' address 0.0.0.0.
85+
/// Returns true for the special 'unspecified' address (0.0.0.0).
8686
pub fn is_unspecified(&self) -> bool {
8787
self.inner.s_addr == 0
8888
}
8989

9090
/// Returns true if this is a loopback address (127.0.0.0/8).
9191
///
92-
/// This property is defined by RFC 6890.
92+
/// This property is defined by [RFC 1122].
93+
/// [RFC 1122]: https://tools.ietf.org/html/rfc1122
9394
#[stable(since = "1.7.0", feature = "ip_17")]
9495
pub fn is_loopback(&self) -> bool {
9596
self.octets()[0] == 127
9697
}
9798

9899
/// Returns true if this is a private address.
99100
///
100-
/// The private address ranges are defined in RFC 1918 and include:
101+
/// The private address ranges are defined in [RFC 1918] and include:
102+
/// [RFC 1918]: https://tools.ietf.org/html/rfc1918
101103
///
102104
/// - 10.0.0.0/8
103105
/// - 172.16.0.0/12
@@ -114,7 +116,8 @@ impl Ipv4Addr {
114116

115117
/// Returns true if the address is link-local (169.254.0.0/16).
116118
///
117-
/// This property is defined by RFC 6890.
119+
/// This property is defined by [RFC 3927].
120+
/// [RFC 3927]: https://tools.ietf.org/html/rfc3927
118121
#[stable(since = "1.7.0", feature = "ip_17")]
119122
pub fn is_link_local(&self) -> bool {
120123
self.octets()[0] == 169 && self.octets()[1] == 254
@@ -137,18 +140,20 @@ impl Ipv4Addr {
137140
!self.is_broadcast() && !self.is_documentation() && !self.is_unspecified()
138141
}
139142

140-
/// Returns true if this is a multicast address.
143+
/// Returns true if this is a multicast address (224.0.0.0/4).
141144
///
142145
/// Multicast addresses have a most significant octet between 224 and 239,
143-
/// and is defined by RFC 5771.
146+
/// and is defined by [RFC 5771].
147+
/// [RFC 5771]: https://tools.ietf.org/html/rfc5771
144148
#[stable(since = "1.7.0", feature = "ip_17")]
145149
pub fn is_multicast(&self) -> bool {
146150
self.octets()[0] >= 224 && self.octets()[0] <= 239
147151
}
148152

149-
/// Returns true if this is a broadcast address.
153+
/// Returns true if this is a broadcast address (255.255.255.255).
150154
///
151-
/// A broadcast address has all octets set to 255 as defined in RFC 919.
155+
/// A broadcast address has all octets set to 255 as defined in [RFC 919].
156+
/// [RFC 919]: https://tools.ietf.org/html/rfc919
152157
#[stable(since = "1.7.0", feature = "ip_17")]
153158
pub fn is_broadcast(&self) -> bool {
154159
self.octets()[0] == 255 && self.octets()[1] == 255 &&
@@ -157,7 +162,8 @@ impl Ipv4Addr {
157162

158163
/// Returns true if this address is in a range designated for documentation.
159164
///
160-
/// This is defined in RFC 5737:
165+
/// This is defined in [RFC 5737]:
166+
/// [RFC 5737]: https://tools.ietf.org/html/rfc5737
161167
///
162168
/// - 192.0.2.0/24 (TEST-NET-1)
163169
/// - 198.51.100.0/24 (TEST-NET-2)
@@ -321,17 +327,19 @@ impl Ipv6Addr {
321327
]
322328
}
323329

324-
/// Returns true for the special 'unspecified' address ::.
330+
/// Returns true for the special 'unspecified' address (::).
325331
///
326-
/// This property is defined in RFC 6890.
332+
/// This property is defined in [RFC 4291].
333+
/// [RFC 4291]: https://tools.ietf.org/html/rfc4291
327334
#[stable(since = "1.7.0", feature = "ip_17")]
328335
pub fn is_unspecified(&self) -> bool {
329336
self.segments() == [0, 0, 0, 0, 0, 0, 0, 0]
330337
}
331338

332339
/// Returns true if this is a loopback address (::1).
333340
///
334-
/// This property is defined in RFC 6890.
341+
/// This property is defined in [RFC 4291].
342+
/// [RFC 4291]: https://tools.ietf.org/html/rfc4291
335343
#[stable(since = "1.7.0", feature = "ip_17")]
336344
pub fn is_loopback(&self) -> bool {
337345
self.segments() == [0, 0, 0, 0, 0, 0, 0, 1]
@@ -352,26 +360,33 @@ impl Ipv6Addr {
352360
}
353361
}
354362

355-
/// Returns true if this is a unique local address (IPv6).
363+
/// Returns true if this is a unique local address (fc00::/7).
356364
///
357-
/// Unique local addresses are defined in RFC 4193 and have the form fc00::/7.
365+
/// This property is defined in [RFC 4193].
366+
/// [RFC 4193]: https://tools.ietf.org/html/rfc4193
358367
pub fn is_unique_local(&self) -> bool {
359368
(self.segments()[0] & 0xfe00) == 0xfc00
360369
}
361370

362371
/// Returns true if the address is unicast and link-local (fe80::/10).
372+
///
373+
/// This property is defined in [RFC 4291].
374+
/// [RFC 4291]: https://tools.ietf.org/html/rfc4291
363375
pub fn is_unicast_link_local(&self) -> bool {
364376
(self.segments()[0] & 0xffc0) == 0xfe80
365377
}
366378

367-
/// Returns true if this is a deprecated unicast site-local address (IPv6
368-
/// fec0::/10).
379+
/// Returns true if this is a deprecated unicast site-local address
380+
/// (fec0::/10).
369381
pub fn is_unicast_site_local(&self) -> bool {
370382
(self.segments()[0] & 0xffc0) == 0xfec0
371383
}
372384

373385
/// Returns true if this is an address reserved for documentation
374-
/// This is defined to be 2001:db8::/32 in RFC 3849.
386+
/// (2001:db8::/32).
387+
///
388+
/// This property is defined in [RFC 3849].
389+
/// [RFC 3849]: https://tools.ietf.org/html/rfc3849
375390
pub fn is_documentation(&self) -> bool {
376391
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
377392
}
@@ -411,10 +426,10 @@ impl Ipv6Addr {
411426
}
412427
}
413428

414-
/// Returns true if this is a multicast address.
429+
/// Returns true if this is a multicast address (ff00::/8).
415430
///
416-
/// Multicast addresses have the form ff00::/8, and this property is defined
417-
/// by RFC 3956.
431+
/// This property is defined by [RFC 4291].
432+
/// [RFC 4291]: https://tools.ietf.org/html/rfc4291
418433
#[stable(since = "1.7.0", feature = "ip_17")]
419434
pub fn is_multicast(&self) -> bool {
420435
(self.segments()[0] & 0xff00) == 0xff00

0 commit comments

Comments
 (0)