HP-UX Reference (11i v1 05/09) - 2 System Calls (vol 5)
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 multi-
cast 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 calling
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 sender’s socket address can be returned in the from parameter when
recvfrom() is
called (see recv(2)).
AF_CCITT
SO_SNDBUF and SO_RCVBUF are the only options supported for sockets of the AF_CCITT address fam-
ily.
_XOPEN_SOURCE_EXTENDED Only
The value of l_linger in the linger structure is interpreted as a time limit in seconds.
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.
OBSOLESCENCE
Currently, the
socklen_t and size_t types are the same size. This is compatible with both the UNIX
95 and UNIX 98 profiles. However, in a future release, socklen_t might be a different size. In that
case, passing a size_t pointer will evoke compile-time warnings, which must be corrected in order for the
application to behave correctly. Applications that use socklen_t now, where appropriate, will avoid
such migration problems. On the other hand, applications that need to be portable to the UNIX 95 profile
should follow the X/Open specification (see xopen_networking(7)).
HP-UX 11i Version 1: September 2005 − 4 − Hewlett-Packard Company Section 2−−119