Share this page

# lrs_length_send

Sockets Functions

Sends data of a specified length on a stream socket.

    int lrs_length_send( char *socket_descriptor, char *buffer, int location_option, [char* locators], [char* additional_params], LrsLastArg );

socket_descriptor | A descriptor identifying the socket.
buffer | A descriptor identifying the buffer to send. For details on editing the Windows Sockets Buffers, see the Windows Sockets protocol in the VuGen User Guide.
location_option | The method with which to locate the field within the buffer that determines the length. NoOption - 0 OffsetSize - 1 LeftRightBoundaries - 2 LeftBoundarySize - 3
locator | The values to enable location of the length field within the buffer. You can use parameterization for these values. For option 1, OffsetSize, use "Offset=xxx" (default=0) and "Size=xxx". For option 2, LeftRightBoundaries, specify "LB=xxx", "RB=xxx, and the optional "Ordinal=" and "Offset=xxx". For option 3, LeftBoundarySize, specify "Size=xxx", "LB=xxx", and the optional "Ordinal=" and "Offset=xxx".
additional_params | The format of the length field to be found. Encoding= - 0 for decimal (default), 1 for HEX" Order=" - 0 for by host (default), 1 by network order scheme" SubtractSize=" - 0 do not include the size of the data in its length (default), or 1, include the size of the data in its length. Since the options are passed as separate string parameters to lrs_length_receive e.g., "Order=1", "Encoding=1", they can be used together. Some length fields in a buffer include their own length in the total value. SubtractSize enables you to subtract the length of the field from the total to enable lrs_length_receive to correctly read only the length of data.
LrsLastArg | A marker indicating the end of the parameter list.

The lrs_length_send function writes data of a specified length from sock_descriptor into buffer. It is useful when sending parameterized data, where the length of data can be different each time the function is called. lrs_length_send saves you from having to calculate the length each time as VuGen will automatically write the correct length of the data into the field specified by the locator and location_option arguments.

VuGen inserts the length in the buffer itself. The user must be aware where the length value is placed within the buffer (unless the NoOption option is chosen) and its location is specified by the parameters location_option and locators. lrs_length_send first obtains the value of length (hereafter called length) and afterwards writes length number of bytes from the socket_descriptor into buffer.

The socket_descriptor and buffer parameters are identical to the first two parameters of lrs_send.

### location_option argument

The following table lists the values for location_option argument:

Location option | Description
--- | ---
NoOption | lrs_length_send will behave identically to lrs_send. That is, the amount of data to be send will not be limited to a specified length but by the socket buffer size.
OffsetSize | length takes up sizebytes and is placed offset bytes from the beginning of the buffer. The values for the offset and size are passed as locator parameters with the "Offset" and Size" identifiers (e.g., "Offset=6", "Size=4"). After locating the length field lrs_length_receive will write length number of bytes that directly follow it. The default value of "Offset" is zero.
LeftRightBoundaries | length is found between a left and right boundary. The values for both boundaries are passed as locator parameters using "LB" and "RB". The amount of data to write will be length number of bytes immediately following the right boundary. The locator parameters "Offset" and "Ordinal" may also be used.If the left or right boundary is a binary value, specify this by appending /BIN to the option indicator, for example, `"RB/BIN=\\x00\\x00\\x01\\x00\\x00\\x00"`
LeftBoundarySize | length is located after a left boundary and takes up size bytes. The values for the left boundary and size are passed as locator parameters "LB" and "Size", respectively. The locator parameters "Offset" and "Ordinal" may also be used as well as the /BIN indicator option.

### locator argument

The following table lists the values for the locator argument:

Multiple Locator argument values can be used by passing them as separate string parameters to lrs_length_receive e.g., "LB=LeftLeft ", "Size=1", "Offset=18".

Locator option | Description
--- | ---
Offset | Use Offset (e.g., "Offset=4") with the OffsetSize location_option where Offset specifies how many bytes from the beginning of the buffer lies the length field .Use "Offset" with the LeftRightBoundaries or LeftBoundarySize location_option where, to locate length,Offset number of bytes will be added to the left boundary. This is useful when there is always a specific number of bytes of unknown content following a known left boundary. For example, consider three characters, "ABC", that define the left boundary - if there are always 2 bytes of unknown content between "ABC" and length then pass "LB=ABC" and "Offset=2".
Ordinal | Use Ordinal with the LeftRightBoundaries or LeftBoundarySize location_option. It indicates that the length field begins after the ordinal instance of the left boundary. For example, if the left boundary, the string "ABC", appears many times in the buffer, then "Ordinal=2" specifies that you use the second instance of "ABC" to locating length. Note that "Ordinal" can be used in conjunction with "Offset". length lies Offset bytes following the Ordinal instance of the left boundary.

## Return Values

If this function fails, it returns NULL. If it succeeds, it returns a pointer to the converted buffer. You can also retrieve the converted buffer using lrs_get_user_buffer.

## Parameterization

All locator and additional_params arguments can be parameterized.

## Example

In the following example, the buffer buf6 is sent on socket0. The data to be sent is parameterized. "NameParameter" is a parameter taken from a list of first names.

The length field specified by the left and right boundaries falls between the colons - it initially has the value 4.

Example: buf6:
"Start Data LBoundary & Offset:4:RBoundary<NameParameter>"

However, as the name in "NameParameter" changes, VuGen inserts a different length in this field. In the first iteration, the name "David" is taken from the parameter list. VuGen inserts 5 (see below "SENT BUFFER on first iteration"), being the length of the word "David".

In the next invocation of lrs_length_send, the data has changed to the name "Michael". The length field is modified to 7 (see below "SENT BUFFER on second iteration").

Copy code

    #include "lrs.h"

    Action() {
         lrs_create_socket("socket0", "TCP",
                   "RemoteHost=bonaparte.abc.co.il:7", LrsLastArg);
         lrs_length_send("socket0", "buf6", LeftRightBoundaries, "LB=LBoundary",
                   "RB=:RBoundary", "Offset=10", LrsLastArg);
         lrs_close_socket("socket0");
         return 0;
    }

Example: ===SENT BUFFER (on first iteration) ===
"Start Data LBoundary & Offset:5:RBoundaryDavid"

Example: ===SENT BUFFER (on second iteration) ===
"Start Data LBoundary & Offset:7:RBoundaryMichael"

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: