getsockopt (Windows Sockets)

A version of this page is also available for

Windows Embedded CE 6.0 R3


This function retrieves a socket option.


int getsockopt(
  int level,
  int optname,
  char FAR* optval,
  int FAR* optlen


  • s
    [in] Descriptor identifying a 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 optval buffer.

Return Value

If no error occurs, this function returns zero. If an error occurs, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

The following table shows the possible error codes.

Error code Description


A successful WSAStartup call must occur before using this function.


The network subsystem has failed.


One of the optval or optlen parameters is not a valid part of the user address space, or the optlen parameter is too small.


A blocking Winsock call is in progress, or the service provider is still processing a callback function.


The level parameter is unknown or invalid.


The option is unknown or unsupported by the indicated protocol family.


The descriptor is not a socket.


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 packet routing and out of band (OOB) data transfer.

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 will be set to the size of the value returned. For SO_LINGER, this will be the size of a linger structure. For most other options, it will be 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 the option was never set with setsockopt (Windows Sockets), then getsockopt returns the default value for the option.

To view SOL_SOCKET options that are are supported for getsockopt, see SOL_SOCKET.

To view IPPROTO_TCP options that are are supported for getsockopt, see IPPROTO_TCP.

To view IPPROTO_IP options that are are supported for getsockopt, see IPPROTO_IP.

To view IPPROTO_IPv6 options that are are supported for getsockopt, see IPPROTO_IPV6.

To view IPPROTO_RAW options that are are supported for getsockopt, see Windows Mobile topic IPPROTO_RAW.

To view SOL_IRLMP options that are are supported for getsockopt, see SOL_IRLMP.


Windows Embedded CE does not support Internetwork Packet Exchange (IPX).

The following list shows BSD options that are not supported in Windows Embedded CE for getsockopt


Calling getsockopt with an unsupported option will result in an error code of WSAENOPROTOOPT being returned from WSAGetLastError.

Notes for IrDA Sockets

  • The Af_irda.h header file must be explicitly included.
  • Windows NT® and Windows 2000 will return WSAENETDOWN to indicate the underlying transceiver driver failed to initialize with the IrDA protocol stack.
  • IrDA supports special socket options. For more information about these socket options, see SOL_IRLMP.
  • Many SO level socket options are not meaningful to IrDA; only SO_LINGER and SO_DONTLINGER are specifically supported.

For more inforamtion about IrDA support in Windows Embedded CE, see Infrared Communications.


Header winsock2.h
Library Ws2.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also


bind (Windows Sockets)
setsockopt (Windows Sockets)
socket (Windows Sockets)

Other Resources