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 getsockopt(
  SOCKET 
s,
  int 
level,
  int 
optname,
  char FAR* 
optval,
  int FAR* 
optlen
);

Parameters

s

[in] Descriptor identifying a socket.

level

[in] Level at which the option is defined; the supported levels include:

IPPROTO_IP

IPPROTO_IPV6

IPPROTO_TCP

IPPROTO_UDP

SOL_SOCKET

SOL_IRLMP

IPPROTO_RAW

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.

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

WSANOTINITIALISED

A successful WSAStartupcall must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAEFAULT

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

WSAEINPROGRESS

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

WSAEINVAL

The levelparameter is unknown or invalid.

WSAENOPROTOOPT

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

WSAENOTSOCK

The 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 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 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 lingerstructure. 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 getsockoptreturns 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.

Note:
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

  • SO_RCVLOWAT

  • SO_RCVTIME

  • SO_SNDLOWAT

  • SO_SNDTIMEO

  • TCP_MAXSEG

Calling getsockoptwith 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.

Requirements

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