|
The getsockopt function retrieves the value for the option specified by the option_name argument for the socket specified by the socket argument. If the size of the option value is greater than option_len, the value stored in the object pointed to by the option_value argument is silently truncated. Otherwise, the object pointed to by the option_len argument is modified to indicate the actual length of the value.
Syntax
int getsockopt(
int socket,
int level,
int option_name,
void *option_value,
int *option_len
);
|
Parameters
socket
A descriptor that identifies a socket.
level
Specifies the protocol level at which the option resides. To retrieve options at the socket level specify the level as SOL_SOCKET. To retrieve options at other levels, supply the appropriate level identifier for the protocol controlling the option (for example IPPROTO_TCP for TCP protocol).
option_name
Specifies a single option to be retrieved. The socket.h header defines the socket-level options. The options are as follows:
Type
|
Meaning
|
SO_ACCEPTCONN
|
Reports whether socket listening is enabled. This option stores an int value. This is a Boolean option.
|
SO_BROADCAST
|
Reports whether transmission of broadcast messages is supported, if this is supported by the protocol. This option stores an int value. This is a Boolean option.
|
SO_REUSEADDR
|
Reports whether the rules used in validating addresses supplied to bind allows reuse of local addresses, if this is supported by the protocol. This option stores an int value. This is a Boolean option.
|
SO_KEEPALIVE
|
Reports whether connections are kept active with periodic transmission of messages, if this is supported by the protocol.
If the connected socket fails to respond to these messages, the connection is broken. This option shall store an int value. This is a Boolean option.
|
SO_LINGER
|
Reports whether the socket lingers on closesocket if data is present. If SO_LINGER is set, the system blocks the calling thread during closesocket until it can transmit the data or until the end of the interval indicated by the l_linger member, whichever comes first. If SO_LINGER is not specified, and closesocket is issued, the system handles the call in a way that allows the calling thread to continue as quickly as possible. This option stores a linger structure.
|
SO_OOBINLINE
|
Reports whether the socket leaves received out-of-band data (data marked urgent) inline. This option stores an int value. This is a Boolean option.
|
SO_SNDBUF
|
Reports send buffer size information. This option stores an int value.
|
SO_RCVBUF
|
Reports receive buffer size information. This option stores an int value.
|
SO_ERROR
|
Reports information about error status and clears it. This option shall store an int value.
|
SO_TYPE
|
Reports the socket type. This option stores an int value.
|
SO_DONTROUTE
|
Reports whether outgoing messages bypass the standard routing facilities. The destination shall be on a directly-connected network, and messages are directed to the appropriate network interface according to the destination address. The effect, if any, of this option depends on what protocol is in use. This option stores an int value. This is a Boolean option.
|
SO_RCVLOWAT
|
Reports the minimum number of bytes to process for socket input operations. The default value for SO_RCVLOWAT is 1. If SO_RCVLOWAT is set to a larger value, blocking receive calls normally wait until they have received the smaller of the low water mark value or the requested amount. (They may return less than the low water mark if an error occurs, a signal is caught, or the type of data next in the receive queue is different from that returned; for example, out-of-band data.) This option stores an int value.
|
SO_RCVTIMEO
|
Reports the timeout value for input operations. This option stores a timeval structure with the number of seconds and microseconds specifying the limit on how long to wait for an input operation to complete. If a receive operation has blocked for this much time without receiving additional data, it returns with a partial count or errno set to [EAGAIN] or [EWOULDBLOCK] if no data was received. The default for this option is zero, which indicates that a receive operation shall not time out.
|
SO_SNDLOWAT
|
Reports the minimum number of bytes to process for socket output operations. Non-blocking output operations process no data if flow control does not allow the smaller of the send low water mark value or the entire request to be processed. This option shall store an int value.
|
SO_SNDTIMEO
|
Reports the timeout value specifying the amount of time that an output function blocks because flow control prevents data from being sent. If a send operation has blocked for this time, it returns with a partial count or with errno set to [EAGAIN] or [EWOULDBLOCK] if no data was sent. The default for this option is zero, which indicates that a send operation shall not time out. The option stores a timeval structure.
|
For Boolean options, 0 indicates that the option is disabled and 1 indicates that the option is enabled.
option_value
A pointer to the buffer in which the value for the requested option is specified.
option_len
The size, in bytes, of the buffer pointed to by the option_value parameter.
Return value
If no error occurs, getsockopt returns 0; otherwise, -1 is returned and errno set to indicate the error.
|