xref: /illumos-gate/usr/src/man/man3xnet/setsockopt.3xnet (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)

Sun Microsystems, Inc. gratefully acknowledges The Open Group for
permission to reproduce portions of its copyrighted documentation.
Original documentation from The Open Group can be obtained online at
http://www.opengroup.org/bookstore/.

The Institute of Electrical and Electronics Engineers and The Open
Group, have given us permission to reprint portions of their
documentation.

In the following statement, the phrase ``this text'' refers to portions
of the system documentation.

Portions of this text are reprinted and reproduced in electronic form
in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
Standard for Information Technology -- Portable Operating System
Interface (POSIX), The Open Group Base Specifications Issue 6,
Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
Engineers, Inc and The Open Group. In the event of any discrepancy
between these versions and the original IEEE and The Open Group
Standard, the original IEEE and The Open Group Standard is the referee
document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html.

This notice shall appear on any product containing this material.

The contents of this file are subject to the terms of the
Common Development and Distribution License (the "License").
You may not use this file except in compliance with the License.

You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions
and limitations under the License.

When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at usr/src/OPENSOLARIS.LICENSE.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]


Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.

SETSOCKOPT 3XNET "Jan 21, 2007"
NAME
setsockopt - set the socket options
SYNOPSIS

cc [ flag... ] file... -lxnet [ library... ]
#include <sys/socket.h>

int setsockopt(int socket, int level, int option_name,
 const void*option_value, socklen_t option_len);
DESCRIPTION

The setsockopt() function sets the option specified by the option_name argument, at the protocol level specified by the level argument, to the value pointed to by the option_value argument for the socket associated 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 argument as SOL_SOCKET. 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(3XNET).

The option_name argument specifies a single option to set. The option_name argument and any specified options are passed uninterpreted to the appropriate protocol module for interpretations. The <sys/socket.h> header defines the socket level options. The options are as follow SO_DEBUG

Turns on recording of debugging information. This option enables or disables debugging in the underlying protocol modules. This option takes an int value. This is a boolean option.

SO_BROADCAST

Permits sending of broadcast messages, if this is supported by the protocol. This option takes an int value. This is a boolean option.

SO_REUSEADDR

Specifies that the rules used in validating addresses supplied to bind(3XNET) should allow reuse of local addresses, if this is supported by the protocol. This option takes an int value. This is a boolean option.

SO_KEEPALIVE

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 messages, the connection is broken and threads writing to that socket are notified with a SIGPIPE signal. This is a boolean option.

SO_LINGER

Lingers on a close(2) if data is present. This option controls the action taken when unsent messages queue on a socket and close(2) is performed. If SO_LINGER is set, the system blocks the process during close(2) until it can transmit the data or until the time expires. If SO_LINGER is not specified, and close(2) is issued, the system handles the call in a way that allows the process 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.

SO_OOBINLINE

Leaves received out-of-band data (data marked urgent) in line. This option takes an int value. This is a boolean option.

SO_SNDBUF

Sets send buffer size. This option takes an int value.

SO_RCVBUF

Sets receive buffer size. This option takes an int value.

SO_DONTROUTE

Requests that outgoing messages bypass the standard routing facilities. The destination must be on a directly-connected network, and messages are directed to the appropriate network interface according to the destination address. The effect, if any, of this option depends on what protocol is in use. This option takes an int value. This is a boolean option.

SO_MAC_EXEMPT

Sets the mandatory access control on the socket. A socket that has this option enabled can communicate with an unlabeled peer if the socket is in the global zone or has a label that dominates the default label of the peer. Otherwise, the socket must have a label that is equal to the default label of the unlabeled peer. SO_MAC_EXEMPT is a boolean option that is available only when the system is configured with Trusted Extensions.

SO_ALLZONES

Bypasses zone boundaries (privileged). This option stores an int value. This is a boolean option. The SO_ALLZONES option can be used to bypass zone boundaries between shared-IP zones. Normally, the system prevents a socket from being bound to an address that is not assigned to the current zone. It also prevents a socket that is bound to a wildcard address from receiving traffic for other zones. However, some daemons which run in the global zone might need to send and receive traffic using addresses that belong to other shared-IP zones. If set before a socket is bound, SO_ALLZONES causes the socket to ignore zone boundaries between shared-IP zones and permits the socket to be bound to any address assigned to the shared-IP zones. If the socket is bound to a wildcard address, it receives traffic intended for all shared-IP zones and behaves as if an equivalent socket were bound in each active shared-IP zone. Applications that use the SO_ALLZONES option to initiate connections or send datagram traffic should specify the source address for outbound traffic by binding to a specific address. There is no effect from setting this option in an exclusive-IP zone. Setting this option requires the sys_net_config privilege. See zones(5).

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.

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.

RETURN VALUES

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.

EDOM

The send and receive timeout values are too big to fit into the timeout fields in the socket structure.

EFAULT

The option_value parameter can not be accessed or written.

EINVAL

The specified option is invalid at the specified socket level or the socket has been shut down.

EISCONN

The socket is already connected, and a specified option can not be set while the socket is connected.

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

There was insufficient memory available for the operation to complete.

ENOBUFS

Insufficient resources are available in the system to complete the call.

ENOSR

There were insufficient STREAMS resources available for the operation to complete.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Standard
MT-Level MT-Safe
SEE ALSO

bind(3XNET), endprotoent(3XNET), getsockopt(3XNET), socket(3XNET), attributes(5), standards(5)