The getpeereid function returns the effective user and group IDs of the peer connected to a Unix Ns -domain socket. The argument s must be a Unix Ns -domain socket (unix(4)) of type SOCK_STREAM on which either connect(2) or listen(2) have been called. The effective used ID is placed in euid, and the effective group ID in egid.
The credentials returned to the listen(2) caller are those of its peer at the time it called connect(2); the credentials returned to the connect(2) caller are those of its peer at the time it called listen(2). This mechanism is reliable; there is no way for either side to influence the credentials returned to its peer except by calling the appropriate system call (i.e., either connect(2) or listen(2)) under different effective credentials.
One common use of this routine is for a Unix Ns -domain server to verify the credentials of its client. Likewise, the client can verify the credentials of the server.
.Fx , getpeereid is implemented in terms of the LOCAL_PEERCRED unix(4) socket option.
.Rv -std getpeereid
The getpeereid function fails if: