File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
library/std/src/os/unix/net Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,16 @@ impl SocketAddr {
107107 addr : libc:: sockaddr_un ,
108108 mut len : libc:: socklen_t ,
109109 ) -> 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 { crate :: mem:: transmute :: < & [ libc:: c_char ] , & [ u8 ] > ( & addr. sun_path ) } ;
116+ len = crate :: sys:: memchr:: memchr ( 0 , sun_path)
117+ . map_or ( len, |new_len| ( new_len + sun_path_offset ( & addr) ) as libc:: socklen_t ) ;
118+ }
119+
110120 if len == 0 {
111121 // When there is a datagram from unnamed unix socket
112122 // linux returns zero bytes of address
You can’t perform that action at this time.
0 commit comments