SockGetSockOpt

The SockGetSockOpt() call gets the socket options associated with a socket.

Syntax:

>>--SockGetSockOpt(socket, level, optName, optVal)-----------------------><

where:

socket

is the socket descriptor.

level

specifies which option level is queried for the specified optname. The only supported level is SOL_SOCKET.

optname

is the name of the specified socket option. Only one option can be specified with a call.

optval

is the variable to receive the option values requested. For socket options that are Boolean the option is enabled if optval is nonzero and disabled if optval is 0.

SockGetSockOpt() returns the value of a socket option at the socket level. It can be requested for sockets of all domain types. Some options are supported only for specific socket types.

The following options are recognized for SOL_SOCKET:

SO_BROADCAST

returns the information whether datagram sockets are able to broadcast messages. If this option is enabled, the application can send broadcast messages using datagram socket, if the interface specified in the destination supports broadcasting of packets.

SO_DEBUG

returns the information whether debug information can be recorded for a socket.

SO_DONTROUTE

returns the information whether the socket is able to bypass the routing of outgoing messages. If this option is enabled, outgoing messages are directed to the network interface specified in the network portion of the destination address. When enabled, packets can only be sent to directly connected networks.

SO_ERROR

returns any error pending at the socket and clears the error status. It can be used to check for asynchronous errors at connected datagram sockets or for asynchronous errors that are not explicitly returned by one of the socket calls.

SO_KEEPALIVE

returns the information whether stream sockets are able to send keepalive packets. TCP uses a timer called the keepalive timer. This timer monitors idle connections that might have been disconnected because of a peer crash or timeout. If this option is enabled, a keepalive packet is periodically sent to the peer.

This option is mainly used to enable servers to close connections that are no longer active as a result of clients ending connections without properly closing them.

SO_LINGER

returns the information whether stream sockets are able to linger on close if data is present. If this option is enabled and there is data still to be sent when SockSoClose() is called, the calling application is blocked during the SockSoClose() call until the data is transmitted or the connection has timed out. If this option is disabled, the SockSoClose() call returns without blocking the caller while TCP is trying to send the data. Although the data transfer is usually successful, it cannot be guaranteed because TCP tries to send the data only for a specific amount of time.

SO_OOBINLINE

returns the information whether stream sockets are able to receive out-of-band data. If this option is enabled, out-of-band data is placed in the normal data input queue as it is received. It is then made available to SockRecv() and SockRecvFrom() without the MSG_OOB flag being specified in those calls. If this option is disabled, out-of-band data is placed in the priority data input queue as it is received. It can then only be made available to SockRecv() and SockRecvFrom() by specifying the MSG_OOB flag in those calls.

SO_RCVBUF

returns the buffer size for input.

SO_RCVLOWAT

returns the receive low-water mark.

SO_RCVTIMEO

returns the timeout value for a receive operation.

SO_REUSEADDR

returns the information whether stream and datagram sockets are able to reuse local addresses. If this option is enabled, the local addresses that are already in use can then be bound. This alters the normal algorithm used in the SockBind() call. At connection time, the system checks whether the local addresses and ports differ from foreign addresses and ports. If not, the error value EADDRINUSE is returned.

SO_SNDBUF

returns the size of the send buffer.

SO_SNDLOWAT

returns the send low-water mark. This mark is ignored for nonblocking calls and not used in the Internet domain.

SO_SNDTIMEO

returns the timeout value for a send operation.

SO_TYPE

returns the socket type. The integer pointed to by optval is then set to one of the following: STREAM, DGRAM, RAW, or UNKNOWN.

SO_USELOOPBACK

bypasses hardware where possible.

All option values are integral except for SO_LINGER, which contains the following blank-delimited integers:

Return values:

The value 0 indicates successful execution of the call. The value -1 indicates an error. You can get the specific error code by calling SockSock_Errno() or SockPSock_Errno(). Possible values are:

EADDRINUSE

The address is already in use.

ENOTSOCK

socket is not a valid socket descriptor.

ENOPROTOOPT

optname or level is not recognized.

Note: SockGetSockOpt() interfaces with the C function getsockopt().