BSD Sockets Interface Programmer's Guide
Chapter 3 65
Advanced Topics for Stream Sockets
Socket Options
Function result: 0 if setsockopt is successful, –1 if failure occurs.
Example: See the description of the SO_REUSEADDR option for
an example.
Refer to the setsockopt(2) man page for more information on
setsockopt.
SO_REUSEADDR
This option is AF_INET socket-specific.
SO_REUSEADDR enables you to restart a daemon which was killed or
terminated.
This option modifies the rules used by bind to validate local addresses,
but it does not violate the uniqueness requirements of an association.
SO_REUSEADDR modifies the bind rules only when a wildcard Internet
Protocol (IP) address is used in combination with a particular protocol
port. The host still checks at connection time to be sure any other sockets
with the same local address and local port do not have the same remote
address and remote port. Connect fails if the uniqueness requirement is
violated.
Example of the SO_REUSEADDR Option
A network daemon server is listening on a specific port: port 2000. If you
executed netstat an, part of the output would resemble:
Active connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp 0 0 *.2000 *.* LISTEN
optname name of option supported option name
optval pointer to option input
value
Must be at least size of
(int). Holds either value to
be set or boolean flag
optlen length of optval size of optval
Parameter
Description of
Contents
INPUT Value