SO_BSP_STATE socket option

The SO_BSP_STATE socket option returns the local address, local port, remote address, remote port, socket type, and protocol used by a socket.

To perform this operation, call the getsockopt function with the following parameters.

Socket option value

The constant that represents this socket option is 0x1009.

Syntax

int getsockopt(
  (SOCKET) s,      // descriptor identifying a socket 
  (int) SOL_SOCKET,   // level
  (int) SO_BSP_STATE, // optname
  (char *) optval,         // output buffer,
  (int) *optlen,       // size of output buffer
);

Parameters

s [in]

A descriptor identifying the socket.

level [in]

The level at which the option is defined. Use SOL_SOCKET for this operation.

optname [in]

The socket option for which the value is to be retrieved. Use SO_BSP_STATE for this operation.

optval [out]

A pointer to the buffer in which the value for the requested option is to be returned. This parameter should point to buffer equal to or larger than the size of a CSADDR_INFO structure.

optlen [in, out]

A pointer to the size, in bytes, of the optval buffer. This size must be equal to or larger than the size of a CSADDR_INFO structure.

Return value

If the operation completes successfully, getsockopt returns zero.

If the operation fails, a value of SOCKET_ERROR is returned and a specific error code can be retrieved by calling WSAGetLastError.

Error code Meaning
WSANOTINITIALISED
A successful WSAStartup call must occur before using this function.
WSAENETDOWN
The network subsystem has failed.
WSAEFAULT
One of the optval or the optlen parameters point to memory that is not in a valid part of the user address space. This error is also returned if the value pointed to by the optlen parameter is less than the size of a CSADDR_INFO structure.
WSAEINPROGRESS
A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEINVAL
The level parameter is unknown or invalid.
WSAENOPROTOOPT
The option is unknown or unsupported by the indicated protocol family.
WSAENOTSOCK
The descriptor is not a socket.

 

Remarks

The getsockopt function called with the SO_BSP_STATE socket option retrieves the local address, local port, remote address, remote port, socket type, and protocol used by a socket. The SO_BSP_STATE socket option works with IPv6 or IPv4 sockets (the AF_INET6 and AF_INET address families).

If the getsockopt function is successful, the information is returned in a CSADDR_INFO structure in the buffer pointed to by the optval parameter. The integer pointed to by optlen should originally contain the size of this buffer; on return, it will be set to the length, in bytes, of the value returned in the optval parameter.

The iSocketType and iProtocol members in the returned CSADDR_INFO structure are filled in for the socket descriptor in the s parameter.

If the socket is in a connected or bound state, then the LocalAddr member of the returned CSADDR_INFO structure will be set to a SOCKADDR structure representing the local address and port. If the socket is in a connected state, then the RemoteAddr member of the returned CSADDR_INFO structure will be set to a SOCKADDR structure representing the remote address and port.

If the socket is not in a connected or bound state, then the LocalAddr member of the returned CSADDR_INFO structure is returned with a NULL pointer in the lpSockaddr member and the iSockaddrLength member set to zero. If the socket is not in a bound state, then the RemoteAddr member of the returned CSADDR_INFO structure is returned with a NULL pointer in the lpSockaddr member and the iSockaddrLength member set to zero.

If the getsockopt function fails, the optval and optlen parameters are left unchanged and the optval parameter does not point to a returned CSADDR_INFO structure.

Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.

Requirements

Requirement Value
Minimum supported client
Windows Vista [desktop apps only]
Minimum supported server
Windows Server 2008 [desktop apps only]
Header
Ws2def.h (include Winsock2.h)

See also

getsockopt

CSADDR_INFO

SOCKADDR