@@ -30,7 +30,7 @@ const TCP_CA_NAME_MAX: usize = 16;
3030/// # Arguments
3131///
3232/// * `$name:ident`: name of the type you want to implement `SetSockOpt` for.
33- /// * `$level:path ` : socket layer, or a `protocol level`: could be *raw sockets*
33+ /// * `$level:expr ` : socket layer, or a `protocol level`: could be *raw sockets*
3434/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
3535/// and more. Please refer to your system manual for more options. Will be passed as the second
3636/// argument (`level`) to the `setsockopt` call.
@@ -41,7 +41,7 @@ const TCP_CA_NAME_MAX: usize = 16;
4141/// * Type that implements the `Set` trait for the type from the previous item (like `SetBool` for
4242/// `bool`, `SetUsize` for `usize`, etc.).
4343macro_rules! setsockopt_impl {
44- ( $name: ident, $level: path , $flag: path, $ty: ty, $setter: ty) => {
44+ ( $name: ident, $level: expr , $flag: path, $ty: ty, $setter: ty) => {
4545 impl SetSockOpt for $name {
4646 type Val = $ty;
4747
@@ -82,7 +82,7 @@ macro_rules! setsockopt_impl {
8282/// * Type that implements the `Get` trait for the type from the previous item (`GetBool` for
8383/// `bool`, `GetUsize` for `usize`, etc.).
8484macro_rules! getsockopt_impl {
85- ( $name: ident, $level: path , $flag: path, $ty: ty, $getter: ty) => {
85+ ( $name: ident, $level: expr , $flag: path, $ty: ty, $getter: ty) => {
8686 impl GetSockOpt for $name {
8787 type Val = $ty;
8888
@@ -117,7 +117,7 @@ macro_rules! getsockopt_impl {
117117/// * `GetOnly`, `SetOnly` or `Both`: whether you want to implement only getter, only setter or
118118/// both of them.
119119/// * `$name:ident`: name of type `GetSockOpt`/`SetSockOpt` will be implemented for.
120- /// * `$level:path ` : socket layer, or a `protocol level`: could be *raw sockets*
120+ /// * `$level:expr ` : socket layer, or a `protocol level`: could be *raw sockets*
121121/// (`lic::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
122122/// and more. Please refer to your system manual for more options. Will be passed as the second
123123/// argument (`level`) to the `getsockopt`/`setsockopt` call.
@@ -128,81 +128,81 @@ macro_rules! getsockopt_impl {
128128/// * `$getter:ty`: `Get` implementation; optional; only for `GetOnly` and `Both`.
129129/// * `$setter:ty`: `Set` implementation; optional; only for `SetOnly` and `Both`.
130130macro_rules! sockopt_impl {
131- ( GetOnly , $name: ident, $level: path , $flag: path, bool ) => {
131+ ( GetOnly , $name: ident, $level: expr , $flag: path, bool ) => {
132132 sockopt_impl!( GetOnly , $name, $level, $flag, bool , GetBool ) ;
133133 } ;
134134
135- ( GetOnly , $name: ident, $level: path , $flag: path, u8 ) => {
135+ ( GetOnly , $name: ident, $level: expr , $flag: path, u8 ) => {
136136 sockopt_impl!( GetOnly , $name, $level, $flag, u8 , GetU8 ) ;
137137 } ;
138138
139- ( GetOnly , $name: ident, $level: path , $flag: path, usize ) => {
139+ ( GetOnly , $name: ident, $level: expr , $flag: path, usize ) => {
140140 sockopt_impl!( GetOnly , $name, $level, $flag, usize , GetUsize ) ;
141141 } ;
142142
143- ( SetOnly , $name: ident, $level: path , $flag: path, bool ) => {
143+ ( SetOnly , $name: ident, $level: expr , $flag: path, bool ) => {
144144 sockopt_impl!( SetOnly , $name, $level, $flag, bool , SetBool ) ;
145145 } ;
146146
147- ( SetOnly , $name: ident, $level: path , $flag: path, u8 ) => {
147+ ( SetOnly , $name: ident, $level: expr , $flag: path, u8 ) => {
148148 sockopt_impl!( SetOnly , $name, $level, $flag, u8 , SetU8 ) ;
149149 } ;
150150
151- ( SetOnly , $name: ident, $level: path , $flag: path, usize ) => {
151+ ( SetOnly , $name: ident, $level: expr , $flag: path, usize ) => {
152152 sockopt_impl!( SetOnly , $name, $level, $flag, usize , SetUsize ) ;
153153 } ;
154154
155- ( Both , $name: ident, $level: path , $flag: path, bool ) => {
155+ ( Both , $name: ident, $level: expr , $flag: path, bool ) => {
156156 sockopt_impl!( Both , $name, $level, $flag, bool , GetBool , SetBool ) ;
157157 } ;
158158
159- ( Both , $name: ident, $level: path , $flag: path, u8 ) => {
159+ ( Both , $name: ident, $level: expr , $flag: path, u8 ) => {
160160 sockopt_impl!( Both , $name, $level, $flag, u8 , GetU8 , SetU8 ) ;
161161 } ;
162162
163- ( Both , $name: ident, $level: path , $flag: path, usize ) => {
163+ ( Both , $name: ident, $level: expr , $flag: path, usize ) => {
164164 sockopt_impl!( Both , $name, $level, $flag, usize , GetUsize , SetUsize ) ;
165165 } ;
166166
167- ( Both , $name: ident, $level: path , $flag: path, OsString <$array: ty>) => {
167+ ( Both , $name: ident, $level: expr , $flag: path, OsString <$array: ty>) => {
168168 sockopt_impl!( Both , $name, $level, $flag, OsString , GetOsString <$array>, SetOsString ) ;
169169 } ;
170170
171171 /*
172172 * Matchers with generic getter types must be placed at the end, so
173173 * they'll only match _after_ specialized matchers fail
174174 */
175- ( GetOnly , $name: ident, $level: path , $flag: path, $ty: ty) => {
175+ ( GetOnly , $name: ident, $level: expr , $flag: path, $ty: ty) => {
176176 sockopt_impl!( GetOnly , $name, $level, $flag, $ty, GetStruct <$ty>) ;
177177 } ;
178178
179- ( GetOnly , $name: ident, $level: path , $flag: path, $ty: ty, $getter: ty) => {
179+ ( GetOnly , $name: ident, $level: expr , $flag: path, $ty: ty, $getter: ty) => {
180180 #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
181181 pub struct $name;
182182
183183 getsockopt_impl!( $name, $level, $flag, $ty, $getter) ;
184184 } ;
185185
186- ( SetOnly , $name: ident, $level: path , $flag: path, $ty: ty) => {
186+ ( SetOnly , $name: ident, $level: expr , $flag: path, $ty: ty) => {
187187 sockopt_impl!( SetOnly , $name, $level, $flag, $ty, SetStruct <$ty>) ;
188188 } ;
189189
190- ( SetOnly , $name: ident, $level: path , $flag: path, $ty: ty, $setter: ty) => {
190+ ( SetOnly , $name: ident, $level: expr , $flag: path, $ty: ty, $setter: ty) => {
191191 #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
192192 pub struct $name;
193193
194194 setsockopt_impl!( $name, $level, $flag, $ty, $setter) ;
195195 } ;
196196
197- ( Both , $name: ident, $level: path , $flag: path, $ty: ty, $getter: ty, $setter: ty) => {
197+ ( Both , $name: ident, $level: expr , $flag: path, $ty: ty, $getter: ty, $setter: ty) => {
198198 #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
199199 pub struct $name;
200200
201201 setsockopt_impl!( $name, $level, $flag, $ty, $setter) ;
202202 getsockopt_impl!( $name, $level, $flag, $ty, $getter) ;
203203 } ;
204204
205- ( Both , $name: ident, $level: path , $flag: path, $ty: ty) => {
205+ ( Both , $name: ident, $level: expr , $flag: path, $ty: ty) => {
206206 sockopt_impl!( Both , $name, $level, $flag, $ty, GetStruct <$ty>, SetStruct <$ty>) ;
207207 } ;
208208}
@@ -246,6 +246,14 @@ sockopt_impl!(Both, Broadcast, libc::SOL_SOCKET, libc::SO_BROADCAST, bool);
246246sockopt_impl ! ( Both , OobInline , libc:: SOL_SOCKET , libc:: SO_OOBINLINE , bool ) ;
247247sockopt_impl ! ( GetOnly , SocketError , libc:: SOL_SOCKET , libc:: SO_ERROR , i32 ) ;
248248sockopt_impl ! ( Both , KeepAlive , libc:: SOL_SOCKET , libc:: SO_KEEPALIVE , bool ) ;
249+ #[ cfg( any(
250+ target_os = "dragonfly" ,
251+ target_os = "freebsd" ,
252+ target_os = "macos" ,
253+ target_os = "ios"
254+ ) ) ]
255+ // Get the credentials of the peer process of a connected unix domain socket.
256+ sockopt_impl ! ( GetOnly , LocalPeerCred , 0 , libc:: LOCAL_PEERCRED , super :: XuCred ) ;
249257#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
250258sockopt_impl ! ( GetOnly , PeerCredentials , libc:: SOL_SOCKET , libc:: SO_PEERCRED , super :: UnixCredentials ) ;
251259#[ cfg( any( target_os = "ios" ,
0 commit comments