getsockopt.2 (2010 09)

g
getsockopt(2) getsockopt(2)
Setting the SO_REUSEADDR option allows the local socket address to be reused in subsequent calls to
bind(). This permits multiple SOCK_STREAM sockets to be bound to the same local address, as long
as all existing sockets with the desired local address are in a connected state before
bind() is called for
a new socket. For SOCK_DGRAM sockets,
SO_REUSEADDR allows multiple sockets to receive UDP mul-
ticast datagrams addressed to the bound port number. For all SOCK_DGRAM sockets bound to the same
local address,
SO_REUSEADDR must be set before calling
bind().
Setting the
SO_REUSEPORT option allows multiple SOCK_DGRAM sockets to share the same address
and port. Each one of those sockets, including the first one to use that port, must specify this option
before calling bind().
SO_RCVBUF and SO_SNDBUF specify the maximum number of bytes that the system may allocate, as
needed, for the receive and send buffers, respectively. These limits are merely approximate because of
the way in which memory is allocated. For example, a large number of small transmissions may require
more memory than the sum of the number of data bytes sent. The default receive and send buffer sizes
are protocol-specific. For more information, see the appropriate manual entries, such as TCP(7P) and
UDP(7P).
For SOCK_STREAM sockets, larger buffer sizes can improve performance. An application can increase
the size of the receive buffer at any time; however, it can decrease the receive buffer size only prior to cal-
ling
connect() or listen(). An application can increase or decrease the send buffer at any time.
For SOCK_DGRAM sockets, the size of the receive and send buffers limits the size of the maximum
datagram that can be received and sent, respectively. These limits include socket buffer space that is also
used to save the sender’s socket address (
struct sockaddr
) which is associated with each datagram
transmission. The senders socket address can be returned in the from parameter when
recvfrom() is
called (see recv (2)).
AF_CCITT Only
SO_SNDBUF and SO_RCVBUF are the only options supported for sockets of the AF_CCITT address fam-
ily.
X/Open Sockets Only
The value of
l_linger in the linger structure is interpreted as a time limit in seconds.
X/Open Sockets Compilation Environment
See xopen_networking(7).
RETURN VALUE
getsockopt() and setsockopt() return the following values:
0 Successful completion.
-1 Failure. errno is set to indicate the error.
ERRORS
If
getsockopt() or setsockopt() fails, errno is set to one of the following values:
[EBADF] The argument s is not a valid descriptor.
[EFAULT] The optval or optlen address is not valid.
[EINVAL] The level or optlen value is not valid; or optval is the NULL address; or the
protocol connection has been released.
[ENOBUFS] Insufficient memory is available for internal system data structures.
[ENOPROTOOPT] The option is not recognized at the specified option level.
[ENOTSOCK] The argument s is not a socket descriptor.
[EOPNOTSUPP] The option is not supported by the socket family or socket type.
[EINTR] The operation was interrupted by a signal. Application needs to retry
get-
sockopt() if it wants to get the value of an option or retry setsockopt()
to set an option.
OBSOLESCENCE
Currently, the
socklen_t and size_t types are the same size. This is compatible with the UNIX 95
and UNIX 03 profiles. However, in a future release, socklen_t might be a different size. In that case,
4 Hewlett-Packard Company 4 HP-UX 11i Version 3: September 2010