Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix byte-swapped flowinfo and scope_id #1969

Closed

Conversation

jgallagher
Copy link
Contributor

The From<SockaddrIn6> for net::SocketAddrV6 implementation used from_be() on each of the port/flowinfo/scope_id fields, but the flowinfo and scope_id are not stored in big endian, causing the conversion to produce a SocketAddrV6 with byte-swapped flowinfo and scope_id. I noticed this when running getifaddrs() on my machine and then converting to a standard SocketAddrV6 created an address with a scope ID of 33554432 (hex 0x02000000) for an interface that should have been scope id 2.

I added a basic test to round-trip between a standard SocketAddrV6 and a SockaddrIn6; prior to the change to the From impl, this test failed with

thread 'sys::socket::addr::tests::sockaddr_in6::roundtrip_std_socketaddrv6' panicked at 'assertion failed: `(left == right)`
  left: `[1234:5678:90ab:cdef::1111:2222%67305985]:258`,
 right: `[1234:5678:90ab:cdef::1111:2222%16909060]:258`

where 67305985 == 0x4030201 is the byte-swapped value of 16909060 == 0x1020304, the expected value.

@asomers
Copy link
Member

asomers commented Jan 13, 2023

Duplicate of #1964

@asomers asomers marked this as a duplicate of #1964 Jan 13, 2023
@asomers asomers closed this Jan 13, 2023
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.

None yet

2 participants