@@ -30,7 +30,7 @@ const TCP_CA_NAME_MAX: usize = 16;
30
30
/// # Arguments
31
31
///
32
32
/// * `$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*
34
34
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
35
35
/// and more. Please refer to your system manual for more options. Will be passed as the second
36
36
/// argument (`level`) to the `setsockopt` call.
@@ -41,7 +41,7 @@ const TCP_CA_NAME_MAX: usize = 16;
41
41
/// * Type that implements the `Set` trait for the type from the previous item (like `SetBool` for
42
42
/// `bool`, `SetUsize` for `usize`, etc.).
43
43
macro_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) => {
45
45
impl SetSockOpt for $name {
46
46
type Val = $ty;
47
47
@@ -82,7 +82,7 @@ macro_rules! setsockopt_impl {
82
82
/// * Type that implements the `Get` trait for the type from the previous item (`GetBool` for
83
83
/// `bool`, `GetUsize` for `usize`, etc.).
84
84
macro_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) => {
86
86
impl GetSockOpt for $name {
87
87
type Val = $ty;
88
88
@@ -117,7 +117,7 @@ macro_rules! getsockopt_impl {
117
117
/// * `GetOnly`, `SetOnly` or `Both`: whether you want to implement only getter, only setter or
118
118
/// both of them.
119
119
/// * `$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*
121
121
/// (`lic::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
122
122
/// and more. Please refer to your system manual for more options. Will be passed as the second
123
123
/// argument (`level`) to the `getsockopt`/`setsockopt` call.
@@ -128,81 +128,81 @@ macro_rules! getsockopt_impl {
128
128
/// * `$getter:ty`: `Get` implementation; optional; only for `GetOnly` and `Both`.
129
129
/// * `$setter:ty`: `Set` implementation; optional; only for `SetOnly` and `Both`.
130
130
macro_rules! sockopt_impl {
131
- ( GetOnly , $name: ident, $level: path , $flag: path, bool ) => {
131
+ ( GetOnly , $name: ident, $level: expr , $flag: path, bool ) => {
132
132
sockopt_impl!( GetOnly , $name, $level, $flag, bool , GetBool ) ;
133
133
} ;
134
134
135
- ( GetOnly , $name: ident, $level: path , $flag: path, u8 ) => {
135
+ ( GetOnly , $name: ident, $level: expr , $flag: path, u8 ) => {
136
136
sockopt_impl!( GetOnly , $name, $level, $flag, u8 , GetU8 ) ;
137
137
} ;
138
138
139
- ( GetOnly , $name: ident, $level: path , $flag: path, usize ) => {
139
+ ( GetOnly , $name: ident, $level: expr , $flag: path, usize ) => {
140
140
sockopt_impl!( GetOnly , $name, $level, $flag, usize , GetUsize ) ;
141
141
} ;
142
142
143
- ( SetOnly , $name: ident, $level: path , $flag: path, bool ) => {
143
+ ( SetOnly , $name: ident, $level: expr , $flag: path, bool ) => {
144
144
sockopt_impl!( SetOnly , $name, $level, $flag, bool , SetBool ) ;
145
145
} ;
146
146
147
- ( SetOnly , $name: ident, $level: path , $flag: path, u8 ) => {
147
+ ( SetOnly , $name: ident, $level: expr , $flag: path, u8 ) => {
148
148
sockopt_impl!( SetOnly , $name, $level, $flag, u8 , SetU8 ) ;
149
149
} ;
150
150
151
- ( SetOnly , $name: ident, $level: path , $flag: path, usize ) => {
151
+ ( SetOnly , $name: ident, $level: expr , $flag: path, usize ) => {
152
152
sockopt_impl!( SetOnly , $name, $level, $flag, usize , SetUsize ) ;
153
153
} ;
154
154
155
- ( Both , $name: ident, $level: path , $flag: path, bool ) => {
155
+ ( Both , $name: ident, $level: expr , $flag: path, bool ) => {
156
156
sockopt_impl!( Both , $name, $level, $flag, bool , GetBool , SetBool ) ;
157
157
} ;
158
158
159
- ( Both , $name: ident, $level: path , $flag: path, u8 ) => {
159
+ ( Both , $name: ident, $level: expr , $flag: path, u8 ) => {
160
160
sockopt_impl!( Both , $name, $level, $flag, u8 , GetU8 , SetU8 ) ;
161
161
} ;
162
162
163
- ( Both , $name: ident, $level: path , $flag: path, usize ) => {
163
+ ( Both , $name: ident, $level: expr , $flag: path, usize ) => {
164
164
sockopt_impl!( Both , $name, $level, $flag, usize , GetUsize , SetUsize ) ;
165
165
} ;
166
166
167
- ( Both , $name: ident, $level: path , $flag: path, OsString <$array: ty>) => {
167
+ ( Both , $name: ident, $level: expr , $flag: path, OsString <$array: ty>) => {
168
168
sockopt_impl!( Both , $name, $level, $flag, OsString , GetOsString <$array>, SetOsString ) ;
169
169
} ;
170
170
171
171
/*
172
172
* Matchers with generic getter types must be placed at the end, so
173
173
* they'll only match _after_ specialized matchers fail
174
174
*/
175
- ( GetOnly , $name: ident, $level: path , $flag: path, $ty: ty) => {
175
+ ( GetOnly , $name: ident, $level: expr , $flag: path, $ty: ty) => {
176
176
sockopt_impl!( GetOnly , $name, $level, $flag, $ty, GetStruct <$ty>) ;
177
177
} ;
178
178
179
- ( GetOnly , $name: ident, $level: path , $flag: path, $ty: ty, $getter: ty) => {
179
+ ( GetOnly , $name: ident, $level: expr , $flag: path, $ty: ty, $getter: ty) => {
180
180
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
181
181
pub struct $name;
182
182
183
183
getsockopt_impl!( $name, $level, $flag, $ty, $getter) ;
184
184
} ;
185
185
186
- ( SetOnly , $name: ident, $level: path , $flag: path, $ty: ty) => {
186
+ ( SetOnly , $name: ident, $level: expr , $flag: path, $ty: ty) => {
187
187
sockopt_impl!( SetOnly , $name, $level, $flag, $ty, SetStruct <$ty>) ;
188
188
} ;
189
189
190
- ( SetOnly , $name: ident, $level: path , $flag: path, $ty: ty, $setter: ty) => {
190
+ ( SetOnly , $name: ident, $level: expr , $flag: path, $ty: ty, $setter: ty) => {
191
191
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
192
192
pub struct $name;
193
193
194
194
setsockopt_impl!( $name, $level, $flag, $ty, $setter) ;
195
195
} ;
196
196
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) => {
198
198
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
199
199
pub struct $name;
200
200
201
201
setsockopt_impl!( $name, $level, $flag, $ty, $setter) ;
202
202
getsockopt_impl!( $name, $level, $flag, $ty, $getter) ;
203
203
} ;
204
204
205
- ( Both , $name: ident, $level: path , $flag: path, $ty: ty) => {
205
+ ( Both , $name: ident, $level: expr , $flag: path, $ty: ty) => {
206
206
sockopt_impl!( Both , $name, $level, $flag, $ty, GetStruct <$ty>, SetStruct <$ty>) ;
207
207
} ;
208
208
}
@@ -246,6 +246,14 @@ sockopt_impl!(Both, Broadcast, libc::SOL_SOCKET, libc::SO_BROADCAST, bool);
246
246
sockopt_impl ! ( Both , OobInline , libc:: SOL_SOCKET , libc:: SO_OOBINLINE , bool ) ;
247
247
sockopt_impl ! ( GetOnly , SocketError , libc:: SOL_SOCKET , libc:: SO_ERROR , i32 ) ;
248
248
sockopt_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 ) ;
249
257
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
250
258
sockopt_impl ! ( GetOnly , PeerCredentials , libc:: SOL_SOCKET , libc:: SO_PEERCRED , super :: UnixCredentials ) ;
251
259
#[ cfg( any( target_os = "ios" ,
0 commit comments