@@ -20,34 +20,57 @@ use vec;
20
20
use iter;
21
21
use slice;
22
22
23
- /// Representation of a socket address for networking applications .
23
+ /// An internet socket address, either IPv4 or IPv6 .
24
24
///
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
28
30
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
29
31
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
30
32
pub enum SocketAddr {
31
- /// An IPv4 socket address which is a (ip, port) combination .
33
+ /// An IPv4 socket address.
32
34
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
33
35
V4 ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] SocketAddrV4 ) ,
34
36
/// An IPv6 socket address.
35
37
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
36
38
V6 ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] SocketAddrV6 ) ,
37
39
}
38
40
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
40
51
#[ derive( Copy ) ]
41
52
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
42
53
pub struct SocketAddrV4 { inner : c:: sockaddr_in }
43
54
44
55
/// 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
45
66
#[ derive( Copy ) ]
46
67
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
47
68
pub struct SocketAddrV6 { inner : c:: sockaddr_in6 }
48
69
49
70
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
51
74
///
52
75
/// # Examples
53
76
///
@@ -84,7 +107,7 @@ impl SocketAddr {
84
107
}
85
108
}
86
109
87
- /// Change the IP address associated with this socket address.
110
+ /// Changes the IP address associated with this socket address.
88
111
///
89
112
/// # Examples
90
113
///
@@ -123,7 +146,7 @@ impl SocketAddr {
123
146
}
124
147
}
125
148
126
- /// Change the port number associated with this socket address.
149
+ /// Changes the port number associated with this socket address.
127
150
///
128
151
/// # Examples
129
152
///
@@ -142,8 +165,14 @@ impl SocketAddr {
142
165
}
143
166
}
144
167
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
147
176
///
148
177
/// # Examples
149
178
///
@@ -164,8 +193,14 @@ impl SocketAddr {
164
193
}
165
194
}
166
195
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
169
204
///
170
205
/// # Examples
171
206
///
@@ -189,7 +224,9 @@ impl SocketAddr {
189
224
}
190
225
191
226
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
193
230
///
194
231
/// # Examples
195
232
///
@@ -227,7 +264,7 @@ impl SocketAddrV4 {
227
264
}
228
265
}
229
266
230
- /// Change the IP address associated with this socket address.
267
+ /// Changes the IP address associated with this socket address.
231
268
///
232
269
/// # Examples
233
270
///
@@ -258,7 +295,7 @@ impl SocketAddrV4 {
258
295
ntoh ( self . inner . sin_port )
259
296
}
260
297
261
- /// Change the port number associated with this socket address.
298
+ /// Changes the port number associated with this socket address.
262
299
///
263
300
/// # Examples
264
301
///
@@ -276,8 +313,14 @@ impl SocketAddrV4 {
276
313
}
277
314
278
315
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
281
324
///
282
325
/// # Examples
283
326
///
@@ -318,7 +361,7 @@ impl SocketAddrV6 {
318
361
}
319
362
}
320
363
321
- /// Change the IP address associated with this socket address.
364
+ /// Changes the IP address associated with this socket address.
322
365
///
323
366
/// # Examples
324
367
///
@@ -349,7 +392,7 @@ impl SocketAddrV6 {
349
392
ntoh ( self . inner . sin6_port )
350
393
}
351
394
352
- /// Change the port number associated with this socket address.
395
+ /// Changes the port number associated with this socket address.
353
396
///
354
397
/// # Examples
355
398
///
@@ -365,8 +408,17 @@ impl SocketAddrV6 {
365
408
self . inner . sin6_port = hton ( new_port) ;
366
409
}
367
410
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
370
422
///
371
423
/// # Examples
372
424
///
@@ -381,7 +433,11 @@ impl SocketAddrV6 {
381
433
self . inner . sin6_flowinfo
382
434
}
383
435
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
385
441
///
386
442
/// # Examples
387
443
///
@@ -397,8 +453,12 @@ impl SocketAddrV6 {
397
453
self . inner . sin6_flowinfo = new_flowinfo;
398
454
}
399
455
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
402
462
///
403
463
/// # Examples
404
464
///
@@ -415,6 +475,10 @@ impl SocketAddrV6 {
415
475
416
476
/// Change the scope ID associated with this socket address.
417
477
///
478
+ /// See the [`scope_id`] method's documentation for more details.
479
+ ///
480
+ /// [`scope_id`]: #method.scope_id
481
+ ///
418
482
/// # Examples
419
483
///
420
484
/// ```
0 commit comments