|
|
Berkeley Sockets/iX Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 2 Socket System CallsGETSOCKOPT, SETSOCKOPT |
|
getsockopt and setsockopt manipulate options associated with a socket. The socket is identified by the socket descriptor s. Options can exist at multiple protocol levels. Options are described below under the appropriate option. When manipulating socket options, the level at which the option resides (level) and the name of the option (optname) must be specified. To manipulate options at the "socket" level, level is specified as SOL_SOCKET. There are two kinds of options: boolean and non-boolean. Boolean options are either set or not set and also can use optval and optlen (see below) to pass information. Non-boolean options always use optval and optlen to pass information. To determine whether or not a boolean option is set, the return value of getsockopt must be examined. If the option is set, getsockopt returns without error. If the boolean option is not set, getsockopt returns -1 and errno is set to ENOPROTOOPT. For setsockopt, the parameters optval and optlen are used to pass option information from the calling process to the system. optval is the address of a location in memory that contains the option information to be passed to the system. optlen is an integer that specifies the size in bytes of the option information. For getsockopt, optval and optlen are used to pass option information from the system to the calling process. optval is the address of a location in memory that contains the option information to be passed to the calling process, or (char *) NULL if the option information is not of interest and not to be passed to the calling process. optlen is an address of an integer initially used to specify the maximum number of bytes of option information to be passed. If optval is not (char *) NULL, optlen is set on return to the actual number of bytes of option information passed. If the getsockopt call fails, no option information is passed. optname and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file <sys/socket.h> contains definitions for "socket" level options. Options at other protocol levels vary in format and name. The "socket" level options defined in the include file <sys/socket.h> are explained below. When the socket level is SOL_SOCKETS, the following options are available:
SO_LINGER controls the actions taken when unsent messages are queued on a SOCK_STREAM socket and a close is performed. If SO_LINGER is toggled on with a non-zero linger interval, the system blocks the process on the close attempt until it is able to transmit the data or until it decides it is unable to deliver the information. If SO_LINGERis toggled on with a linger interval of zero, the connection is immediately terminated on the close of the socket, and any unsent data queued on the connection is lost. If SO_LINGER is toggled off (default upon socket creation) and a close is issued, the call returns immediately. The system still gracefully brings down the connection by transmitting any queued data, if possible. SO_LINGER can be toggled on/off at any time during the life of an established connection. Toggling SO_LINGER does not affect the action of shutdown. The SO_BROADCAST option requests permission to send internet broadcast datagrams on the socket. The ip level option defined in the include file <netinet/in.h> is explained below. When the socket level is IPPROTO_IP, the following option is available:
No options are defined for this level. The tcp level option defined in the include file <netinet/tcp.h> is described below. When the socket level is IPPROTO_TCP, the following option is available:
If the call is successful, 0 is returned. If it fails, -1 is returned and an error code is stored in errno. The call to getsockopt or setsockopt fails if:
|
|