1.1.27.20 getsockname

C

int getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen)

Description

Returns the current address to which the socket fd is bound.

Parameters

ParametersDescription
fdSocket file descriptor.
addrPointer to address structure.
addrlenLength of address structure.

Returns

On success, zero is returned.

On error, -1 is returned, and errno is set to indicate the error.

Remarks

errnoDescription
EFAULTSystem fault.
EINVALaddrlen is invalid (e.g., is negative).
ENOTSOCKThe file descriptor fd does not refer to a socket.
ENOTCONNThe socket is not connected, and no target has been given.