The setsockopt function

Description

The setsockopt function sets the current value of a socket's option.

Declaration

The system include file WinSock2.inc contains the following declaration for the setsockopt function:

 function setsockopt(s : SOCKET; level, optname : integer; optval : address; optlen : integer) : integer;
  external dll='ws2_32.dll';

Arguments

The First Argument

The first argument passed to the setsockopt function is the socket for which you want to set the option value.

The Second Argument

The second argument passed to the setsockopt function is the level at which the socket option is defined. You will usually use SOL_SOCKET as the value of this argument.

The third argument passed to the setsockopt function is an integer value that identifies the socket option whose value you want to set. The socket options you are most likely to set are given below:

Return Values

The setsockopt function returns a value of integer type that indicates whether the call was successful. A value of zero means that the call succeeded. A value of SOCKET_ERROR indicates that the called failed, and in this case you can use the WSAGetLastError function to retrieve a code that identifies the error that caused the call to fail. NOTE: The constant SOCKET_ERROR is declared in the system include file WinSock2.inc.

Reference Information

The authoritative source of information about the WinSock2 library is the Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website at msdn.microsoft.com.