Skip to content

Commit 6923954

Browse files
tobzThomasdezeeuw
authored andcommitted
Add test for Socket::passcred/set_passcred and fix formatting.
1 parent 630c8a7 commit 6923954

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/sys/unix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ pub(crate) use libc::SO_LINGER;
172172
target_os = "watchos",
173173
))]
174174
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
175+
#[cfg(target_os = "linux")]
176+
pub(crate) use libc::SO_PASSCRED;
175177
pub(crate) use libc::{
176178
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
177179
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
178180
IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET,
179181
SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF,
180182
SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
181183
};
182-
#[cfg(target_os = "linux")]
183-
pub(crate) use libc::SO_PASSCRED;
184184
#[cfg(not(any(
185185
target_os = "dragonfly",
186186
target_os = "haiku",

tests/socket.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1680,3 +1680,19 @@ fn cookie() {
16801680
Err(err) => panic!("Could not get socket cookie a second time, err: {err}"),
16811681
}
16821682
}
1683+
1684+
#[cfg(all(unix, target_os = "linux"))]
1685+
#[test]
1686+
fn set_passcred() {
1687+
let socket = Socket::new(Domain::UNIX, Type::DGRAM, None).unwrap();
1688+
assert!(!socket.passcred().unwrap());
1689+
1690+
socket.set_passcred(true).unwrap();
1691+
assert!(socket.passcred().unwrap());
1692+
1693+
let socket = Socket::new(Domain::UNIX, Type::STREAM, None).unwrap();
1694+
assert!(!socket.passcred().unwrap());
1695+
1696+
socket.set_passcred(true).unwrap();
1697+
assert!(socket.passcred().unwrap());
1698+
}

0 commit comments

Comments
 (0)