Skip to content

Conversation

@cspiegel
Copy link
Contributor

As an example, the IPv6 address fe80::1 is represented in memory (in a
sin6_addr.s6_addr) as:

[0xfe, 0x80, 0x00, ..., 0x01]

So to construct an IPv6 address from 16-bit values, as is required by
net::Ipv6Addr::new, these should be passed as 0xfe80, 0x0000, etc.
However, the make_int16() function here was building them as 0x80fe,
etc. (or rather, it was being called in such a way to construct such
swapped integers). Because this function is used only to build IPv6
addresses, simply swapping the order of its parameters is sufficient to
properly construct IPv6 addresses.

As an example, the IPv6 address fe80::1 is represented in memory (in a
sin6_addr.s6_addr) as:

[0xfe, 0x80, 0x00, ..., 0x01]

So to construct an IPv6 address from 16-bit values, as is required by
net::Ipv6Addr::new, these should be passed as 0xfe80, 0x0000, etc.
However, the make_int16() function here was building them as 0x80fe,
etc. (or rather, it was being *called* in such a way to construct such
swapped integers). Because this function is used only to build IPv6
addresses, simply swapping the order of its parameters is sufficient to
properly construct IPv6 addresses.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.4%) to 86.957% when pulling 7fd0cf0 on cspiegel:build-ipv6 into 3c41bc4 on andrew-d:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.4%) to 86.957% when pulling 7fd0cf0 on cspiegel:build-ipv6 into 3c41bc4 on andrew-d:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.4%) to 86.957% when pulling 7fd0cf0 on cspiegel:build-ipv6 into 3c41bc4 on andrew-d:master.

@andrew-d
Copy link
Owner

Huh, good catch - and thanks for the PR! Would you mind writing a test for this? Something like:

assert_eq!(make_int16(0xff, 0x00), 0xff00)

@cspiegel
Copy link
Contributor Author

OK, I've updated the branch with the requested test.

@andrew-d
Copy link
Owner

Awesome - thanks! 😀

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 86.842% when pulling 085d95a on cspiegel:build-ipv6 into 3c41bc4 on andrew-d:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 86.842% when pulling 085d95a on cspiegel:build-ipv6 into 3c41bc4 on andrew-d:master.

@andrew-d andrew-d merged commit abfe8b6 into andrew-d:master Feb 19, 2017
@cspiegel cspiegel deleted the build-ipv6 branch February 19, 2017 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants