diff options
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/socket/addr.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index c6988227..e6c5f8ae 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -551,7 +551,7 @@ impl UnixAddr { ret.sun_path.as_mut_ptr().offset(1) as *mut u8, path.len()); - Ok(UnixAddr(ret, path.len() + 1)) + Ok(UnixAddr(ret, ret.sun_path.len())) } } @@ -1126,9 +1126,11 @@ mod datalink { #[cfg(test)] mod tests { - #[cfg(any(target_os = "dragonfly", + #[cfg(any(target_os = "android", + target_os = "dragonfly", target_os = "freebsd", target_os = "ios", + target_os = "linux", target_os = "macos", target_os = "netbsd", target_os = "openbsd"))] @@ -1174,4 +1176,18 @@ mod tests { _ => { unreachable!() } }; } + + #[cfg(any(target_os = "android", target_os = "linux"))] + #[test] + fn test_abstract_sun_path() { + let name = String::from("nix\0abstract\0test"); + let addr = UnixAddr::new_abstract(name.as_bytes()).unwrap(); + + let sun_path1 = addr.sun_path(); + let sun_path2 = [0u8, 110, 105, 120, 0, 97, 98, 115, 116, 114, 97, 99, 116, 0, 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + assert_eq!(sun_path1.len(), sun_path2.len()); + for i in 0..sun_path1.len() { + assert_eq!(sun_path1[i], sun_path2[i]); + } + } } |