:orphan: .. index:: pair: group; Tools to work with "struct sockaddr" .. _doxid-group__ts__tapi__sockaddr: Tools to work with "struct sockaddr" ==================================== .. toctree:: :hidden: enum_tapi_address_type.rst Overview ~~~~~~~~ Definition of test API for working with struct sockaddr. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block // enums enum :ref:`tapi_address_type`; // global functions uint16_t :ref:`tapi_get_random_port`(void); :ref:`te_errno` :ref:`tapi_allocate_port`(struct :ref:`rcf_rpc_server`* pco, uint16_t* p_port); :ref:`te_errno` :ref:`tapi_allocate_port_range`(struct :ref:`rcf_rpc_server`* pco, uint16_t* p_port, int num); :ref:`te_errno` :ref:`tapi_allocate_port_htons`(:ref:`rcf_rpc_server`* pco, uint16_t* p_port); uint16_t :ref:`tapi_get_port`(:ref:`rcf_rpc_server`* rpcs); static uint16_t :ref:`tapi_get_port_htons`(:ref:`rcf_rpc_server`* rpcs); static :ref:`te_errno` :ref:`tapi_sockaddr_clone`(:ref:`rcf_rpc_server`* pco, const struct sockaddr* src, struct sockaddr_storage* dst); static void :ref:`tapi_sockaddr_clone_exact`(const struct sockaddr* src, struct sockaddr_storage* dst); struct sockaddr* :ref:`tapi_sockaddr_clone_typed`(const struct sockaddr* addr, :ref:`tapi_address_type` type); :ref:`te_errno` :ref:`tapi_allocate_set_port`(:ref:`rcf_rpc_server`* rpcs, const struct sockaddr* addr); static int :ref:`tapi_sockaddr_cmp`(const struct sockaddr* addr1, const struct sockaddr* addr2); :ref:`te_errno` :ref:`tapi_sockaddr_clone2`(const struct sockaddr* src, struct sockaddr** dst); // macros #define :ref:`TAPI_ADDRESS_TYPE` #define :ref:`TEST_GET_TYPED_ADDR`(_base_addr, _type_arg, _res_addr) .. _details-group__ts__tapi__sockaddr: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Definition of test API for working with struct sockaddr. Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved. Global Functions ---------------- .. index:: pair: function; tapi_get_random_port .. _doxid-group__ts__tapi__sockaddr_1gaa62b12a193796d56618f47938fd02eec: .. ref-code-block:: cpp :class: doxyrest-title-code-block uint16_t tapi_get_random_port(void) Get a random port number from a range where conflicts with other applications are unlikely. You should check for yourself whether retrieved port is free on your host. .. rubric:: Returns: Port number in host byte order. .. index:: pair: function; tapi_allocate_port .. _doxid-group__ts__tapi__sockaddr_1gac6de78c6dd9c302f7b01e434e35134f5: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`te_errno` tapi_allocate_port(struct :ref:`rcf_rpc_server`* pco, uint16_t* p_port) Retrieve unused in system port in host order. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - pco - RPC server to check that port is free * - p_port - Location for allocated port .. rubric:: Returns: Status code. .. rubric:: See also: :ref:`tapi_get_port ` .. index:: pair: function; tapi_allocate_port_range .. _doxid-group__ts__tapi__sockaddr_1ga233a321ce4a51313630410db3370d739: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`te_errno` tapi_allocate_port_range(struct :ref:`rcf_rpc_server`* pco, uint16_t* p_port, int num) Retrieve range of ports unused in system, in host order. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - pco - RPC server to check that port is free * - p_port - Location for allocated ports, pointer to array, should have enough place for ``items``. * - num - Number of ports requests, i.e. length of range. .. rubric:: Returns: Status code. .. index:: pair: function; tapi_allocate_port_htons .. _doxid-group__ts__tapi__sockaddr_1ga3408c8812a0d5ed2dd44d243186155c1: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`te_errno` tapi_allocate_port_htons(:ref:`rcf_rpc_server`* pco, uint16_t* p_port) Retrieve unused in system port in network order. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - pco - RPC server to check that port is free * - p_port - Location for allocated port .. rubric:: Returns: Status code. .. rubric:: See also: :ref:`tapi_get_port_htons ` .. index:: pair: function; tapi_get_port .. _doxid-group__ts__tapi__sockaddr_1ga9201ea1ab71bacf112f9723a7a3b8020: .. ref-code-block:: cpp :class: doxyrest-title-code-block uint16_t tapi_get_port(:ref:`rcf_rpc_server`* rpcs) Retrieve unused in system port in host order. It calls :ref:`tapi_allocate_port() ` to get a port, but unlike that function it jumps to cleanup on failure. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - rpcs - RPC server to check that port is free. .. rubric:: Returns: Port number. .. rubric:: See also: :ref:`tapi_get_port_htons `, :ref:`tapi_allocate_port ` .. index:: pair: function; tapi_get_port_htons .. _doxid-group__ts__tapi__sockaddr_1gabce34c9da421c220c56a57e615b8f15b: .. ref-code-block:: cpp :class: doxyrest-title-code-block static uint16_t tapi_get_port_htons(:ref:`rcf_rpc_server`* rpcs) Retrieve unused in system port in network order. It jumps to cleanup on failure. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - rpcs - RPC server to check that port is free. .. rubric:: Returns: Port number. .. rubric:: See also: :ref:`tapi_get_port `, :ref:`tapi_allocate_port_htons ` .. index:: pair: function; tapi_sockaddr_clone .. _doxid-group__ts__tapi__sockaddr_1gad34ee59b3d873b3bb6319fe4a5b2a353: .. ref-code-block:: cpp :class: doxyrest-title-code-block static :ref:`te_errno` tapi_sockaddr_clone(:ref:`rcf_rpc_server`* pco, const struct sockaddr* src, struct sockaddr_storage* dst) Generate new sockaddr basing on existing one (copy data and allocate new port). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - pco - RPC server to check that port is free * - src - existing sockaddr * - dst - location for new sockaddr .. rubric:: Returns: Status code. .. index:: pair: function; tapi_sockaddr_clone_exact .. _doxid-group__ts__tapi__sockaddr_1ga77dfb295da51f2872a98c4dec0c75167: .. ref-code-block:: cpp :class: doxyrest-title-code-block static void tapi_sockaddr_clone_exact(const struct sockaddr* src, struct sockaddr_storage* dst) Obtain an exact copy of a given socket address. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - src - existing sockaddr * - dst - location for a clone .. rubric:: Returns: Status code. .. index:: pair: function; tapi_sockaddr_clone_typed .. _doxid-group__ts__tapi__sockaddr_1ga665039eed3de267f9575ef07eb118053: .. ref-code-block:: cpp :class: doxyrest-title-code-block struct sockaddr* tapi_sockaddr_clone_typed(const struct sockaddr* addr, :ref:`tapi_address_type` type) Get address of the specified type based on ``addr``. New address instance is allocated from the heap. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - addr - Base address - port is copied from it. * - type - Required address type. .. rubric:: Returns: Pointer to the address of the specified type. .. index:: pair: function; tapi_allocate_set_port .. _doxid-group__ts__tapi__sockaddr_1gac61a915842fcbdf9fd58cd5258583cb9: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`te_errno` tapi_allocate_set_port(:ref:`rcf_rpc_server`* rpcs, const struct sockaddr* addr) Allocate a free port and set it to ``addr``. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - rpcs - RPC server handle. * - addr - Address to set the new port. .. rubric:: Returns: Status code. .. index:: pair: function; tapi_sockaddr_cmp .. _doxid-group__ts__tapi__sockaddr_1gab2a6227705bcea13b02d9aec69ba2eb5: .. ref-code-block:: cpp :class: doxyrest-title-code-block static int tapi_sockaddr_cmp(const struct sockaddr* addr1, const struct sockaddr* addr2) Compair the content of two 'struct sockaddr' structures. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - addr1 - The first address * - addr2 - The second address * - 0 - equal * - -1 - not equal * - -2 - comparison of addresses of unsupported family .. rubric:: Returns: The comparison result: .. index:: pair: function; tapi_sockaddr_clone2 .. _doxid-group__ts__tapi__sockaddr_1ga86b7e2c0dd47f917d2bfddff2ddd774f: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`te_errno` tapi_sockaddr_clone2(const struct sockaddr* src, struct sockaddr** dst) Allocate memory of **sockaddr_storage** size and copy ``src`` data to there. ``dst`` should be released with ``free(3)`` when it is no longer needed. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - src - Existing sockaddr. * - dst - Copy of sockaddr. .. rubric:: Returns: Status code. Macros ------ .. index:: pair: define; TAPI_ADDRESS_TYPE .. _doxid-group__ts__tapi__sockaddr_1ga6a805ee036dc7898490210d2dac93d2a: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define TAPI_ADDRESS_TYPE Address types list, can be passed to macro **TEST_GET_ENUM_PARAM**. .. index:: pair: define; TEST_GET_TYPED_ADDR .. _doxid-group__ts__tapi__sockaddr_1ga9dc0b5987f2524d3889b046b68383bb2: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define TEST_GET_TYPED_ADDR(_base_addr, _type_arg, _res_addr) Get address type and allocate required address. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - _base_addr - Pointer to the base address. * - _type_arg - Variable to get address type. * - _res_addr - Ponter to save the requested address.