Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd octet-oriented interface to std::net::Ipv6Addr #1498
Conversation
This comment has been minimized.
This comment has been minimized.
|
I’d call the methods As far as I understand, in English, the word octet is used to be explicit about having 8 bits in contexts where a byte may have a different length. In the Rust standard library however, there is widespread precedent of the word "bytes" being used to designate Other than this naming bikeshed, +1 on the feature. |
This comment has been minimized.
This comment has been minimized.
|
I agree with @SimonSapin. It's pretty annoying to work with IPv6 addresses right now in comparison to IPv4 ones: https://github.com/sfackler/rust-socks/blob/master/src/v5.rs#L12-L29 |
sfackler
self-assigned this
Feb 15, 2016
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin I see your point about "bytes," but note that |
This comment has been minimized.
This comment has been minimized.
|
Ah, ok. Given |
nrc
added
the
T-libs
label
Feb 18, 2016
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
added
the
final-comment-period
label
Mar 3, 2016
This comment has been minimized.
This comment has been minimized.
|
I personally like the motivation for this RFC and I think we should definitely have these methods. Some nitpicks about the API I might have are:
|
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton on the contrary, for use cases that involve getting IP addresses out of a network protocol, it's very reasonable to get a let mut buf = [0; 16];
try!(reader.read_all(&mut buf));
let ip = Ipv6Addr::from_octets(&buf);vs let ip = Ipv6Addr::from_octets(try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8()),
try!(reader.read_u8())); |
This comment has been minimized.
This comment has been minimized.
|
Agreed with @sfackler - I have not had trouble getting a |
This comment has been minimized.
This comment has been minimized.
|
Hm ok, if you end up having |
This comment has been minimized.
This comment has been minimized.
|
That'd work as well. I currently use the |
This comment has been minimized.
This comment has been minimized.
|
I suppose while we're at it we could also add |
This comment has been minimized.
This comment has been minimized.
|
It's a bit easier to get at a |
This comment has been minimized.
This comment has been minimized.
|
I think vital information is missing: What byte-order should get exposed: The host byte order (little endian most of the time) or network byte order (big endian)? (If that's already in the RFC, then I can't find it and it should probably be made more visible.) |
This comment has been minimized.
This comment has been minimized.
I'm afraid I don't understand your question - the interface exposes an array of 16 single bytes, so there isn't any question of byte order. If the interface exposed an array of 8 16-bit integers, or a single 128-bit integer (if Rust had such a type), then the byte order of those integers would need to be specified, but that's not the case here. |
This comment has been minimized.
This comment has been minimized.
|
It should be the same order as |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton @sfackler I like your suggestions of adding an I think I'll also change |
This comment has been minimized.
This comment has been minimized.
|
@AGWA yeah it's fine to just push an update to the RFC. |
This comment has been minimized.
This comment has been minimized.
|
@AGWA It's interesting in which order the bytes are, for an address starting with |
This comment has been minimized.
This comment has been minimized.
|
For an address starting with Starting with |
This comment has been minimized.
This comment has been minimized.
|
Sorry if it is clear in what order the bytes are, however it's not that clear to me. For me, an IPv6 address is composed of eight unsigned 16-bit integers. Now my question was whether these 16-bit integers are themselves in big-endian (as they're sent over the network) or little-endian order (how most hosts represent 16-bit integers). |
This comment has been minimized.
This comment has been minimized.
https://tools.ietf.org/html/rfc2460 only talks about IPv6 addresses being made of 128 bits. The grouping by 16 bits only exists for the purpose of hex serialization. |
This comment has been minimized.
This comment has been minimized.
|
Thank you, that clears it up! |
AGWA
added some commits
Mar 10, 2016
This comment has been minimized.
This comment has been minimized.
|
I just pushed an update to the RFC that reflects the feedback so far. |
This comment has been minimized.
This comment has been minimized.
|
Looks good to me, thanks @AGWA! |
alexcrichton
referenced this pull request
Mar 17, 2016
Closed
Tracking issue for Ipv6Addr octet methods #32313
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this RFC during triage yesterday and the conclusion was to merge. It was brought up that it's relatively odd to consume fixed-size arrays in the standard library, but as pointed out by @sfackler this is tenable even today in some situations. It was also brought up that we would likely inevitably want this functionality regardless as it's just an extra implementation of Tracking issue: rust-lang/rust#32313 |
This comment has been minimized.
This comment has been minimized.
|
Ah and of course, thanks again for the RFC @AGWA! |
AGWA commentedFeb 13, 2016
Summary: Add constructor and getter functions to
std::net::Ipv6Addrthat are oriented around octets.Rendered