.Os BSD 4.2
.Sh NAME
.Nm getpeername
-.Nd get name of connected peer
+.Nd get address of connected peer
.Sh SYNOPSIS
.Fd #include <sys/socket.h>
.Ft int
-.Fn getpeername "int s" "struct sockaddr *name" "int *namelen"
+.Fo getpeername
+.Fa "int socket"
+.Fa "struct sockaddr *restrict address"
+.Fa "socklen_t *restrict address_len"
+.Fc
.Sh DESCRIPTION
-.Fn Getpeername
-returns the name of the peer connected to
-socket
-.Fa s .
The
-.Fa namelen
+.Fn getpeername
+function returns the address of the peer connected to the specified
+socket.
+.Pp
+The
+.Fa address_len
parameter should be initialized to indicate
the amount of space pointed to by
-.Fa name .
-On return it contains the actual size of the name
+.Fa address .
+On return it contains the actual size of the address
returned (in bytes).
-The name is truncated if the buffer provided is too small.
-.Sh DIAGNOSTICS
-A 0 is returned if the call succeeds, -1 if it fails.
+.Pp
+The address is truncated if the buffer provided is too small.
+.Sh RETURN VALUES
+.Rv -std getpeername
.Sh ERRORS
The call succeeds unless:
.Bl -tag -width Er
+.\" ==========
.It Bq Er EBADF
The argument
-.Fa s
+.Fa socket
is not a valid descriptor.
-.It Bq Er ENOTSOCK
-The argument
-.Fa s
-is a file, not a socket.
-.It Bq Er ENOTCONN
-The socket is not connected.
-.It Bq Er ENOBUFS
-Insufficient resources were available in the system
-to perform the operation.
+.\" ==========
.It Bq Er EFAULT
The
-.Fa name
+.Fa address
parameter points to memory not in a valid part of the
process address space.
+.\" ==========
+.It Bq Er EINVAL
+.Fa socket
+has been shut down.
+.\" ==========
+.It Bq Er ENOBUFS
+Insufficient resources were available in the system
+to perform the operation.
+.\" ==========
+.It Bq Er ENOTCONN
+Either the socket is not connected
+or it has not had the peer pre-specified.
+.\" ==========
+.It Bq Er ENOTSOCK
+The argument
+.Fa socket
+refers to something other than a socket (e.g., a file).
+.\" ==========
+.It Bq Er EOPNOTSUPP
+.Fn getpeername
+is not supported for the protocol in use by
+.Fa socket .
.El
.Sh SEE ALSO
.Xr accept 2 ,
.Xr bind 2 ,
-.Xr socket 2 ,
-.Xr getsockname 2
+.Xr getsockname 2 ,
+.Xr socket 2
.Sh HISTORY
The
.Fn getpeername