getpeername(3)

NAME
getpeername - get address of connected peer

SYNOPSIS
#include <sys/socket.h>

  AF_UNIX only:
#include <sys/un.h>

int getpeername(int s, struct sockaddr *addr,
    size_t *addrlen);

DESCRIPTION
s is a socket descriptor. getpeername returns the address of the peer socket connected to the socket indicated by s. addr points to a socket address structure in which this address is returned. addrlen points to an object of type size_t, which should be initialized to indicate the size of the address structure. On return, it contains the actual size of the address returned (in bytes). If addr does not point to enough space to contain the whole address of the peer, only the first addrlen bytes of the address are returned.

RETURN VALUE
If the call is successful, 0 is returned. If the call fails, -1 is returned and an error code is stored in errno.

DIAGNOSTICS
getpeername fails if:

[EBADF]
    The argument s is not a valid file descriptor.

[ENOTCONN]
    The socket is not connected.

[EINVAL]
    The socket has been shut down. The argument s is a file, not a socket.

[EOPNOTSUPP]
    Operation not supported for AF_UNIX sockets.

SEE ALSO
bind(3), socket(3), getsockname(3).