GetSockOpt

Read syntax diagramSkip visual syntax diagram SOCKET ( ' GETSOCKOPT ' , socketid , level , optname )

Purpose

Use the GetSockOpt function to get the status of options and other data associated with an AF_INET socket. Most socket options are set with the SetSockOpt function. Multiple options can be associated with each socket. You must specify each option or other item you want to query on a separate call.

Parameters

socketid
is the identifier of the socket.
level
is the protocol level for which the socket option or other data is being queried. SOL_SOCKET and IPPROTO_TCP are supported. All optname values beginning with SO_ are for protocol level SOL_SOCKET and are interpreted by the general socket code. All optname values beginning with TCP_ are for protocol level IPPROTO_TCP and are interpreted by the TCP/IP internal code.
optname
is a value that indicates the type of information requested:
Value
Description
SO_ASCII
Gets the status of the SO_ASCII option, which controls the translation of data to ASCII. The setting can be On or Off. When SO_ASCII is On, data is translated to ASCII. When SO_ASCII is Off, data is not translated to or from ASCII. This option is ignored by ASCII hosts. In the return string, the option setting is followed by the name of the translation table used, if translation is applied to the data.
SO_BROADCAST
Gets the status of the SO_BROADCAST option, which controls the ability to send broadcast messages over the socket. The setting can be On or Off. This option does not apply to stream sockets.
SO_DEBUG
Gets the status of the SO_DEBUG option, which controls the recording of debug information. The setting can be On or Off.
SO_EBCDIC
Gets the status of the SO_EBCDIC option, which controls the translation of data to EBCDIC. The setting can be On or Off. When SO_EBCDIC is On, data is translated to EBCDIC. When SO_EBCDIC is Off, data is not translated to or from EBCDIC. In the return string, the option setting is followed by the name of the translation table used, if translation is applied to the data.
SO_ERROR
Gets the pending errors on the socket and clears the error status. It can be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors (errors that are not explicitly returned by one of the socket functions).
SO_KEEPALIVE
Gets the status of the SO_KEEPALIVE option, which controls whether a datagram is periodically sent on an idle connection. The setting can be On or Off.
SO_LINGER
Gets the status of the SO_LINGER option, which controls whether the Close function will linger if data is present. The setting can be On or Off:
  • If SO_LINGER is On and there is unsent data present when Close is called, the calling application is blocked until the data transmission is complete or the connection has timed out.
  • If SO_LINGER is Off, a call to Close returns without blocking the caller. TCP/IP still tries to send the data. Although the data transfer is usually successful, it cannot be guaranteed, because TCP/IP repeats the Send request for only a specified period of time.

In the return string, an On setting is followed by the number of seconds that TCP/IP continues trying to send the data after Close is called.

SO_OOBINLINE
Gets the status of the SO_OOBINLINE option, which controls how out-of-band data is to be received. This option applies only to AF_INET stream sockets. The setting can be On or Off:
  • When SO_OOBINLINE is On, out-of-band data is placed in the normal data input queue as it is received. The Recv and RecvFrom functions can then receive the data without enabling the the MSG_OOB flag.
  • When SO_OOBINLINE is Off, out-of-band data is placed in the priority data input queue as it is received. The Recv and Recvfrom functions must enable the MSG_OOB flag to receive the data.
SO_SNDBUF
Gets the size of the TCP/IP send buffer in OPTVAL.
SO_REUSEADDR
Gets the status of the SO_REUSEADDR option, which controls whether local addresses can be reused. The setting can be On or Off. When SO_REUSEADDR is On, local addresses that are already in use can be bound. Instead of the usual algorithm of checking at Bind time, TCP/IP checks at Connect time to ensure that the local address and port are not the same as the remote address and port. If the association already exists at Connect time, Connect returns Error 48 (EADDRINUSE) and the connect request fails.
SO_TYPE
Gets the socket type, which can be SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.
TCP_NODELAY
Gets the status of the do-not-delay-the-send flag, which indicates whether TCP can send small packets as soon as possible. The setting can be On or Off.

Return Values

If successful, this function returns a string containing return code 0 and the option status or other requested value. If unsuccessful, this function returns a string containing a nonzero return code, an error name, and an error message.

Examples

Call
Return Values
Socket('GetSockOpt',5,'Sol_Socket','So_ASCII')
'0 On STANDARD'
Socket('GetSockOpt',5,'Sol_Socket','So_Broadcast')
'0 On'
Socket('GetSockOpt',5,'Sol_Socket','So_Error')
'0 0'
Socket('GetSockOpt',5,'Sol_Socket','So_Linger')
'0 On 60'
Socket('GetSockOpt',5,'Sol_Socket','So_Sndbuf')
'0 8192'
Socket('GetSockOpt',5,'Sol_Socket','So_Type')
'0 SOCK_STREAM'
Socket('GetSockOpt',5,'IPproto_TCP','TCP_NoDelay')
'0 Off'

The C socket call is: getsockopt(s, level, optname, optval, optlen)

Messages and Return Codes

For a list of REXX Sockets system messages, see REXX Sockets System Messages. For a list of REXX Sockets return codes, see REXX Sockets Return Codes.