Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getpeername() - get the name of the communications partner

&pagelevel(4)&pagelevel

#include <sys/socket.h>
#include <netinet/in.h>

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

Description

The getpeername() returns the name of the communications partner connected to socket s.

name points to a memory area. After getpeername() has been executed successfully, *name contains the address of the communications partner.

The size_t variable, to which the namelen parameter points, initially indicates the size of the memory area referenced by name. After the function returns, *namelen contains the current size of the returned name in bytes.

Return value

0:

If successful.

-1:

If errors occur. errno is set to indicate the error.

Errors

EBADF

The s parameter is not a valid descriptor.

EFAULT

The name parameter points to an area outside the process address range.

ENOTCONN

The socket has no connection.

ENOTSOCK

Descriptor s references a file and not a socket.

See also

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