@@ -137,6 +137,8 @@ sockopt_impl!(Both, Broadcast, consts::SOL_SOCKET, consts::SO_BROADCAST, bool);
137
137
sockopt_impl ! ( Both , OobInline , consts:: SOL_SOCKET , consts:: SO_OOBINLINE , bool ) ;
138
138
sockopt_impl ! ( GetOnly , SocketError , consts:: SOL_SOCKET , consts:: SO_ERROR , i32 ) ;
139
139
sockopt_impl ! ( Both , KeepAlive , consts:: SOL_SOCKET , consts:: SO_KEEPALIVE , bool ) ;
140
+ #[ cfg( target_os = "linux" ) ]
141
+ sockopt_impl ! ( GetOnly , PeerCredentials , consts:: SOL_SOCKET , consts:: SO_PEERCRED , super :: ucred) ;
140
142
#[ cfg( any( target_os = "macos" ,
141
143
target_os = "ios" ) ) ]
142
144
sockopt_impl ! ( Both , TcpKeepAlive , consts:: IPPROTO_TCP , consts:: TCP_KEEPALIVE , u32 ) ;
@@ -300,3 +302,19 @@ impl<'a> Set<'a, u8> for SetU8 {
300
302
mem:: size_of :: < c_int > ( ) as socklen_t
301
303
}
302
304
}
305
+
306
+
307
+ #[ cfg( test) ]
308
+ mod test {
309
+ #[ cfg( target_os = "linux" ) ]
310
+ #[ test]
311
+ fn can_get_peercred_on_unix_socket ( ) {
312
+ use super :: super :: * ;
313
+
314
+ let ( a, b) = socketpair ( AddressFamily :: Unix , SockType :: Stream , 0 , SockFlag :: empty ( ) ) . unwrap ( ) ;
315
+ let a_cred = getsockopt ( a, super :: PeerCredentials ) . unwrap ( ) ;
316
+ let b_cred = getsockopt ( b, super :: PeerCredentials ) . unwrap ( ) ;
317
+ assert_eq ! ( a_cred, b_cred) ;
318
+ assert ! ( a_cred. pid != 0 ) ;
319
+ }
320
+ }
0 commit comments