Skip to content

Commit c5d6732

Browse files
bors[bot]aarond10
andauthored
Merge #1964
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 <aarond10@gmail.com>
2 parents ef70d9e + cfe689a commit c5d6732

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2525
([#1921](https://github.com/nix-rust/nix/pull/1921))
2626

2727
### Fixed
28+
- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering.
29+
([#1964](https://github.com/nix-rust/nix/pull/1964))
30+
2831
### Removed
2932

3033
- Removed deprecated IoVec API.

src/sys/socket/addr.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,8 @@ impl From<SockaddrIn6> for net::SocketAddrV6 {
11821182
net::SocketAddrV6::new(
11831183
net::Ipv6Addr::from(addr.0.sin6_addr.s6_addr),
11841184
u16::from_be(addr.0.sin6_port),
1185-
u32::from_be(addr.0.sin6_flowinfo),
1186-
u32::from_be(addr.0.sin6_scope_id),
1185+
addr.0.sin6_flowinfo,
1186+
addr.0.sin6_scope_id,
11871187
)
11881188
}
11891189
}
@@ -2525,6 +2525,18 @@ mod tests {
25252525
SockaddrIn6::size() as usize
25262526
);
25272527
}
2528+
2529+
#[test]
2530+
// Ensure that we can convert to-and-from std::net variants without change.
2531+
fn to_and_from() {
2532+
let s = "[1234:5678:90ab:cdef::1111:2222]:8080";
2533+
let mut nix_sin6 = SockaddrIn6::from_str(s).unwrap();
2534+
nix_sin6.0.sin6_flowinfo = 0x12345678;
2535+
nix_sin6.0.sin6_scope_id = 0x9abcdef0;
2536+
2537+
let std_sin6 : std::net::SocketAddrV6 = nix_sin6.into();
2538+
assert_eq!(nix_sin6, std_sin6.into());
2539+
}
25282540
}
25292541

25302542
mod sockaddr_storage {

0 commit comments

Comments
 (0)