.TH getsockname() "" "" "Sockets Function (libsocket)"
.PC "Get the name of a socket"
\fBint getsockname(\fIsocket\^\fB, \fIname\^\fB, \fInamelen\^\fB)\fR
\fBint \fIsocket\^\fB, *\fInamelen\^\fB; struct sockaddr *\fIname\^\fB;\fR
.PP
Function
.B getsockname()
returns the current name that is bound to
.IR socket .
.PP
.I socket
is a file descriptor that identifies the socket in question.
.I name
points to a space into which
.B getsockname()
can write the socket name.
.I namelen
points to an integer that holds the number of bytes to which
.I name
points.
.B getsockname()
re-initializes this integer to the number of bytes in the name that it
writes at address
.IR name .
.PP
If all goes well,
.B getsockname()
returns zero.
If a problem 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 getsockname()
sets
.BR errno :
.IP \fBEBADF\fR
.I socket
is not a valid file descriptor.
.IP \fIENOTSOCK\fR
.I socket
identifies a file, not a socket.
.IP \fBENOBUFS\fR
The system lacks sufficient resources to perform the operation.
.IP \fBEFAULT\fR
.I name
contains an illegal address.
.SH "See Also"
.Xr "bind()," bind
.Xr "libsocket," libsocket
.Xr "socket()" socket
