Share this page

# lrs_get_socket_attrib

Sockets Functions

Gets a socket's attributes.

    char *lrs_get_socket_attrib( char *s_desc , int attribute );

s_desc | A descriptor identifying the socket.
attribute | A socket attribute.

The lrs_get_socket_attrib function retrieves the specified socket attribute. This allows you to get information about the socket. You can only retrieve attributes from sockets that were bound or connected to a socket. To bind a socket to an existing socket, use lrs_create_socket(...LocalPort=...). To connect to a socket, use lrs_create_socket(...RemoteHost=...).

The available attributes are:

LOCAL_ADDRESS | The IP address (in standard dotted form) of the machine running the script.
LOCAL_HOSTNAME | The host name of the local machine.
LOCAL_PORT | The port number of the socket in the host byte order. This may be used for either bounded or connected sockets.
REMOTE_ADDRESS | The IP address of the peer machine. (TCP sockets only)
REMOTE_HOSTNAME | The host name of the peer machine. (TCP sockets only)
REMOTE_PORT | The port number of the peer socket in the host byte order. (TCP sockets only)

## Return Values

This function returns the value of the specified attribute as a string. If no value is available, it returns NULL.

## Parameterization

You cannot use standard parameterization for any arguments in this function.

## Example

In the following example, lrs_get_socket_attrib retrieves the IP address of the peer machine.

Copy code

    char *peer;
    lrs_receive("socket2", "buf20", LrsLastArg);
    /* Get the size and location of the data within the buffer. */
    peer =lrs_get_socket_attrib("socket2", REMOTE_ADDRESS );
    lr_output_message("The IP address of the remote host is:%s\n", peer);

The output generated by the above code, as seen in the VuGen execution log is:
`Message from run.c(32): The IP address of the remote host is:199.203.74.235`

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: