Skip to content

Commit 68ff495

Browse files
author
Joe Ellis
committedSep 14, 2020
Fix peer credentials for Android
1 parent 72eef61 commit 68ff495

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed
 

‎library/std/src/sys/unix/ext/ucred.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,23 @@ pub mod impl_linux {
4343
use crate::os::unix::io::AsRawFd;
4444
use crate::os::unix::net::UnixStream;
4545
use crate::{io, mem};
46+
use libc::{c_void, getsockopt, socklen_t, ucred, SOL_SOCKET, SO_PEERCRED};
4647

4748
pub fn peer_cred(socket: &UnixStream) -> io::Result<UCred> {
48-
use libc::{c_void, ucred};
49-
5049
let ucred_size = mem::size_of::<ucred>();
5150

5251
// Trivial sanity checks.
5352
assert!(mem::size_of::<u32>() <= mem::size_of::<usize>());
5453
assert!(ucred_size <= u32::MAX as usize);
5554

56-
let mut ucred_size = ucred_size as u32;
55+
let mut ucred_size = ucred_size as socklen_t;
5756
let mut ucred: ucred = ucred { pid: 1, uid: 1, gid: 1 };
5857

5958
unsafe {
60-
let ret = libc::getsockopt(
59+
let ret = getsockopt(
6160
socket.as_raw_fd(),
62-
libc::SOL_SOCKET,
63-
libc::SO_PEERCRED,
61+
SOL_SOCKET,
62+
SO_PEERCRED,
6463
&mut ucred as *mut ucred as *mut c_void,
6564
&mut ucred_size,
6665
);

0 commit comments

Comments
 (0)
Please sign in to comment.