Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function retrieves a socket option.

Syntax

int WSPGetSockOpt(
  SOCKET 
s,
  int 
level,
  int 
optname,
  char FAR* 
optval,
  LPINT 
optlen,
  LPINT 
lpErrno 
);

Parameters

s

[in] Descriptor identifying a socket.

level

[in] Level at which the option is defined; the supported levels include SOL_SOCKET. To view SOL_SOCKET options that are are supported for WSPGetSockOpt, see SOL_SOCKET.

optname

[in] Socket option for which the value is to be retrieved.

optval

[out] Pointer to the buffer in which the value for the requested option is to be returned.

optlen

[in, out] Pointer to the size of the optvalbuffer.

lpErrno

[out] A pointer to the error code.

Return Value

If no error occurs, this function returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code is available in lpErrno.

The following table shows the possible error codes.

Error value Description

WSAENETDOWN

Network subsystem has failed.

WSAEFAULT

One of the optvalor the optlenparameters is not a valid part of the user address space, or the optlenparameter is too small.

WSAEINVAL

The levelis unknown or invalid.

WSAEINPROGRESS

Function is invoked when a callback is in progress.

WSAENOPROTOOPT

Option is unknown or unsupported by the indicated protocol family.

WSAENOTSOCK

Descriptor is not a socket.

Remarks

This function retrieves the current value for a socket option associated with a socket of any type, in any state, and stores the result in optval. Options can exist at multiple protocol levels, but they are always present at the uppermost socket level. Options affect socket operations, such as the routing of packets and OOB data transfer.

The value associated with the selected option is returned in the buffer optval. The integer pointed to by optlenshould originally contain the size of this buffer; on return, it will be set to the size of the value returned. For SO_LINGER, this will be the size of a structure linger; for most other options it will be the size of an integer.

The Windows Sockets SPI client is responsible for allocating any memory space pointed to directly or indirectly by any of the parameters it specifies.

If the option was never set with WSPSetSockOpt, then WSPGetSockOptreturns the default value for the option.

Calling WSPGetSockOptwith an unsupported option will result in an error code of WSAENOPROTOOPT being returned in lpErrno.

Requirements

Header ws2spi.h
Library Ws2.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also