4 #include <sys/socket.h>
7 * get the effective user ID and effective group ID of a peer
8 * connected through a Unix domain socket.
10 int getpeereid(int sd
, uid_t
*euid
, gid_t
*egid
) {
13 socklen_t ucred_length
;
15 /* Initialize Data Structures */
16 ucred_length
= sizeof(struct ucred
);
17 memset(&cred
, '\0', ucred_length
);
19 /* Validate Input Parameters */
20 if (euid
== NULL
|| egid
== NULL
) {
23 } /* getsockopt will handle validating 'sd' */
25 /* Get the credentials of the peer at the other end of 'sd' */
26 rc
= getsockopt(sd
, SOL_SOCKET
, SO_PEERCRED
, &cred
, &ucred_length
);
28 /* Success - return the results */
33 /* Failure - getsockopt takes care of setting errno */