ISocket.getpeername

Obtains the remote socket address.

Note: This generic wrapper should be used only in special situations, the subclass variants for a particular address family are preferred.

getpeername() returns the address of the peer connected to this socket, in the buffer pointed to by remote_address. The addrlen argument is initialized to this.in_addrlen which indicates the amount of space pointed to by addr. On return it contains the actual size of the name returned (in bytes). The name is truncated if the buffer provided is too small; in this case, addrlen will return a value greater than this.in_addrlen.

class ISocket
int
getpeername
(
sockaddr* remote_address
,
out socklen_t addrlen
)

Parameters

remote_address sockaddr*

filled in with the address of the remote socket, as known to the communications layer; expected to point to a sin_addr or sin6_addr instance, depending on the IP version of this instance

addrlen socklen_t

actual address struct length output, initialised to this.in_addrlen; returning a different value indicates socket family mixup

Return Value

Type: int

0 success or -1 on failure. On failure errno is set appropriately.

Errors: EBADF this.fd is not a valid descriptor.

EFAULT remote_address points to memory not in a valid part of the process address space.

EINVAL addrlen is invalid (e.g., is negative).

ENOBUFS Insufficient resources were available in the system to perform the operation.

ENOTCONN The socket is not connected.

ENOTSOCK this.fd is a file, not a socket.

Meta