.TH getsockopt() "" "" "Sockets Function (libsocket)"
.PC "Read a socket option"
.B "#include <sys/types.h>"
.B "#include <sys/socket.h>"
\fBint getsockopt(\fIsocket\^\fB, \fIlevel\^\fB, \fIoption\^\fB, \fIbuffer\^\fB, \fIlength\^\fB)\fR
\fBint \fIsocket\^\fB, \fIlevel\^\fB, \fIoption\^\fB;\fR
\fBchar *\fIbuffer\^\fB;\fR
\fBint *\fIlength\^\fB;\fR
.PP
Function
.B getsockopt()
reads the options that are set on a socket.
.PP
.I socket
gives the identifier of the socket, as returned by the function
.BR socket() .
.PP
.I level
gives the level at which the options are set.
To retrieve options set on the socket level, set
.I level
to
.B SOL_SOCKET ;
whereas to retrieve options set the TCP level, set
.I level
to the number of the TCP protocol.
.PP
.I option
gives the number of the option whose setting interests you.
For a list of options that are recognized at the socket level, see
header file
.BR <sys/socket.h> .
Options at other levels are set by their respective protocols.
.PP
.I buffer
gives the address of the buffer into which the retrieve information will
be written.
.I length
gives the address of an integer that gives the length of
.IR buffer ,
in bytes.
If
.B getsockopt()
succeeds in retrieving the value of the requested option,
it writes the option into
.I buffer
and re-initializes the
.B int
to which
.I length
points to give the length of the material it wrote into
.IR buffer .
.PP
If all goes well,
.B getsockopt()
returns zero.
If something goes wrong, it returns \-1 and sets
.B errno
to one of the following values:
.IP \fBEBADF\fR
.I socket
does not identify a valid socket.
.IP \fBENOMEM\fR
The available user memory was insufficient to complete the operation.
.IP \fBENOPROTOOPT\fR
.I option
gives an unknown option.
.\".IP \fBENOSR\fR
.\"There were insufficient STREAMS
.\"resources available for the operation to
.\"complete.
.IP \fBENOTSOCK\fR
.I socket
identifies a file, not a socket.
.SH "See Also"
.Xr "libsocket," libsocket
.Xr "setsockopt()" setsockop
