getpeername()

get the name of the peer connected to a socket

Synopsis:

#include <sys/socket.h>

int getpeername( int s, 
                 struct sockaddr *name, 
                 int *namelen );

Description:

The getpeername() function returns the name of the peer connected to socket s. You should initialize the namelen parameter to indicate the amount of space pointed to by name. On return, namelen contains the actual size of the name (in bytes). The name is truncated if the buffer provided is too small.

Returns:

The address of the remote socket, or -1 if an error occurs (errno is set).

Errors:

If an error occurred, errno could contain one of the following:

EBADF
The argument s isn't a valid descriptor.
EFAULT
The name parameter points to memory that isn't in a valid part of the process address space.
ENOBUFS
Insufficient resources were available in the system to perform the operation.
ENOTCONN
The socket isn't connected.

Classification:

POSIX 1003.1g (draft)

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

accept(), bind(), getsockname(), socket()