6.5.1 Client Applications and Connect Data
An application written to communicate through Windows Sockets with a transport that supports connect data should call setsockopt with SOL_SOCKET as the level, SO_CONNDATA as the option name, and an option value that is a pointer to a buffer containing the connect data the transport should send to the remote node with the connection request. Such an application must call setsockopt before it calls connect, and the application-supplied connect data is transmitted when the application makes its call to connect.
Besides making a call to connect, retrieving response-connect data requires two additional steps:
1.Before calling connect, the application must inform Windows Sockets of how much space to reserve for the expected response-connect data. To do this, the application calls setsockopt with option level SOL_SOCKET, option name SO_CONNDATALEN, and option pointing to an integer that specifies the maximum number of bytes the application expects. Windows Sockets allocates a buffer of this size to contain connect data sent by the server application from the remote node.
2.After connect has completed successfully, the application can call getsockopt with an option level of SOL_SOCKET, option name of SO_CONNDATA, and option pointing to a large enough buffer to hold the response-connect data. Then, Windows Sockets copies the response-connect data, if any, into the application's buffer.
After an application has set up a response-connect buffer, Windows Sockets uses that buffer for the lifetime of the socket. That is, an application can retrieve response-connect data for a particular socket at any time after the socket is connected and before it is closed.