Skip to content

Commit 6f0c742

Browse files
committed
Expanded and added links to std::net::{SocketAddr,SocketAddrV4,SocketAddrV6} docs
Part of #29363 Changed summary sentences of SocketAddr and IpAddr for consistency Linked to SocketAddrV4 and SocketAddrV6 from SocketAddr, moving explaination there Expanded top-level docs for SocketAddrV4 and SocketAddrV6, linking to some relevant IETF RFCs, and linking back to SocketAddr Changed some of the method summaries to third person as per RFC 1574; added links to IETF RFCs where appropriate
1 parent be713fa commit 6f0c742

File tree

2 files changed

+90
-26
lines changed

2 files changed

+90
-26
lines changed

src/libstd/net/addr.rs

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,57 @@ use vec;
2020
use iter;
2121
use slice;
2222

23-
/// Representation of a socket address for networking applications.
23+
/// An internet socket address, either IPv4 or IPv6.
2424
///
25-
/// A socket address can either represent the IPv4 or IPv6 protocol and is
26-
/// paired with at least a port number as well. Each protocol may have more
27-
/// specific information about the address available to it as well.
25+
/// This enum can contain either an [`SocketAddrV4`] or an [`SocketAddrV6`]. see their
26+
/// respective documentation for more details.
27+
///
28+
/// [`SocketAddrV4`]: ../../std/net/struct.SocketAddrV4.html
29+
/// [`SocketAddrV6`]: ../../std/net/struct.SocketAddrV6.html
2830
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
2931
#[stable(feature = "rust1", since = "1.0.0")]
3032
pub enum SocketAddr {
31-
/// An IPv4 socket address which is a (ip, port) combination.
33+
/// An IPv4 socket address.
3234
#[stable(feature = "rust1", since = "1.0.0")]
3335
V4(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV4),
3436
/// An IPv6 socket address.
3537
#[stable(feature = "rust1", since = "1.0.0")]
3638
V6(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV6),
3739
}
3840

39-
/// An IPv4 socket address which is a (ip, port) combination.
41+
/// An IPv4 socket address.
42+
///
43+
/// IPv4 socket addresses consist of an [IPv4 address] and a 16-bit port number, as
44+
/// stated in [IETF RFC 793].
45+
///
46+
/// See [`SocketAddr`] for a type encompassing both IPv4 and IPv6 socket addresses.
47+
///
48+
/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793
49+
/// [IPv4 address]: ../../std/net/struct.Ipv4Addr.html
50+
/// [`SocketAddr`]: ../../std/net/enum.SocketAddr.html
4051
#[derive(Copy)]
4152
#[stable(feature = "rust1", since = "1.0.0")]
4253
pub struct SocketAddrV4 { inner: c::sockaddr_in }
4354

4455
/// An IPv6 socket address.
56+
///
57+
/// IPv6 socket addresses consist of an [Ipv6 address], a 16-bit port number, as well
58+
/// as fields containing the traffic class, the flow label, and a scope identifier
59+
/// (see [IETF RFC 2553, Section 3.3] for more details).
60+
///
61+
/// See [`SocketAddr`] for a type encompassing both IPv4 and IPv6 socket addresses.
62+
///
63+
/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
64+
/// [IPv6 address]: ../../std/net/struct.Ipv6Addr.html
65+
/// [`SocketAddr`]: ../../std/net/enum.SocketAddr.html
4566
#[derive(Copy)]
4667
#[stable(feature = "rust1", since = "1.0.0")]
4768
pub struct SocketAddrV6 { inner: c::sockaddr_in6 }
4869

4970
impl SocketAddr {
50-
/// Creates a new socket address from the (ip, port) pair.
71+
/// Creates a new socket address from an [IP address] and a port number.
72+
///
73+
/// [IP address]: ../../std/net/enum.IpAddr.html
5174
///
5275
/// # Examples
5376
///
@@ -84,7 +107,7 @@ impl SocketAddr {
84107
}
85108
}
86109

87-
/// Change the IP address associated with this socket address.
110+
/// Changes the IP address associated with this socket address.
88111
///
89112
/// # Examples
90113
///
@@ -123,7 +146,7 @@ impl SocketAddr {
123146
}
124147
}
125148

126-
/// Change the port number associated with this socket address.
149+
/// Changes the port number associated with this socket address.
127150
///
128151
/// # Examples
129152
///
@@ -142,8 +165,14 @@ impl SocketAddr {
142165
}
143166
}
144167

145-
/// Returns true if the IP in this `SocketAddr` is a valid IPv4 address,
146-
/// false if it's a valid IPv6 address.
168+
/// Returns [`true`] if the [IP address] in this `SocketAddr` is an
169+
/// [IPv4 address] and [`false`] if it's an [IPv6 address].
170+
///
171+
/// [`true`]: ../../std/primitive.bool.html
172+
/// [`false`]: ../../std/primitive.bool.html
173+
/// [IP address]: ../../std/net/enum.IpAddr.html
174+
/// [IPv4 address]: ../../std/net/enum.IpAddr.html#variant.V4
175+
/// [IPv6 address]: ../../std/net/enum.IpAddr.html#variant.V6
147176
///
148177
/// # Examples
149178
///
@@ -164,8 +193,14 @@ impl SocketAddr {
164193
}
165194
}
166195

