getpeereid Subroutine

Note: The getpeerid technology used to support this function in AIX® was originally published by D. J. Bernstein, Associate Professor, Department of Mathematics, Statistics, and Computer Science, University of Illinois at Chicago. In addition, the specific getpeerid syntax reflected originated with William Erik Baxter. All the aforementioned are used by AIX with permission.

Purpose

Gets the effective user ID and effective group ID of a peer on a connected UNIX domain socket.

Syntax

#include <sys/types.h>
	int getpeereid (int socket, uid_t *euid, gid_t *egid)

Description

The getpeereid subroutine returns the effective user and group IDs of the peer connected to a stream socket in the UNIX domain. The effective user and group IDs are saved in the socket, to be returned, when the peer calls connect or listen.

Parameters

Item Description
socket Specifies the descriptor number of a connected socket.
euid The effective user ID of the peer socket.
egid The effective group ID of the peer socket.

Return Values

When the getpeereid subroutine successfully completes, a value of 0 is returned and the euid and egid parameters hold the effective user ID and group ID, respectively.

If the getpeereid subroutine is unsuccessful, the system handler returns a value of -1 to the calling program and sets the errno global variable to an error code that indicates the specific error.

Error Codes

The getpeereid subroutine is unsuccessful if any of the following errors occurs:
Item Description
EBADF The socket parameter is not valid.
ENOTSOCK The socket parameter refers to a file, not a socket.
ENOTCONN The socket is not connected.
ENOBUFS Insufficient resources were available in the system to complete the call.
EFAULT The address parameter is not in a writable part of the user address space.