File tree 1 file changed +10
-0
lines changed
library/std/src/os/unix/net
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,16 @@ impl SocketAddr {
107
107
addr : libc:: sockaddr_un ,
108
108
mut len : libc:: socklen_t ,
109
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
+
110
120
if len == 0 {
111
121
// When there is a datagram from unnamed unix socket
112
122
// linux returns zero bytes of address
You can’t perform that action at this time.
0 commit comments