Skip to content

Commit

Permalink
Merge #1964
Browse files Browse the repository at this point in the history
1964: Fix endian swap on SocketAddrV6. r=asomers a=aarond10

This is a bug. flowinfo and scope_id should not be byte swapped here.

See also #1963.

Co-authored-by: Aaron Drew <[email protected]>
  • Loading branch information
bors[bot] and aarond10 authored Jan 13, 2023
2 parents ef70d9e + cfe689a commit c5d6732
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
([#1921](https://github.com/nix-rust/nix/pull/1921))

### Fixed
- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering.
([#1964](https://github.com/nix-rust/nix/pull/1964))

### Removed

- Removed deprecated IoVec API.
Expand Down
16 changes: 14 additions & 2 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,8 @@ impl From<SockaddrIn6> for net::SocketAddrV6 {
net::SocketAddrV6::new(
net::Ipv6Addr::from(addr.0.sin6_addr.s6_addr),
u16::from_be(addr.0.sin6_port),
u32::from_be(addr.0.sin6_flowinfo),
u32::from_be(addr.0.sin6_scope_id),
addr.0.sin6_flowinfo,
addr.0.sin6_scope_id,
)
}
}
Expand Down Expand Up @@ -2525,6 +2525,18 @@ mod tests {
SockaddrIn6::size() as usize
);
}

#[test]
// Ensure that we can convert to-and-from std::net variants without change.
fn to_and_from() {
let s = "[1234:5678:90ab:cdef::1111:2222]:8080";
let mut nix_sin6 = SockaddrIn6::from_str(s).unwrap();
nix_sin6.0.sin6_flowinfo = 0x12345678;
nix_sin6.0.sin6_scope_id = 0x9abcdef0;

let std_sin6 : std::net::SocketAddrV6 = nix_sin6.into();
assert_eq!(nix_sin6, std_sin6.into());
}
}

mod sockaddr_storage {
Expand Down

0 comments on commit c5d6732

Please sign in to comment.