This section describes how to create a script that handles receive socket buffers with variable lengths.
Problem
Several applications work with variable length receive sockets. The application makes two calls to the server: the first call to obtain the buffer length and the second call to retrieve the buffer information. VuGen only makes a single call and handles the entire socket as buffer information, thus ignoring the dynamic behavior of the application.
In the following example, the replay failed because it handled all of the bytes as data:
The recording log indicates that two calls were made to the receive buffer by the application. In the first call, four bytes were received. In the second call, 60 bytes were received.
/* recv(): 4 bytes were received from socket 1568 using flags 0 (4 requested) */
(recv_10, 4, 1568)
"\x00\x00\x00"
"<"
/* recv(): 60 bytes were received from socket 1568 using flags 0 (60 requested) */
Create a wrapper function, custom_lrs_receive that makes two calls to lrs_receive_ex: the first to get the buffer header (length), and the second to receive all the other bytes in the receive buffer based to the retrieved length. Define the new function and specify its prototype. This wrapper function should also contain a parsing routine that makes any required conversions, for example a Hex string to a number. You can also add a debug function that issues an error message when the function fails. After you define the wrapper function, replace the lrs_receive function from your script with the new function.
#define lrs_receive custom_lrs_receive
int custom_lrs_receive(char *sock_desc, char *buf_desc,void *dummy)