.TH getpeername() "" "" "Sockets Function (libsocket)"
.PC "Get name of connected peer"
\fBint getpeername(\fIsocket\^\fB, \fIname\^\fB, \fInamelen\^\fB)\fR
\fBint \fIsocket\^\fB, *\fInamelen\^\fB; struct sockaddr *\fIname\^\fB;\fR
.PP
.B getpeername()
returns the name of the ``peer socket'' that is connected to
.IR socket .
.PP
.I name
points to the space into which
.B getpeername()
writes the name of the peer.
.I namelen
points to an integer that gives the amount of space to which
.B name
points.
.B getpeername()
re-initializes it to the length, in bytes, of the peer
name that it has written at
.IR name .
.PP
If all goes well,
.B getpeername()
returns zero.
If an error occurs, it returns \-1 and sets
.B errno
to an appropriate value.
The following lists the errors that can occur, by the value to which
.B getpeername()
sets
.BR errno :
.IP \fBEBADF\fR
.I socket
is not a valid descriptor.
.IP \fBENOTSOCK\fR
.I socket
describes a file, not a socket.
.IP \fBENOTCONN\fR
.I socket
is not connected.
.IP \fBENOBUFS\fR
The system lack resources to perform the operation.
.IP \fBEFAULT\fR
.I name
contains an illegal address.
.SH "See Also"
.Xr "accept()," accept
.Xr "bind()," bind
.Xr "getsockname()," getsockna
.Xr "libsocket," libsocket
.Xr "socket()" socket
