setsockopt(3N-xs) (X/OPEN SOCKETS) setsockopt(3N-xs)
NAME
setsockopt - set the socket options
SYNOPSIS
cc [flag ...] file ... -lxnet [library ...]
#include <sys/socket.h>
int setsockopt(int socket, int level, int optionname, const void
*optionvalue, sizet optionlen);
DESCRIPTION
The setsockopt function sets the option specified by the optionname
argument, at the protocol level specified by the level argument, to
the value pointed to by the optionvalue argument for the socket asso-
ciated with the file descriptor specified by the socket argument.
The level argument specifies the protocol level at which the option
resides. To set options at the socket level, specify the level argu-
ment as SOLSOCKET. To set options at other levels, supply the
appropriate protocol number for the protocol controlling the option.
For example, to indicate that an option will be interpreted by the TCP
(Transport Control Protocol), set level to the protocol number of TCP,
as defined in the <netinet/in.h> header, or as determined by using
getprotobyname.
The optionname argument specifies a single option to set. The
optionname argument and any specified options are passed uninter-
preted to the appropriate protocol module for interpretations. The
<sys/socket.h> header defines the socket level options. The socket
level options can be enabled or disabled. The options are as follows:
SODEBUG Turns on recording of debugging information. This
option enables or disables debugging in the underlying
protocol modules. This option takes an int value.
SOBROADCAST Permits sending of broadcast messages, if this is sup-
ported by the protocol. This option takes an int
value.
SOREUSEADDR Specifies that the rules used in validating addresses
supplied to bind should allow reuse of local
addresses, if this is supported by the protocol. This
option takes an int value.
SOKEEPALIVE Keeps connections active by enabling the periodic
transmission of messages, if this is supported by the
protocol. This option takes an int value.
If the connected socket fails to respond to these mes-
sages, the connection is broken and processes writing
to that socket are notified with a SIGPIPE signal.
Page 1 Reliant UNIX 5.44 Printed 11/98
setsockopt(3N-xs) (X/OPEN SOCKETS) setsockopt(3N-xs)
SOLINGER Lingers on a close if data is present. This option
controls the action taken when unsent messages queue
on a socket and close is performed. If SOLINGER is
set, the system blocks the process during close until
it can transmit the data or until the time expires. If
SOLINGER is not specified, and close is issued, the
system handles the call in a way that allows the pro-
cess to continue as quickly as possible. This option
takes a linger structure, as defined in the
<sys/socket.h> header, to specify the state of the
option and linger interval.
SOOOBINLINE Leaves received out-of-band data (data marked urgent)
in line. This option takes an int value.
SOSNDBUF Sets send buffer size. This option takes an int value.
SORCVBUF Sets receive buffer size. This option takes an int
value.
For boolean options, 0 indicates that the option is disabled and 1
indicates that the option is enabled.
Options at other protocol levels vary in format and name.
RETURN VALUE
Upon successful completion, setsockopt returns 0. Otherwise, -1 is
returned and errno is set to indicate the error.
ERRORS
The setsockopt function will fail if:
EBADF The socket argument is not a valid file descriptor.
EINVAL The specified option is invalid at the specified
socket level or the socket has been shut down.
ENOPROTOOPT The option is not supported by the protocol.
ENOTSOCK The socket argument does not refer to a socket.
The setsockopt function may fail if:
ENOMEM The memory available was not sufficient to complete
the operation.
ENOBUFS The resources available in the system are not suffi-
cient to complete the call.
ENOSR There were insufficient STREAMS resources available
for the operation to complete.
Page 2 Reliant UNIX 5.44 Printed 11/98
setsockopt(3N-xs) (X/OPEN SOCKETS) setsockopt(3N-xs)
APPLICATION USAGE
The setsockopt function provides an application program with the means
to control socket behavior. An application program can use setsockopt
to allocate buffer space, control timeouts, or permit socket data
broadcasts. The <sys/socket.h> header defines the socket-level options
available to setsockopt.
Options may exist at multiple protocol levels. The SO options are
always present at the uppermost socket level.
SEE ALSO
bind(3N-xs), getprotoent(3N-xs), getsockopt(3N-xs), socket(3N-xs),
ip(7).
Page 3 Reliant UNIX 5.44 Printed 11/98