Comtrol eCos User Manual
Page 563

Chapter 38. TCP/IP Library Reference
DESCRIPTION
getsockopt() and setsockopt() manipulate the options associated with a
socket.
Options may exist at multiple protocol levels; they are always
present at the uppermost “socket” level.
When manipulating socket options the level at which the option resides
and the name of the option must be specified.
To manipulate options at
the socket level, level is specified as SOL_SOCKET.
To manipulate
options at any other level the protocol number of the appropriate proto-
col controlling the option is supplied.
For example, to indicate that an
option is to be interpreted by the TCP protocol, level should be set to
the protocol number of TCP; see getprotoent(3).
The parameters optval and optlen are used to access option values for
setsockopt().
For getsockopt() they identify a buffer in which the value
for the requested option(s) are to be returned.
For getsockopt(), optlen
is a value-result parameter, initially containing the size of the buffer
pointed to by optval, and modified on return to indicate the actual size
of the value returned.
If no option value is to be supplied or returned,
optval may be NULL.
optname and any specified options are passed uninterpreted to the appro-
priate protocol module for interpretation.
The include file
<
sys/socket.h> contains definitions for socket level options, described
below.
Options at other protocol levels vary in format and name; consult
the appropriate entries in section 4 of the manual.
Most socket-level options utilize an int parameter for optval.
For
setsockopt(), the parameter should be non-zero to enable a boolean
option, or zero if the option is to be disabled.
SO_LINGER uses a struct
linger parameter, defined in
<
sys/socket.h>, which specifies the desired
state of the option and the linger interval (see below).
SO_SNDTIMEO and
SO_RCVTIMEO use a struct timeval parameter, defined in
<
sys/time.h>.
The following options are recognized at the socket level.
Except as
noted, each may be examined with getsockopt() and set with setsockopt().
SO_DEBUG
enables recording of debugging information
SO_REUSEADDR
enables local address reuse
SO_REUSEPORT
enables duplicate address and port bindings
SO_KEEPALIVE
enables keep connections alive
SO_DONTROUTE
enables routing bypass for outgoing messages
SO_LINGER
linger on close if data present
SO_BROADCAST
enables permission to transmit broadcast messages
SO_OOBINLINE
enables reception of out-of-band data in band
SO_SNDBUF
set buffer size for output
SO_RCVBUF
set buffer size for input
SO_SNDLOWAT
set minimum count for output
SO_RCVLOWAT
set minimum count for input
SO_SNDTIMEO
set timeout value for output
SO_RCVTIMEO
set timeout value for input
SO_TYPE
get the type of the socket (get only)
SO_ERROR
get and clear error on the socket (get only)
459