28.5.1 Client Applications and Connect Data

A Windows Sockets client application written for a transport that supports connect data should call setsockopt with SOL_SOCKET as the level, SO_CONNDATA as the option name, and a buffer in the option value field containing the connect data it is supposed to send. This call must be made prior to calling the connect function. The specified connect data is then sent with the connect request.

Retrieving response connect data requires a two-step procedure. First, before the connect call, the application must inform the Windows Sockets DLL of how much space to reserve for the response connect data. This is done by calling setsockopt with option level SOL_SOCKET, option name SO_CONNDATALEN, and having the option value parameter pointing to an integer that contains the maximum number of connect data bytes expected. The Windows Sockets DLL will set aside a buffer of this size to contain connect data sent by the server application.

After the connect has completed successfully, the application may call getsockopt with an option level of SOL_SOCKET, option name of SO_CONNDATA, and a large enough buffer in the option value parameter to hold the response connect data. The Windows Sockets DLL then copies the response connect data into the caller's buffer.

The Windows Sockets DLL keeps the response connect data buffer valid for the lifetime of the socket. Therefore, an application may retrieve the response connect data for the socket at any time after the socket is connected and before it is closed.