getsockname(3)

NAME
getsockname - get socket address

SYNOPSIS
#include <sys/socket.h>

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

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

DESCRIPTION
s is a socket descriptor. getsockname returns the address of 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 socket, 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 and error code is stored in errno.

DIAGNOSTICS
getsockname fails if:

[EBADF]
    s is not a valid descriptor.

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

[EOPNOTSUPP]
    Operation not supported for AF_UNIX sockets.

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