Skip to content

Commit 6fd7418

Browse files
aarond10asomers
authored andcommitted
Fix endian swap on SocketAddrV6.
flowinfo and scope_id should not be byte swapped.
1 parent e7a646d commit 6fd7418

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/).
55

6+
## [Unreleased] - ReleaseDate
7+
### Added
8+
### Changed
9+
### Fixed
10+
- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering.
11+
([#1964](https://github.com/nix-rust/nix/pull/1964))
12+
13+
### Removed
14+
615
## [0.26.1] - 2022-11-29
716
### Added
817
### Changed

src/sys/socket/addr.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,8 @@ impl From<SockaddrIn6> for net::SocketAddrV6 {
14761476
net::SocketAddrV6::new(
14771477
net::Ipv6Addr::from(addr.0.sin6_addr.s6_addr),
14781478
u16::from_be(addr.0.sin6_port),
1479-
u32::from_be(addr.0.sin6_flowinfo),
1480-
u32::from_be(addr.0.sin6_scope_id),
1479+
addr.0.sin6_flowinfo,
1480+
addr.0.sin6_scope_id,
14811481
)
14821482
}
14831483
}
@@ -3167,6 +3167,18 @@ mod tests {
31673167
SockaddrIn6::size() as usize
31683168
);
31693169
}
3170+
3171+
#[test]
3172+
// Ensure that we can convert to-and-from std::net variants without change.
3173+
fn to_and_from() {
3174+
let s = "[1234:5678:90ab:cdef::1111:2222]:8080";
3175+
let mut nix_sin6 = SockaddrIn6::from_str(s).unwrap();
3176+
nix_sin6.0.sin6_flowinfo = 0x12345678;
3177+
nix_sin6.0.sin6_scope_id = 0x9abcdef0;
3178+
3179+
let std_sin6 : std::net::SocketAddrV6 = nix_sin6.into();
3180+
assert_eq!(nix_sin6, std_sin6.into());
3181+
}
31703182
}
31713183

31723184
mod sockaddr_storage {

0 commit comments

Comments
 (0)