167-
/// Returns true if the IP in this `SocketAddr` is a valid IPv6 address,
168-
/// false if it's a valid IPv4 address.
196+
/// Returns [`true`] if the [IP address] in this `SocketAddr` is an
197+
/// [IPv6 address] and [`false`] if it's an [IPv4 address].
198+
///
199+
/// [`true`]: ../../std/primitive.bool.html
200+
/// [`false`]: ../../std/primitive.bool.html
201+
/// [IP address]: ../../std/net/enum.IpAddr.html
202+
/// [IPv4 address]: ../../std/net/enum.IpAddr.html#variant.V4
203+
/// [IPv6 address]: ../../std/net/enum.IpAddr.html#variant.V6
169204
///
170205
/// # Examples
171206
///
@@ -189,7 +224,9 @@ impl SocketAddr {
189224
}
190225

191226
impl SocketAddrV4 {
192-
/// Creates a new socket address from the (ip, port) pair.
227+
/// Creates a new socket address from an [IPv4 address] and a port number.
228+
///
229+
/// [IPv4 address]: ../../std/net/struct.Ipv4Addr.html
193230
///
194231
/// # Examples
195232
///
@@ -227,7 +264,7 @@ impl SocketAddrV4 {
227264
}
228265
}
229266

230-
/// Change the IP address associated with this socket address.
267+
/// Changes the IP address associated with this socket address.
231268
///
232269
/// # Examples
233270
///
@@ -258,7 +295,7 @@ impl SocketAddrV4 {
258295
ntoh(self.inner.sin_port)
259296
}
260297

261-
/// Change the port number associated with this socket address.
298+
/// Changes the port number associated with this socket address.
262299
///
263300
/// # Examples
264301
///
@@ -276,8 +313,14 @@ impl SocketAddrV4 {
276313
}
277314

278315
impl SocketAddrV6 {
279-
/// Creates a new socket address from the ip/port/flowinfo/scope_id
280-
/// components.
316+
/// Creates a new socket address from an [IPv6 address], a 16-bit port number,
317+
/// and the `flowinfo` and `scope_id` fields.
318+
///
319+
/// For more information on the meaning and layout of the `flowinfo` and `scope_id`
320+
/// parameters, see [IETF RFC 2553, Section 3.3].
321+
///
322+
/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
323+
/// [IPv6 address]: ../../std/net/struct.Ipv6Addr.html
281324
///
282325
/// # Examples
283326
///
@@ -318,7 +361,7 @@ impl SocketAddrV6 {
318361
}
319362
}
320363

321-
/// Change the IP address associated with this socket address.
364+
/// Changes the IP address associated with this socket address.
322365
///
323366
/// # Examples
324367
///
@@ -349,7 +392,7 @@ impl SocketAddrV6 {
349392
ntoh(self.inner.sin6_port)
350393
}
351394

352-
/// Change the port number associated with this socket address.
395+
/// Changes the port number associated with this socket address.
353396
///
354397
/// # Examples
355398
///
@@ -365,8 +408,17 @@ impl SocketAddrV6 {
365408
self.inner.sin6_port = hton(new_port);
366409
}
367410

368-
/// Returns the flow information associated with this address,
369-
/// corresponding to the `sin6_flowinfo` field in C.
411+
/// Returns the flow information associated with this address.
412+
///
413+
/// This information corresponds to the `sin6_flowinfo` field in C, as specified in
414+
/// [IETF RFC 2553, Section 3.3]. It combines information about the flow label and
415+
/// the traffic class as specified in [IETF RFC 2460], respectively [Section 6] and
416+
/// [Section 7].
417+
///
418+
/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
419+
/// [IETF RFC 2460]: https://tools.ietf.org/html/rfc2460
420+
/// [Section 6]: https://tools.ietf.org/html/rfc2460#section-6
421+
/// [Section 7]: https://tools.ietf.org/html/rfc2460#section-7
370422
///
371423
/// # Examples
372424
///
@@ -381,7 +433,11 @@ impl SocketAddrV6 {
381433
self.inner.sin6_flowinfo
382434
}
383435

384-
/// Change the flow information associated with this socket address.
436+
/// Changes the flow information associated with this socket address.
437+
///
438+
/// See the [`flowinfo`] method's documentation for more details.
439+
///
440+
/// [`flowinfo`]: #method.flowinfo
385441
///
386442
/// # Examples
387443
///
@@ -397,8 +453,12 @@ impl SocketAddrV6 {
397453
self.inner.sin6_flowinfo = new_flowinfo;
398454
}
399455

400-
/// Returns the scope ID associated with this address,
401-
/// corresponding to the `sin6_scope_id` field in C.
456+
/// Returns the scope ID associated with this address.
457+
///
458+
/// This information corresponds to the `sin6_scope_id` field in C, as specified in
459+
/// [IETF RFC 2553, Section 3.3].
460+
///
461+
/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
402462
///
403463
/// # Examples
404464
///
@@ -415,6 +475,10 @@ impl SocketAddrV6 {
415475

416476
/// Change the scope ID associated with this socket address.
417477
///
478+
/// See the [`scope_id`] method's documentation for more details.
479+
///
480+
/// [`scope_id`]: #method.scope_id
481+
///
418482
/// # Examples
419483
///
420484
/// ```

src/libstd/net/ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use net::{hton, ntoh};
2121
use sys::net::netc as c;
2222
use sys_common::{AsInner, FromInner};
2323

24-
/// Either an IPv4 address or an IPv6 address.
24+
/// An IP address, either IPv4 or IPv6.
2525
///
2626
/// This enum can contain either an [`Ipv4Addr`] or an [`Ipv6Addr`], see their
2727
/// respective documentation for more details.

0 commit comments

Comments
 (0)