Skip to content

Commit 1c67167

Browse files
committed
test: fix solarish_tap test on big-endian Solaris (#2743)
* patch to correct solarish_tap test for big-endian * changelog
1 parent dad24fb commit 1c67167

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

changelog/2743.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed solarish_tap test on big-endian targets.

src/sys/socket/addr.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,22 +2290,37 @@ mod tests {
22902290
#[cfg(solarish)]
22912291
#[test]
22922292
fn solarish_tap() {
2293-
let bytes = [25u8, 0, 0, 0, 6, 0, 6, 0, 24, 101, 144, 221, 76, 176];
2294-
let ptr = bytes.as_ptr();
2295-
let sa = ptr as *const libc::sockaddr;
2293+
let mut bytes = [0u8, 0, 0, 0, 6, 0, 6, 0, 24, 101, 144, 221, 76, 176];
2294+
// First two elements in array correspond to single 2-byte integer
2295+
// representing sa_family
2296+
let family: u16 = 25;
2297+
// Copy to the array based on the native endianness of the machine
2298+
bytes[0..2].copy_from_slice(&family.to_ne_bytes());
2299+
2300+
// Only 1-byte alignment guaranteed by u8 array. Put into buffer that
2301+
// guarantees sufficient alignment per POSIX, to take pointer.
2302+
let mut ss = mem::MaybeUninit::<libc::sockaddr_storage>::zeroed();
2303+
unsafe {
2304+
ptr::copy_nonoverlapping(
2305+
bytes.as_ptr(),
2306+
ss.as_mut_ptr() as *mut u8,
2307+
bytes.len(),
2308+
);
2309+
}
2310+
let ss = unsafe { ss.assume_init() };
2311+
2312+
let sa = &ss as *const _ as *const libc::sockaddr;
22962313
let len = Some(bytes.len() as socklen_t);
22972314
let _sock_addr = unsafe { SockaddrStorage::from_raw(sa, len) };
22982315

22992316
assert!(_sock_addr.is_some());
2300-
23012317
let sock_addr = _sock_addr.unwrap();
2302-
23032318
assert_eq!(sock_addr.family().unwrap(), AddressFamily::Link);
2304-
23052319
assert_eq!(
23062320
sock_addr.as_link_addr().unwrap().addr(),
23072321
Some([24u8, 101, 144, 221, 76, 176])
23082322
);
2323+
23092324
}
23102325

23112326
#[test]

0 commit comments

Comments
 (0)