In addition to binding a socket to a local address or connecting it to a destination address, application programs need a method to control the socket. For example, when using protocols that use time out and retransmission, the application program may want to obtain or set the time-out parameters. An application program may also want to control the allocation of buffer space, determine if the socket allows transmission of broadcast, or control processing of out-of-band data. The ioctl-style getsockopt and setsockopt subroutines provide the means to control socket operations. The getsockopt subroutine allows an application program to request information about socket options. The setsockopt subroutine allows an application program to set a socket option using the same set of values obtained with the getsockopt subroutine. Not all socket options apply to all sockets. The options that can be set depend on the current state of the socket and the underlying protocol being used.
For additional information that you may need when obtaining or setting socket options, read the following concepts: