BSD Sockets Interface Programmer's Guide
Chapter 3 63
Advanced Topics for Stream Sockets
Socket Options
Function result: 0 if the option is set. If getsockopt fails for any reason,
the function returns -1, and the option is not returned.
An error code is stored in errno.
Example:
len = sizeof (optval))
getsockopt(s, SOL_SOCKET, SO_REUSEADDR, &optval, &len;)
optval may never be zero. It must always point to data sent with the
socket option and must always be at least the size of an integer.
The following socket options set socket parameter values. optval is an
integer containing the new value:
• SO_SNDBUF
• SO_RCVBUF
• SO_SNDLOWAT
• SO_RCVLOWAT
• SO_SNDTIMEO
Parameter Contents INPUT Value
OUTPUT
Value
s socket
descriptor
socket descriptor
for which option
values are to be
returned
unchanged
level protocol
level
SOL_SOCKET unchanged
optname name of
option
supported option
name
unchanged
optval pointer to
current
value of
option
pointer to buffer
where option’s
current value is to
be returned
pointer to buffer
that contains
current option
value
optlen pointer to
length of
optval
pointer to
maximum number
of bytes to be
returned by optval
pointer to
actual size of
optval returned