Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

getsockname() - get the name of a socket

&pagelevel(4)&pagelevel

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

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

Description

The getsockname() function returns the current name for socket s.

name points to a memory area. After successful execution of getsockname(), *name contains the name (address) of socket s. The actual format of the sockaddr structure depends on the address family involved and is described in the  section "Socket addressing".

The size_t variable to which the namelen parameter points initially indicates the size of the memory area referenced by name. When the function returns, *name 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.

ENOTSOCK

Descriptor s references a file and not a socket.

See also

bind(), getpeername(), socket()