We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4b61234 commit 3e38e05Copy full SHA for 3e38e05
std/src/os/unix/net/addr.rs
@@ -107,6 +107,16 @@ impl SocketAddr {
107
addr: libc::sockaddr_un,
108
mut len: libc::socklen_t,
109
) -> io::Result<SocketAddr> {
110
+ if cfg!(target_os = "openbsd") {
111
+ // on OpenBSD, getsockname(2) returns the actual size of the socket address,
112
+ // and not the len of the content. Figure out the length for ourselves.
113
+ // https://marc.info/?l=openbsd-bugs&m=170105481926736&w=2
114
+ let sun_path: &[u8] =
115
+ unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&addr.sun_path) };
116
+ len = core::slice::memchr::memchr(0, sun_path)
117
+ .map_or(len, |new_len| (new_len + sun_path_offset(&addr)) as libc::socklen_t);
118
+ }
119
+
120
if len == 0 {
121
// When there is a datagram from unnamed unix socket
122
// linux returns zero bytes of address
0 commit comments