SYNOPSIS
#include <sys/socket.h>
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
DESCRIPTION
The
The level argument specifies the protocol level at which the option resides. To retrieve options at the socket level, specify the level argument as SOL_SOCKET. To retrieve options at other levels, supply the appropriate protocol number for the protocol controlling the option. For example, to indicate that an option is to be interpreted by the TCP (Transport Control Protocol), set level to the protocol number of TCP.
The value associated with the selected option is returned in the buffer optval. The integer pointed to by optlen should originally contain the size of this buffer; on return, it is set to the size of the value returned. For SO_LINGER, this is the size of a struct linger; for most other options it is the size of an integer.
The application is responsible for allocating any memory space pointed to directly or indirectly by any of the parameters it specified.
If an option has not been set with
The following options are supported for
- SO_DEBUG
-
Reports whether debugging information is being recorded. This option stores an int value in the optval argument. This is a BOOL option.
- SO_ACCEPTCONN
-
Reports whether socket listening is enabled. This option stores an int value in the optval argument. This is a BOOL option.
- SO_BROADCAST
-
Reports whether transmission of broadcast messages is supported, if this is supported by the protocol. This option stores an int value in the optval argument. This is a BOOL option.
- SO_REUSEADDR
-
Reports whether the rules used in validating addresses supplied to
bind() should allow reuse of local addresses, if this is supported by the protocol. This option stores an int value in the optval argument. This is a BOOL 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 and processes writing to that socket are notified with an ENETRESET errno. This option stores an int value in the optval argument. This is a BOOL option.
- SO_LINGER
-
Reports whether the socket lingers on
close() if data is present. If SO_LINGER is set, the system blocks the process duringclose() 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, andclose() is issued, the system handles the call in a way that allows the process to continue as quickly as possible. This option stores a linger structure in the optval argument. - SO_OOBINLINE
-
Reports whether the socket leaves received out-of-band data (data marked urgent) in line. This option stores an int value in optval argument. This is a BOOL option.
- SO_SNDBUF
-
Reports send buffer size information. This option stores an int value in the optval argument.
- SO_RCVBUF
-
Reports receive buffer size information. This option stores an int value in the optval argument.
- SO_ERROR
-
Reports information about error status and clears it. This option stores an int value in the optval argument.
- SO_TYPE
-
Reports the socket type. This option stores an int value in the optval argument.
- SO_DONTROUTE
-
Reports whether outgoing messages bypass the standard routing facilities. The destination must 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 in the optval argument. This is a BOOL option.
- SO_MAX_MSG_SIZE
-
Maximum size of a message for message-oriented socket types (for example, SOCK_DGRAM). Has no meaning for stream-oriented sockets. This option stores an int value in the optval argument.
- TCP_NODELAY
-
Specifies whether the Nagle algorithm used by TCP for send coalescing is disabled. This option stores an int value in the optval argument. This is a BOOL option.
For boolean options, a zero value indicates that the option is disabled and a non-zero value indicates that the option is enabled.
PARAMETERS
- s
-
Is a socket descriptor.
- level
-
Identifies the level at which the option exists. Choose between the socket level or the underlying protocol. Socket level is indicated by the symbolic constant SOL_SOCKET. Any other level requires the protocol number of the appropriate protocol controlling the option.
- optname
-
Specifies a single option to which the request applies.
- optval
-
Points to the buffer where the option is returned. Can be 0 if no option value is to be supplied or returned.
- optlen
-
Initially contains the buffer size pointed to by optval. Upon return, contains the actual size of the returned value.
RETURN VALUES
If successful,
- EBADF
-
The parameter s is not a valid descriptor.
- ENOPROTOOPT
-
The option is unknown at the level indicated.
- ENOTSOCK
-
The parameter s is a file, not a socket.
CONFORMANCE
UNIX 98, with exceptions.
MULTITHREAD SAFETY LEVEL
MT-Safe.
PORTING ISSUES
The following BSD options are not supported: SO_RCVLOWAT, SO_RCVTIMEO, SO_SNDLOWAT, SO_SNDTIMEO,i TCP_MAXSEG.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
close() ,ioctl() ,read() ,setsockopt() ,socket()
PTC MKS Toolkit 10.5 Documentation Build 40.