getsockopt.2 (2010 09)

g
getsockopt(2) getsockopt(2)
The parameters optval and optlen specify the value of the option. optval is the address of the data struc-
ture that contains the option value, and optlen is the length of the data structure. The type and value of
the data structure that optval points to depends on the option. For "boolean" options, the value may be
zero (not set) or nonzero (set). The value of other options depends on the purpose of the option. Usually,
neither optval nor optlen may be the NULL address or zero; see individual protocol manual entries for
any exceptions, such as TCP(7P) and IP(7P).
For
setsockopt(), optval and optlen are used to pass information from the application to the system.
optval is the address of a location in memory that contains the option information to be passed to the sys-
tem. The parameter optlen is an integer value that specifies the size, in bytes, of the data structure
pointed to by optval .
For
getsockopt(), optval and optlen are used to pass information from the system to the application.
The parameter optlen is the address of a variable. Before calling
getsockopt(), the application
should set the value of the variable to the maximum size, in bytes, of the data structure pointed to by
optval . Normally, upon return, the variable pointed to by optlen is set to the actual size the data
returned in the structure pointed to by optval, if
getsockopt() returns without error.
The following "socket" level option names (optname ) are defined in
<sys/socket.h>
. The type of the
variable pointed to by optval is indicated in parentheses. Options for other protocol levels are described
in the individual protocol manual pages, such as TCP(7P) and IP(7P).
SO_ACCEPTCONN (int; boolean ) Returns a non-zero value if socket listening is enabled,
otherwise returns a zero value.
SO_BROADCAST (int; boolean; SOCK_DGRAM sockets only) Allows the application to
send messages to a broadcast address. Default: disallowed.
Note, the actual effect of this option is communication domain depen-
dent. In AF_INET domain, broadcasts are always allowed regardless of
the value set for this option. In AF_UNIX domain, broadcasts are not
supported. For validity in other domains, see individual product
manual.
SO_DEBUG (int; boolean; AF_INET SOCK_STREAM sockets only) Enables or dis-
ables the recording of internal debug information. Default: disabled.
SO_DONTROUTE (int; boolean; AF_INET sockets only) Causes outbound messages to
bypass normal routing facilities. Instead, messages are sent through the
appropriate network interface based on the network portion of the desti-
nation address. Default: disabled.
SO_ERROR (int) Returns any pending error on the socket, and clears the error
status. The value returned by SO_ERROR would be the value of errno
after the next socket data transfer system call.
SO_KEEPALIVE (int; boolean; AF_INET SOCK_STREAM sockets only) If enabled, keeps
an otherwise idle TCP connection active. Default: disabled.
SO_LINGER (struct linger; AF_INET SOCK_STREAM sockets only) Controls
whether or not an application "lingers" (waits) if there are untransmitted
data in the send socket buffer when the socket is closed. The data type
struct linger is defined in <sys/socket.h>. Default: dis-
abled, as if l_onoff had been set to zero. (See details below.)
SO_OOBINLINE (int; boolean; AF_INET SOCK_STREAM sockets only) If enabled,
specifies that out-of-band data (TCP "urgent data") should be left "in-line"
among the normal data stream. Otherwise, one byte of out-of-band data
is pulled out of the data stream, and it is accessible only by setting
MSG_OOB in the flags parameter when the application reads the data
(see recv (2)). Default: disabled.
SO_RCVBUF (int) Specifies the maximum size, in bytes, of the receive socket buffer.
For SOCK_DGRAM sockets, the receive buffer size may limit the max-
imum size of messages that the socket can receive.
Default and maximum values: protocol-dependent; see indivi-
dual protocol manual entries, such as TCP(7P) (default buffer size: 32768
bytes; maximum buffer size: 1073725440 bytes; maximum buffer size can
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010