SETSOCKOPT(3XNET) | X/Open Networking Services Library Functions | SETSOCKOPT(3XNET) |
setsockopt - set the socket options
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);
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
SO_BROADCAST
SO_REUSEADDR
SO_KEEPALIVE
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
SO_OOBINLINE
SO_SNDBUF
SO_RCVBUF
SO_DONTROUTE
SO_MAC_EXEMPT
SO_ALLZONES
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(7).
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.
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.
Upon successful completion, setsockopt() returns 0. Otherwise, -1 is returned and errno is set to indicate the error.
The setsockopt() function will fail if:
EBADF
EDOM
EFAULT
EINVAL
EISCONN
ENOPROTOOPT
ENOTSOCK
The setsockopt() function may fail if:
ENOMEM
ENOBUFS
ENOSR
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Standard |
MT-Level | MT-Safe |
bind(3XNET), endprotoent(3XNET), getsockopt(3XNET), socket(3XNET), attributes(7), standards(7)
January 21, 2007 | OmniOS |